Calendar: Fix inconsistent time (#1328)

This commit is contained in:
Alexander Zinchuk 2021-07-26 17:35:45 +03:00
parent fdf4235383
commit 3004c27130
2 changed files with 5 additions and 2 deletions

View File

@ -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<OwnProps> = ({
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<Date>(defaultSelectedDate);
const [selectedHours, setSelectedHours] = useState<string>(
@ -66,10 +68,10 @@ const CalendarModal: FC<OwnProps> = ({
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());

View File

@ -60,6 +60,7 @@ const READABLE_ERROR_MESSAGES: Record<string, string> = {
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) {