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
95 lines
3.7 KiB
TypeScript
95 lines
3.7 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 { CreditNoteForm } from "@/modules/credit-notes/credit-note-form"
|
|
import { CREDIT_NOTE_ROUTES, CreditNoteStatus } from "@garage/api"
|
|
import type { CreditNotesClient } from "@garage/api"
|
|
import { formatEnum } from "@/shared/utils/formatters"
|
|
import { Printer } from "lucide-react"
|
|
import { useDocumentPrint } from "@/shared/hooks/use-document-print"
|
|
|
|
type CreditNoteItem = {
|
|
id: number
|
|
subject?: string
|
|
credit_invoice?: string
|
|
customer_id?: number
|
|
status?: string
|
|
date?: string
|
|
created_at?: string
|
|
}
|
|
|
|
export default function CreditNotesPage() {
|
|
const router = useRouter()
|
|
const { print, isPrinting } = useDocumentPrint()
|
|
|
|
return (
|
|
<ResourcePage<CreditNotesClient>
|
|
pageTitle="Credit Notes"
|
|
routeKey={CREDIT_NOTE_ROUTES.INDEX}
|
|
searchable
|
|
searchPlaceholder="Search credit notes..."
|
|
statusFilter={{ statuses: CreditNoteStatus }}
|
|
getClient={(api) => api.creditNotes}
|
|
onRowClick={(row) => router.push(`/sales/credit-notes/${(row as any).id}`)}
|
|
headerProps={({ selectedItem, invalidateQuery }) => ({
|
|
actions: (
|
|
<FormDialog title="Credit Note">
|
|
{(resourceId) => (
|
|
<CreditNoteForm
|
|
resourceId={resourceId}
|
|
initialData={selectedItem}
|
|
onSuccess={invalidateQuery}
|
|
/>
|
|
)}
|
|
</FormDialog>
|
|
),
|
|
})}
|
|
columns={({ actionsColumn }) => [
|
|
{
|
|
accessorKey: "subject",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Subject" />,
|
|
},
|
|
{
|
|
accessorKey: "credit_invoice",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Credit Note #" />,
|
|
},
|
|
{
|
|
accessorKey: "status",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Status" />,
|
|
cell: ({ row }) => {
|
|
const item = row.original as unknown as CreditNoteItem
|
|
const status = item.status
|
|
const colorMap: Record<string, string> = {
|
|
draft: "text-muted-foreground",
|
|
open: "text-blue-600",
|
|
applied: "text-green-600",
|
|
void: "text-gray-400",
|
|
}
|
|
return (
|
|
<span className={colorMap[status ?? ""] ?? ""}>
|
|
{formatEnum(status)}
|
|
</span>
|
|
)
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "date",
|
|
header: ({ column }) => <ColumnHeader column={column} title="Date" />,
|
|
},
|
|
actionsColumn({
|
|
extraItems: (row) => [
|
|
{
|
|
label: isPrinting ? "Printing..." : "Print",
|
|
icon: Printer,
|
|
onClick: (r) => print("credit_note", String(r.id), "print"),
|
|
},
|
|
],
|
|
}),
|
|
]}
|
|
/>
|
|
)
|
|
}
|