refactor(calendar): comment out past date disabling logic for calendar component; refactor day slots list to improve slot display and add conditional rendering for add form
This commit is contained in:
parent
ed197143d6
commit
25fb9269fc
@ -35,9 +35,9 @@ export function ScheduleCalendar() {
|
||||
return (
|
||||
<Calendar
|
||||
className="bg-background"
|
||||
disabled={(date) => {
|
||||
return dayjs().isAfter(dayjs(date), 'day');
|
||||
}}
|
||||
// disabled={(date) => {
|
||||
// return dayjs().isAfter(dayjs(date), 'day');
|
||||
// }}
|
||||
mode="single"
|
||||
modifiers={{
|
||||
hasEvent: (date) => {
|
||||
|
||||
@ -2,16 +2,19 @@
|
||||
|
||||
import { DaySlotAddForm } from './day-slot-add-form';
|
||||
import { SlotCard } from './slot-card';
|
||||
import { DataNotFound } from '@/components/shared/alert';
|
||||
import { useCustomerQuery } from '@/hooks/api/customers';
|
||||
import { useMasterSlotsQuery } from '@/hooks/api/slots';
|
||||
import { useDateTimeStore } from '@/stores/datetime';
|
||||
import { LoadingSpinner } from '@repo/ui/components/ui/spinner';
|
||||
import { getDateUTCRange } from '@repo/utils/datetime-format';
|
||||
import dayjs from 'dayjs';
|
||||
import { type PropsWithChildren } from 'react';
|
||||
|
||||
export function DaySlotsList() {
|
||||
const { data: { customer } = {} } = useCustomerQuery();
|
||||
const selectedDate = useDateTimeStore((store) => store.date);
|
||||
|
||||
const now = dayjs();
|
||||
const { endOfDay, startOfDay } = getDateUTCRange(selectedDate).day();
|
||||
|
||||
const { data: { slots } = {}, isLoading } = useMasterSlotsQuery({
|
||||
@ -20,12 +23,31 @@ export function DaySlotsList() {
|
||||
master: { documentId: { eq: customer?.documentId } },
|
||||
},
|
||||
});
|
||||
if (isLoading) return <LoadingSpinner />;
|
||||
|
||||
if (isLoading) {
|
||||
return <LoadingSpinner />;
|
||||
}
|
||||
|
||||
const shouldShowAddForm = now.isSame(selectedDate, 'day') || now.isBefore(selectedDate, 'day');
|
||||
|
||||
if (!slots?.length) {
|
||||
return (
|
||||
<Wrapper>
|
||||
<DataNotFound title="Слоты не найдены" />
|
||||
{shouldShowAddForm && <DaySlotAddForm />}
|
||||
</Wrapper>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-2 px-4">
|
||||
<Wrapper>
|
||||
<h1 className="font-bold">Слоты</h1>
|
||||
{slots?.map((slot) => slot && <SlotCard key={slot.documentId} {...slot} />)}
|
||||
<DaySlotAddForm />
|
||||
</div>
|
||||
{slots.map((slot) => slot && <SlotCard key={slot.documentId} {...slot} />)}
|
||||
{shouldShowAddForm && <DaySlotAddForm />}
|
||||
</Wrapper>
|
||||
);
|
||||
}
|
||||
|
||||
function Wrapper({ children }: Readonly<PropsWithChildren>) {
|
||||
return <div className="flex flex-col space-y-2 px-4">{children}</div>;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user