"use client" import { ResourcePage } from "@/shared/data-view/resource-page" import { ColumnHeader } from "@/shared/data-view/table-view" import { Badge } from "@/shared/components/ui/badge" import { TIME_SHEET_ROUTES } from "@garage/api" import type { TimeSheetsClient } from "@garage/api" import { ClockIcon } from "lucide-react" import { formatEnum } from "@/shared/utils/formatters" function formatDate(value: unknown) { if (!value || typeof value !== "string") return "—" const d = new Date(value) return Number.isNaN(d.getTime()) ? value : d.toLocaleDateString() } function formatTime(value: unknown) { if (!value || typeof value !== "string") return "—" return value.length >= 5 ? value.slice(0, 5) : value } const ACTIVITY_VARIANT: Record = { general: "secondary", order: "default", task: "outline", } export default function TimeSheetsPage() { return ( pageTitle="Time Sheets" routeKey={TIME_SHEET_ROUTES.INDEX} getClient={(api) => api.timeSheets} statusFilter={{ statuses: ["general", "order", "task"], paramKey: "activity_type", allLabel: "All", }} columns={({ actionsColumn }) => [ { accessorKey: "date", header: ({ column }) => , cell: ({ row }) => (
{formatDate((row.original as any).date)}
), }, { accessorKey: "employee", header: ({ column }) => , cell: ({ row }) => { const e = (row.original as any).employee if (!e) return "—" return `${e.first_name ?? ""} ${e.last_name ?? ""}`.trim() || e.email || "—" }, }, { accessorKey: "clock_in", header: ({ column }) => , cell: ({ row }) => {formatTime((row.original as any).clock_in)}, }, { accessorKey: "clock_out", header: ({ column }) => , cell: ({ row }) => {formatTime((row.original as any).clock_out)}, }, { accessorKey: "duration", header: ({ column }) => , cell: ({ row }) => {formatTime((row.original as any).duration)}, }, { accessorKey: "activity_type", header: ({ column }) => , cell: ({ row }) => { const t = (row.original as any).activity_type ?? "general" return {formatEnum(t)} }, }, { accessorKey: "calculated_total_cost", header: ({ column }) => , cell: ({ row }) => { const v = (row.original as any).calculated_total_cost if (v == null) return "—" const n = Number(v) return Number.isFinite(n) ? n.toFixed(2) : "—" }, }, actionsColumn({ onEdit: undefined }), ]} /> ) }