import { useState } from "react"; import { Form, useNavigate, useNavigation } from "react-router"; import { useTranslation } from "react-i18next"; import { FeatherCalendarClock, FeatherCheck, FeatherUserX } from "@subframe/core"; import type { BookingDetailVM, RescheduleSlotOption } from "@hivegrid/view-models"; import { Alert } from "~/ui/components/Alert"; import { BadgeFeedback } from "~/ui/components/BadgeFeedback"; import { Button } from "~/ui/components/Button"; import { Calendar } from "~/ui/components/Calendar"; import { Card } from "~/ui/components/Card"; import { Dialog } from "~/ui/components/Dialog"; import { Loader } from "~/ui/components/Loader"; import { Select } from "~/ui/components/Select"; import { TextInput } from "~/ui/components/TextInput"; import { bookingStatusTone } from "./BookingListPage"; import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell"; /** * AK-P16b · interim booking detail (AD-28, archetype A3): appointment data, * intake answers and the full M129 lifecycle — held/no-show inline, cancel * (reason) / reschedule (slot picker) / re-assign (provider select) as real * Dialogs (S 560) posting the route's existing intents. Date selection * GET-navigates `?slotsDate=` so the loader recomputes engine slots; the * component stays mounted, so the dialog survives the navigation. Final * Subframe optics follow David's D-P16 delta (design-nachzug). * * Page chrome matches the boards/pipelines and task/lead detail screens: the * full-bleed PageHeader bar carries icon, title, status badge and the lifecycle * actions, content sits in PageBody Cards. Navigation back to the list is the * app breadcrumb's job, so the screen renders no back link of its own. */ export interface BookingDetailPageProps { vm: BookingDetailVM; csrf: string | null; rescheduleSlots: readonly RescheduleSlotOption[] | null; slotsDate: string | null; } type OpenDialog = "cancel" | "reschedule" | "reassign" | null; /** Card section heading — same weight the task/lead detail cards use. */ const SECTION_HEADING_CLASS = "text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary"; function isoToLocalDate(dateIso: string): Date { const [year, month, day] = dateIso.split("-").map(Number); return new Date(year ?? 1970, (month ?? 1) - 1, day ?? 1); } function localDateToIso(date: Date): string { const month = String(date.getMonth() + 1).padStart(2, "0"); const day = String(date.getDate()).padStart(2, "0"); return `${date.getFullYear()}-${month}-${day}`; } function CsrfField({ csrf }: { csrf: string | null }): React.JSX.Element | null { return csrf ? : null; } export function BookingDetailPage({ vm, csrf, rescheduleSlots, slotsDate }: BookingDetailPageProps): React.JSX.Element { const { t } = useTranslation(); const navigate = useNavigate(); const navigation = useNavigation(); const [openDialog, setOpenDialog] = useState(null); const [selectedSlot, setSelectedSlot] = useState(null); const [selectedProvider, setSelectedProvider] = useState(""); if (vm.status !== "ready" || !vm.data) { return ; } const data = vm.data; const canAct = data.canWrite && data.status === "scheduled"; const loadingSlots = navigation.state === "loading" && navigation.location?.search.includes("slotsDate="); const closeDialogProps = (dialog: OpenDialog) => ({ open: openDialog === dialog, onOpenChange: (open: boolean) => { if (!open) setOpenDialog(null); }, }); return ( } title={ {data.pageTitle} {t(data.statusKey)} } subtitle={data.whenLabel} subtitleTone="secondary" actions={ canAct ? (
{data.canAdmin ? ( ) : null}
) : undefined } /> {data.cancellationReason ? : null} {t("bookings.detail.customer")}
{data.customerName || "—"} {data.customerEmail ? ( {data.customerEmail} ) : null}
{data.intake.length > 0 ? ( {t("bookings.detail.intake")}
{data.intake.map((entry) => (
{entry.key}
{entry.value || "—"}
))}
) : null}
{/* Cancel (S 560): reason + destructive confirm, auto-mail server-side. */}
{t("bookings.cancelDialog.title")} {t("bookings.cancelDialog.body")}
{/* Reschedule (S 560): pick a date -> loader recomputes slots -> pick a slot. */}
{t("bookings.reschedule.title")} {t("bookings.reschedule.body")}
{ if (!date) return; setSelectedSlot(null); navigate(`?slotsDate=${localDateToIso(date)}`, { preventScrollReset: true, replace: true }); }} />
{loadingSlots ? (
) : slotsDate && rescheduleSlots ? ( rescheduleSlots.length === 0 ? ( {t("bookings.reschedule.noSlots")} ) : (
{rescheduleSlots.map((slot) => ( ))}
) ) : ( {t("bookings.reschedule.pickDateHint")} )}
{selectedSlot ? : null}
{/* Re-assign (S 560, admin): pick another provider. */}
{t("bookings.reassign.title")} {t("bookings.reassign.body")}
{selectedProvider ? : null}
); }