feat: integrate dialog close context in vendor select field and CRUD dialog components feat: enhance vendor general info to format status using utility function feat: implement form dialog context for managing dialog close actions feat: add async select field dialog close context for better form handling fix: update form mutation hook to close dialog on successful submission feat: extend document print types to include expense and credit note feat: add settings update payload type to include logo and other fields feat: create employee attendance and work history pages with resource management feat: implement payment made and received detail pages with actions feat: add quick shortcuts component for easy navigation in the dashboard feat: create actions for payment made and received with print and delete options feat: implement dialog close context for better dialog management feat: add error parsing utility for improved error handling in API responses
126 lines
5.5 KiB
TypeScript
126 lines
5.5 KiB
TypeScript
"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 { EstimateForm } from '@/modules/estimates/estimate-form'
|
|
import { ESTIMATE_ROUTES } from '@garage/api'
|
|
import type { EstimatesClient } from '@garage/api'
|
|
import { Car, FileTextIcon, Printer, UserIcon } from 'lucide-react'
|
|
import { useDocumentPrint } from '@/shared/hooks/use-document-print'
|
|
import Link from 'next/link'
|
|
import { formatDate } from '@/shared/utils/formatters'
|
|
import { getVehicleLabel } from '@/modules/vehicles/utils/getVehicleLabel'
|
|
import { getFullName } from '@/shared/utils/getFullName'
|
|
import { RelationLink } from '@/shared/components/relation-link'
|
|
|
|
export default function EstimatesPage() {
|
|
const router = useRouter()
|
|
const { print, isPrinting } = useDocumentPrint()
|
|
return (
|
|
<ResourcePage<EstimatesClient>
|
|
pageTitle="Estimates"
|
|
routeKey={ESTIMATE_ROUTES.INDEX}
|
|
searchable
|
|
searchPlaceholder="Search estimates..."
|
|
getClient={(api) => api.estimates}
|
|
onRowClick={(row) => router.push(`/sales/estimates/${(row as any).id}`)}
|
|
headerProps={({ selectedItem, invalidateQuery }) => ({
|
|
actions: (
|
|
<FormDialog title="Estimate">
|
|
{(resourceId) => (
|
|
<EstimateForm
|
|
resourceId={resourceId}
|
|
onSuccess={invalidateQuery}
|
|
/>
|
|
)}
|
|
</FormDialog>
|
|
),
|
|
})}
|
|
columns={({ actionsColumn }) => [
|
|
{
|
|
accessorKey: "title",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Title" />,
|
|
cell: ({ row }) => {
|
|
const item = row.original
|
|
return (
|
|
<div className="flex items-center gap-2">
|
|
<Link href={`/sales/estimates/${item.id}`} className="flex items-center gap-2 hover:underline" onClick={(e) => e.stopPropagation()}>
|
|
<FileTextIcon className="text-muted-foreground h-4 w-4" />
|
|
<span>{item.title}</span>
|
|
</Link>
|
|
</div>
|
|
)
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "estimate_number",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Estimate #" />,
|
|
},
|
|
{
|
|
accessorKey: "customer_name",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Customer" />,
|
|
cell: ({ row }) => {
|
|
const item: any = row.original
|
|
return (
|
|
<RelationLink
|
|
href={item.customer?.id ? `/sales/customers/${item.customer.id}` : null}
|
|
icon={UserIcon}
|
|
label={getFullName(item.customer)}
|
|
/>
|
|
)
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "vehicle",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Vehicle" />,
|
|
cell: ({ row }) => {
|
|
const item: any = row.original
|
|
return (
|
|
<RelationLink
|
|
href={item.vehicle?.id ? `/sales/vehicles/${item.vehicle.id}` : null}
|
|
icon={Car}
|
|
label={getVehicleLabel(item.vehicle as any)}
|
|
meta={item.vehicle?.license_plate}
|
|
/>
|
|
)
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "date",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Date" />,
|
|
cell: ({ row }) => {
|
|
const item = row.original
|
|
return formatDate(item.date)
|
|
}
|
|
},
|
|
{
|
|
accessorKey: "has_insurance",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Insurance" />,
|
|
cell: ({ row }) => {
|
|
const item = row.original
|
|
return item.has_insurance ? "Yes" : "No"
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "created_at",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Created" />,
|
|
cell: ({ row }) => {
|
|
const item = row.original
|
|
return item.created_at ? new Date(item.created_at).toLocaleDateString() : "—"
|
|
},
|
|
},
|
|
actionsColumn({
|
|
extraItems: (row) => [
|
|
{
|
|
label: isPrinting ? "Printing..." : "Print",
|
|
icon: Printer,
|
|
onClick: (r) => print("estimate", String(r.id), "print"),
|
|
},
|
|
],
|
|
}),
|
|
]}
|
|
/>
|
|
)
|
|
} |