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
101 lines
4.5 KiB
TypeScript
101 lines
4.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 { PurchaseOrderForm } from "@/modules/purchase-orders/purchase-order-form"
|
|
import { PURCHASE_ORDER_ROUTES } from "@garage/api"
|
|
import type { PurchaseOrdersClient } from "@garage/api"
|
|
import { RelationLink } from "@/shared/components/relation-link"
|
|
import { Building2, Printer } from "lucide-react"
|
|
import { getFullName } from "@/shared/utils/getFullName"
|
|
import { useDocumentPrint } from "@/shared/hooks/use-document-print"
|
|
|
|
export default function PurchaseOrdersPage() {
|
|
const router = useRouter()
|
|
const { print, isPrinting } = useDocumentPrint()
|
|
|
|
return (
|
|
<ResourcePage<PurchaseOrdersClient>
|
|
pageTitle="Purchase Orders"
|
|
routeKey={PURCHASE_ORDER_ROUTES.INDEX}
|
|
searchable
|
|
searchPlaceholder="Search purchase orders..."
|
|
getClient={(api) => api.purchaseOrders}
|
|
onRowClick={(row) => router.push(`/purchase/purchase-order/${(row as any).id}`)}
|
|
headerProps={({ selectedItem, invalidateQuery }) => ({
|
|
actions: (
|
|
<FormDialog classNames={{ dialogContent: "min-w-6xl" }} title="Purchase Order">
|
|
{(resourceId, { close }) => (
|
|
<PurchaseOrderForm
|
|
resourceId={resourceId}
|
|
initialData={selectedItem}
|
|
onSuccess={() => { invalidateQuery(); close()}}
|
|
/>
|
|
)}
|
|
</FormDialog>
|
|
),
|
|
})}
|
|
columns={({ actionsColumn }) => [
|
|
{
|
|
accessorKey: "order_number",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Order #" />,
|
|
cell: ({ row }) => (row.original as any).order_number || "—",
|
|
},
|
|
{
|
|
accessorKey: "title",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Title" />,
|
|
},
|
|
{
|
|
accessorKey: "vendor_name",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Vendor" />,
|
|
cell: ({ row }) => {
|
|
const item = row.original as any
|
|
return (
|
|
<RelationLink
|
|
href={item.vendor?.id ? `/purchase/vendor/${item.vendor.id}` : null}
|
|
icon={Building2}
|
|
label={item.vendor?.company_name || getFullName(item.vendor) || item.vendor_name}
|
|
/>
|
|
)
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "order_date",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Order Date" />,
|
|
cell: ({ row }) => {
|
|
const val = (row.original as any).order_date
|
|
return val ? new Date(val).toLocaleDateString() : "—"
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "delivery_date",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Delivery Date" />,
|
|
cell: ({ row }) => {
|
|
const val = (row.original as any).delivery_date
|
|
return val ? new Date(val).toLocaleDateString() : "—"
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "created_at",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Created" />,
|
|
cell: ({ row }) => {
|
|
const val = (row.original as any).created_at
|
|
return val ? new Date(val).toLocaleDateString() : "—"
|
|
},
|
|
},
|
|
actionsColumn({
|
|
extraItems: (row) => [
|
|
{
|
|
label: isPrinting ? "Printing..." : "Print",
|
|
icon: Printer,
|
|
onClick: (r) => print("purchase_order", String(r.id), "print"),
|
|
},
|
|
],
|
|
}),
|
|
]}
|
|
/>
|
|
)
|
|
}
|