diff --git a/src/shared/ui/calendar/nice-calendar-month.tsx b/src/shared/ui/calendar/nice-calendar-month.tsx index 5327e90..349f994 100644 --- a/src/shared/ui/calendar/nice-calendar-month.tsx +++ b/src/shared/ui/calendar/nice-calendar-month.tsx @@ -29,7 +29,7 @@ const NiceCalendarMonth = ({ const { i18n } = useTranslation(); const currentLocale = i18n.language || 'en'; - const [valueYear, setValueYear] = useState(); + const [valueMonth, setValueMonth] = useState(); const [minMonth, setMinMonth] = useState(); const [maxMonth, setMaxMonth] = useState(); const onChangeToMonth = (selectedMonth: any) => { @@ -50,7 +50,12 @@ const NiceCalendarMonth = ({ setMaxMonth(endDate.toDate()); } } - setValueYear(startMonth?.substring(0, 4)); + if (startMonth) { + const startDate = moment(startMonth, ['YYYY.MM', 'YYYYMM'], true); + if (startDate.isValid()) { + setValueMonth(startDate.toDate()); + } + } } else if(calendarType === CalendarType.End){ if(!!startMonth){ @@ -61,10 +66,20 @@ const NiceCalendarMonth = ({ } } setMaxMonth(new Date()); - setValueYear(endMonth?.substring(0, 4)); + if (endMonth) { + const endDate = moment(endMonth, ['YYYY.MM', 'YYYYMM'], true); + if (endDate.isValid()) { + setValueMonth(endDate.toDate()); + } + } } else if(calendarType === CalendarType.Single){ - setValueYear(singleMonth?.substring(0, 4)); + if (singleMonth) { + const singleDate = moment(singleMonth, ['YYYY.MM', 'YYYYMM'], true); + if (singleDate.isValid()) { + setValueMonth(singleDate.toDate()); + } + } } }; @@ -115,7 +130,7 @@ const NiceCalendarMonth = ({ minDate={ minMonth } maxDate={ maxMonth } onClickMonth={ onChangeToMonth } - value={ valueYear } + value={ valueMonth } formatMonthYear={ formatMonthYear } formatYear= { formatYear } formatMonth={ formmatMonth }