/* eslint-disable react/jsx-no-bind */ 'use client'; import { type SlotComponentProps } from '../types'; import { EditableTimeRangeForm, ReadonlyTimeRange } from '@/components/shared/time-range'; import { useSlotMutation, useSlotQuery } from '@/hooks/api/slots'; import { useScheduleStore } from '@/stores/schedule'; import { Button } from '@repo/ui/components/ui/button'; import { formatTime } from '@repo/utils/datetime-format'; import { PencilLine } from 'lucide-react'; import { useEffect } from 'react'; export function SlotTime(props: Readonly) { const editMode = useScheduleStore((state) => state.editMode); return editMode ? : ; } function SlotTimeEditForm({ documentId }: Readonly) { const { editMode, endTime, resetTime, setEditMode, setEndTime, setStartTime, startTime } = useScheduleStore((state) => state); const { isPending: isMutationPending, mutate: updateSlot } = useSlotMutation({ documentId }); const { data: { slot } = {}, isPending: isQueryPending } = useSlotQuery({ documentId }); const isPending = isMutationPending || isQueryPending; useEffect(() => { if (editMode) { if (slot?.time_start) setStartTime(slot.time_start); if (slot?.time_end) setEndTime(slot.time_end); } }, [editMode, setEndTime, setStartTime, slot]); function handleSubmit() { updateSlot({ data: { time_end: formatTime(endTime).db(), time_start: formatTime(startTime).db() }, }); resetTime(); setEditMode(false); } return ( ); } function SlotTimeReadonly({ documentId }: Readonly) { const setEditMode = useScheduleStore((state) => state.setEditMode); const { data: { slot } = {} } = useSlotQuery({ documentId }); if (!slot) return null; const hasOrders = Boolean(slot?.orders.length); return (
); }