- Updated the `addContact` function to allow all users to add contacts, removing the previous restriction that only masters could do so. - Deleted the `become-master` feature and related utility functions, streamlining the codebase. - Adjusted command settings to reflect the removal of the master role functionality. - Refactored components and hooks to eliminate dependencies on the master role, enhancing user experience and simplifying logic.
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
'use client';
|
||
|
||
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, isNowOrAfter } from '@repo/utils/datetime-format';
|
||
|
||
export function DaySlotsList() {
|
||
const { data: { customer } = {} } = useCustomerQuery();
|
||
const selectedDate = useDateTimeStore((store) => store.date);
|
||
const { endOfDay, startOfDay } = getDateUTCRange(selectedDate).day();
|
||
|
||
const { data: { slots } = {}, isLoading } = useMasterSlotsQuery({
|
||
filters: {
|
||
datetime_start: { gte: startOfDay, lt: endOfDay },
|
||
master: { documentId: { eq: customer?.documentId } },
|
||
},
|
||
});
|
||
|
||
const isSelectedDateTodayOrAfter = selectedDate && isNowOrAfter(selectedDate);
|
||
|
||
return (
|
||
<div className="flex flex-col space-y-2 px-4">
|
||
<h1 className="font-bold">Слоты</h1>
|
||
{isLoading && <LoadingSpinner />}
|
||
{!isLoading && !slots?.length ? <DataNotFound title="Слоты не найдены" /> : null}
|
||
{slots?.map((slot) => slot && <SlotCard key={slot.documentId} {...slot} />)}
|
||
{isSelectedDateTodayOrAfter && <DaySlotAddForm />}
|
||
</div>
|
||
);
|
||
}
|