55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
'use client';
|
|
|
|
import { useCustomerQuery } from '@/hooks/api/customers';
|
|
import { useSlotsQuery } from '@/hooks/api/slots';
|
|
import { useDateTimeStore } from '@/stores/datetime';
|
|
import { Calendar } from '@repo/ui/components/ui/calendar';
|
|
import dayjs from 'dayjs';
|
|
import { useState } from 'react';
|
|
|
|
export function ScheduleCalendar() {
|
|
const { data: { customer } = {} } = useCustomerQuery();
|
|
|
|
const selectedDate = useDateTimeStore((store) => store.date);
|
|
const setSelectedDate = useDateTimeStore((store) => store.setDate);
|
|
|
|
const [currentMonthDate, setCurrentMonthDate] = useState(new Date());
|
|
|
|
const { data: { slots } = {} } = useSlotsQuery({
|
|
filters: {
|
|
date: {
|
|
gte: dayjs(currentMonthDate).startOf('month').format('YYYY-MM-DD'),
|
|
lte: dayjs(currentMonthDate).endOf('month').format('YYYY-MM-DD'),
|
|
},
|
|
master: {
|
|
documentId: {
|
|
eq: customer?.documentId,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
return (
|
|
<Calendar
|
|
className="bg-background"
|
|
disabled={(date) => {
|
|
return dayjs().isAfter(dayjs(date), 'day');
|
|
}}
|
|
mode="single"
|
|
modifiers={{
|
|
hasEvent: (date) => {
|
|
return slots?.some((slot) => dayjs(slot?.date).isSame(date, 'day')) || false;
|
|
},
|
|
}}
|
|
modifiersClassNames={{
|
|
hasEvent: 'border-primary border-2 rounded-xl',
|
|
}}
|
|
onMonthChange={(date) => setCurrentMonthDate(date)}
|
|
onSelect={(date) => {
|
|
if (date) setSelectedDate(date);
|
|
}}
|
|
selected={selectedDate}
|
|
/>
|
|
);
|
|
}
|