diff --git a/src/components/common/CalendarModal.tsx b/src/components/common/CalendarModal.tsx index 13909ae6..aac0c549 100644 --- a/src/components/common/CalendarModal.tsx +++ b/src/components/common/CalendarModal.tsx @@ -5,6 +5,7 @@ import React, { import buildClassName from '../../util/buildClassName'; import { formatTime, formatDateToString } from '../../util/dateFormat'; import useLang, { LangFn } from '../../hooks/useLang'; +import usePrevious from '../../hooks/usePrevious'; import Modal from '../ui/Modal'; import Button from '../ui/Button'; @@ -52,6 +53,7 @@ const CalendarModal: FC = ({ const now = new Date(); const defaultSelectedDate = useMemo(() => (selectedAt ? new Date(selectedAt) : new Date()), [selectedAt]); const maxDate = maxAt ? new Date(maxAt) : undefined; + const prevIsOpen = usePrevious(isOpen); const [selectedDate, setSelectedDate] = useState(defaultSelectedDate); const [selectedHours, setSelectedHours] = useState( @@ -66,10 +68,10 @@ const CalendarModal: FC = ({ const currentDate = selectedDate.getDate(); useEffect(() => { - if (isOpen) { + if (!prevIsOpen && isOpen) { setSelectedDate(defaultSelectedDate); } - }, [isOpen, defaultSelectedDate]); + }, [isOpen, defaultSelectedDate, prevIsOpen]); const shouldDisableNextMonth = (isPastMode && currentYear >= now.getFullYear() && currentMonth >= now.getMonth()) || (maxDate && currentYear >= maxDate.getFullYear() && currentMonth >= maxDate.getMonth()); diff --git a/src/util/getReadableErrorText.ts b/src/util/getReadableErrorText.ts index 4057c33e..30055ecd 100644 --- a/src/util/getReadableErrorText.ts +++ b/src/util/getReadableErrorText.ts @@ -60,6 +60,7 @@ const READABLE_ERROR_MESSAGES: Record = { INVITE_HASH_INVALID: 'The invite hash is invalid', CHANNELS_TOO_MUCH: 'You have joined too many channels/supergroups', USER_ALREADY_PARTICIPANT: 'You already in the group', + SCHEDULE_DATE_INVALID: 'Invalid schedule date provided', }; export default function getReadableErrorText(error: ApiError) {