"use client" import { useState } from "react" import { ResourcePage } from "@/shared/data-view/resource-page" import { ColumnHeader } from "@/shared/data-view/table-view" import FormDialog from "@/shared/components/form-dialog" import { InspectionForm } from "@/modules/inspections/inspection-form" import { InspectionFromTemplateForm } from "@/modules/inspections/inspection-from-template-form" import { InspectionRowActions } from "@/modules/inspections/inspection-row-actions" import { Button } from "@/shared/components/ui/button" import { Dialog, DialogContent, DialogHeader, DialogTitle, } from "@/shared/components/ui/dialog" import { ScrollArea } from "@/shared/components/ui/scroll-area" import { INSPECTION_ROUTES, InspectionStatus } from "@garage/api" import type { InspectionsClient } from "@garage/api" import Link from "next/link" import { Car, ClipboardList, ListChecks, UserIcon } from "lucide-react" import { useRouter } from "next/navigation" import { RelationLink } from "@/shared/components/relation-link" import { getFullName } from "@/shared/utils/getFullName" import { getVehicleLabel } from "@/modules/vehicles/utils/getVehicleLabel" const STATUS_BADGE_CLASS: Record = { in_progress: "bg-amber-100 text-amber-800", completed: "bg-emerald-100 text-emerald-800", cancelled: "bg-rose-100 text-rose-800", } const STATUS_LABEL: Record = { in_progress: "In Progress", completed: "Completed", cancelled: "Cancelled", } export default function InspectionsPage() { const router = useRouter() const [fromTemplateOpen, setFromTemplateOpen] = useState(false) return ( pageTitle="Inspections" routeKey={INSPECTION_ROUTES.INDEX} searchable searchPlaceholder="Search inspections..." statusFilter={{ statuses: InspectionStatus }} getClient={(api) => api.inspections} onRowClick={(row) => router.push(`/sales/inspections/${(row as any).id}`)} headerProps={({ selectedItem, invalidateQuery }) => ({ actions: (
{(resourceId) => ( )} New inspection from template { setFromTemplateOpen(false) invalidateQuery() if (id) router.push(`/sales/inspections/${id}/checkpoints`) }} />
), })} columns={({ openEdit, deleteItem }) => [ { accessorKey: "title", header: ({ column }) => , cell: ({ row }) => { const r = row.original as any return (
{r.title ?? "—"} {r.order_number && ( {r.order_number} )}
) }, }, { accessorKey: "customer", header: ({ column }) => , cell: ({ row }) => { const c = (row.original as any).customer return ( ) }, }, { accessorKey: "vehicle", header: ({ column }) => , cell: ({ row }) => { const v = (row.original as any).vehicle return ( ) }, }, { accessorKey: "inspection_category", header: ({ column }) => , cell: ({ row }) => { const ic = (row.original as any).inspection_category return ic?.inspection_name ?? ic?.name ?? "—" }, }, { accessorKey: "status", header: ({ column }) => , cell: ({ row }) => { const status = (row.original as any).status as string | undefined if (!status) return "—" const cls = STATUS_BADGE_CLASS[status] ?? "bg-gray-100 text-gray-700" return ( {STATUS_LABEL[status] ?? status} ) }, }, { id: "actions", header: () => Actions, enableSorting: false, enableHiding: false, cell: ({ row }) => ( openEdit(row.original as any)} onDelete={() => deleteItem(String((row.original as any).id))} /> ), }, ]} /> ) }