* components/profile: rename components files * components/profile: organize files & folders * split DataCard to 2 components * [2] components/profile: organize files & folders * data-card: fix phone field disabled * fix card header color * add schedule button for master * fix navigation & profile background * add basic schedule page * fix bottom navbar overflows content * header: remove bottom margin * replace vanilla calendar with shadcn/ui one * add slot functional * fix forbidden error * add slot operations * show slots * filter by selected day * add hook useSlots fix update slots list after add slot fix initial fetch slots * use slots hooks * split edit-slot-form into files * rename /time-slots -> /components * refactor components & folders structure * add feature: delete slot * hooks/slot: update query keys * add hooks/profile * add hook useProfileMutation * use useProfileMutation hook for update role * rename useProfile -> useProfileQuery * fix useProfileQuery queryKey * add hook useContactsQuery * remove unused ternary operator * header: add backdrop blur * create slot cards * fix elements y center * fix getSlots filters * ui/ux improvements * fix date time types & names * move profile components from sub folder * add basic slot page * fix add slot form padding x * add slot buttons * extend slot card information * fix import type * use Container in pages * change orange -> yellow for dark * use Loading spinner in slots list * refactor \components\schedule dir structure * add orders list * change query & mutation keys * change url /profile/schedule/slot/ -> /slots/ * order: show services * remove prefetchQuery * bring the results of queries and hooks into a single form * react query: globally show error toast * add font inter * fix header: center text * orders: add sorting * order card: add avatar * rename records -> orders * reduced text size * fix slot buttons * fix datetime card ui * fix header: center text (finally) * layout/container: last:mb-4 * fix type * slot-datetime: use ReadonlyTimeRange * rename files & components * remove unnecessary context using * feature: edit slot time * fix: selected day reset after go back to /schedule * rename AddTimeRange -> EditableTimeRangeForm & refactor * fix some elements on page before data loaded * fix text size * slot-card: remove gap * slot-date: remove margin * fix slots & orders layout * toast: show error text in ui
70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
/* eslint-disable react/jsx-no-bind */
|
||
/* eslint-disable canonical/id-match */
|
||
'use client';
|
||
import { type SlotComponentProps } from './types';
|
||
import { useSlotDelete, useSlotMutation, useSlotQuery } from '@/hooks/slots';
|
||
import { Enum_Slot_State } from '@repo/graphql/types';
|
||
import { Button } from '@repo/ui/components/ui/button';
|
||
import { useRouter } from 'next/navigation';
|
||
|
||
export function SlotButtons({ documentId }: Readonly<SlotComponentProps>) {
|
||
const { data } = useSlotQuery({ documentId });
|
||
const { mutate: updateSlot } = useSlotMutation({ documentId });
|
||
const { mutate: deleteSlot } = useSlotDelete({ documentId });
|
||
|
||
const router = useRouter();
|
||
|
||
const slot = data?.data?.slot;
|
||
|
||
if (!slot) return null;
|
||
|
||
const isOpened = slot?.state === Enum_Slot_State.Open;
|
||
const isClosed = slot?.state === Enum_Slot_State.Closed;
|
||
|
||
function handleOpenSlot() {
|
||
return updateSlot({ data: { state: Enum_Slot_State.Open }, documentId });
|
||
}
|
||
|
||
function handleCloseSlot() {
|
||
return updateSlot({ data: { state: Enum_Slot_State.Closed }, documentId });
|
||
}
|
||
|
||
function handleDeleteSlot() {
|
||
router.back();
|
||
return deleteSlot();
|
||
}
|
||
|
||
const hasOrders = Boolean(slot?.orders.length);
|
||
|
||
return (
|
||
<div className="grid grid-cols-[2fr_1fr]">
|
||
{isOpened && (
|
||
<Button
|
||
className="rounded-l-2xl rounded-r-none bg-orange-100 p-6 text-orange-500 dark:bg-yellow-700 dark:text-orange-100"
|
||
onClick={handleCloseSlot}
|
||
variant="ghost"
|
||
>
|
||
Закрыть
|
||
</Button>
|
||
)}
|
||
{isClosed && (
|
||
<Button
|
||
className="rounded-l-2xl rounded-r-none bg-green-100 p-6 text-green-500 dark:bg-green-700 dark:text-green-100"
|
||
onClick={handleOpenSlot}
|
||
variant="ghost"
|
||
>
|
||
Открыть
|
||
</Button>
|
||
)}
|
||
<Button
|
||
className="rounded-l-none rounded-r-2xl bg-red-100 p-6 text-red-500 dark:bg-red-700 dark:text-red-100"
|
||
disabled={hasOrders}
|
||
onClick={handleDeleteSlot}
|
||
variant="ghost"
|
||
>
|
||
Удалить
|
||
</Button>
|
||
</div>
|
||
);
|
||
}
|