fix(calendar): initialize selected date in ScheduleCalendar component if not set

- Added useEffect to set the selected date to the current date if it is not already defined.
- Imported useEffect alongside useState for managing component lifecycle.
This commit is contained in:
vchikalkin 2025-08-11 15:06:59 +03:00
parent b8ebdb8c64
commit 9dfd2724b6

View File

@ -6,7 +6,7 @@ import { useDateTimeStore } from '@/stores/datetime';
import { Calendar } from '@repo/ui/components/ui/calendar';
import { getDateUTCRange } from '@repo/utils/datetime-format';
import dayjs from 'dayjs';
import { useState } from 'react';
import { useEffect, useState } from 'react';
export function ScheduleCalendar() {
const { data: { customer } = {} } = useCustomerQuery();
@ -14,6 +14,12 @@ export function ScheduleCalendar() {
const selectedDate = useDateTimeStore((store) => store.date);
const setSelectedDate = useDateTimeStore((store) => store.setDate);
useEffect(() => {
if (!selectedDate) {
setSelectedDate(new Date());
}
}, [selectedDate, setSelectedDate]);
const [currentMonthDate, setCurrentMonthDate] = useState(new Date());
const { endOfMonth, startOfMonth } = getDateUTCRange(currentMonthDate).month();