Calendar: Fix inconsistent time (#1328)
This commit is contained in:
parent
fdf4235383
commit
3004c27130
@ -5,6 +5,7 @@ import React, {
|
|||||||
import buildClassName from '../../util/buildClassName';
|
import buildClassName from '../../util/buildClassName';
|
||||||
import { formatTime, formatDateToString } from '../../util/dateFormat';
|
import { formatTime, formatDateToString } from '../../util/dateFormat';
|
||||||
import useLang, { LangFn } from '../../hooks/useLang';
|
import useLang, { LangFn } from '../../hooks/useLang';
|
||||||
|
import usePrevious from '../../hooks/usePrevious';
|
||||||
|
|
||||||
import Modal from '../ui/Modal';
|
import Modal from '../ui/Modal';
|
||||||
import Button from '../ui/Button';
|
import Button from '../ui/Button';
|
||||||
@ -52,6 +53,7 @@ const CalendarModal: FC<OwnProps> = ({
|
|||||||
const now = new Date();
|
const now = new Date();
|
||||||
const defaultSelectedDate = useMemo(() => (selectedAt ? new Date(selectedAt) : new Date()), [selectedAt]);
|
const defaultSelectedDate = useMemo(() => (selectedAt ? new Date(selectedAt) : new Date()), [selectedAt]);
|
||||||
const maxDate = maxAt ? new Date(maxAt) : undefined;
|
const maxDate = maxAt ? new Date(maxAt) : undefined;
|
||||||
|
const prevIsOpen = usePrevious(isOpen);
|
||||||
|
|
||||||
const [selectedDate, setSelectedDate] = useState<Date>(defaultSelectedDate);
|
const [selectedDate, setSelectedDate] = useState<Date>(defaultSelectedDate);
|
||||||
const [selectedHours, setSelectedHours] = useState<string>(
|
const [selectedHours, setSelectedHours] = useState<string>(
|
||||||
@ -66,10 +68,10 @@ const CalendarModal: FC<OwnProps> = ({
|
|||||||
const currentDate = selectedDate.getDate();
|
const currentDate = selectedDate.getDate();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isOpen) {
|
if (!prevIsOpen && isOpen) {
|
||||||
setSelectedDate(defaultSelectedDate);
|
setSelectedDate(defaultSelectedDate);
|
||||||
}
|
}
|
||||||
}, [isOpen, defaultSelectedDate]);
|
}, [isOpen, defaultSelectedDate, prevIsOpen]);
|
||||||
|
|
||||||
const shouldDisableNextMonth = (isPastMode && currentYear >= now.getFullYear() && currentMonth >= now.getMonth())
|
const shouldDisableNextMonth = (isPastMode && currentYear >= now.getFullYear() && currentMonth >= now.getMonth())
|
||||||
|| (maxDate && currentYear >= maxDate.getFullYear() && currentMonth >= maxDate.getMonth());
|
|| (maxDate && currentYear >= maxDate.getFullYear() && currentMonth >= maxDate.getMonth());
|
||||||
|
|||||||
@ -60,6 +60,7 @@ const READABLE_ERROR_MESSAGES: Record<string, string> = {
|
|||||||
INVITE_HASH_INVALID: 'The invite hash is invalid',
|
INVITE_HASH_INVALID: 'The invite hash is invalid',
|
||||||
CHANNELS_TOO_MUCH: 'You have joined too many channels/supergroups',
|
CHANNELS_TOO_MUCH: 'You have joined too many channels/supergroups',
|
||||||
USER_ALREADY_PARTICIPANT: 'You already in the group',
|
USER_ALREADY_PARTICIPANT: 'You already in the group',
|
||||||
|
SCHEDULE_DATE_INVALID: 'Invalid schedule date provided',
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function getReadableErrorText(error: ApiError) {
|
export default function getReadableErrorText(error: ApiError) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user