"use client" import { useRouter } from 'next/navigation' import { ResourcePage } from '@/shared/data-view/resource-page' import { ColumnHeader } from '@/shared/data-view/table-view' import FormDialog from '@/shared/components/form-dialog' import { ImportDataButton } from '@/shared/components/import-data-button' import { ExportDataButton } from '@/shared/components/export-data-button' import { DownloadSampleButton } from '@/shared/components/download-sample-button' import { useAuthApi } from '@/shared/useApi' import { VehicleForm } from '@/modules/vehicles/vehicle-form' import { VEHICLE_ROUTES } from '@garage/api' import type { VehiclesClient } from '@garage/api' import { CarIcon } from 'lucide-react' export default function VehiclesPage() { const router = useRouter() const api = useAuthApi() return ( pageTitle="Vehicles" routeKey={VEHICLE_ROUTES.INDEX} getClient={(api) => api.vehicles} onRowClick={(row) => router.push(`/sales/vehicles/${(row as any).id}`)} headerProps={({ selectedItem, invalidateQuery }) => ({ actions: (
api.vehicles.downloadImportSample()} fileName='vehicles-import-sample' /> api.vehicles.importData(file)} onSuccess={invalidateQuery} /> api.vehicles.exportData(filters)} fileName='vehicles' /> {(resourceId) => ( )}
), })} columns={({ actionsColumn }) => [ { accessorKey: "name", header: ({ column }) => , cell: ({ row }) => { const r = row.original as any const make = r.make ?? "" const model = r.model ?? "" const display = r.name || `${make} ${model}`.trim() || "—" return (
{display} {r.sub_model && ( {r.sub_model} )}
) }, }, { accessorKey: "year", header: ({ column }) => , cell: ({ row }) => (row.original as any).year ?? "—", }, { accessorKey: "license_plate", header: ({ column }) => , cell: ({ row }) => { const val = (row.original as any).license_plate return val ? {val} : "—" }, }, { accessorKey: "vin_number", header: ({ column }) => , cell: ({ row }) => { const val = (row.original as any).vin_number return val ? {val} : "—" }, }, { accessorKey: "engine_size", header: ({ column }) => , cell: ({ row }) => (row.original as any).engine_size ?? "—", }, { accessorKey: "mileage", header: ({ column }) => , cell: ({ row }) => { const val = (row.original as any).mileage return val != null ? `${Number(val).toLocaleString()} mi` : "—" }, }, { accessorKey: "created_at", header: ({ column }) => , cell: ({ row }) => { const val = (row.original as any).created_at return val ? new Date(val).toLocaleDateString() : "—" }, }, actionsColumn(), ]} /> ) }