diff options
Diffstat (limited to 'lib/vendor-rfq-response/vendor-cbe-table/rfq-items-table')
| -rw-r--r-- | lib/vendor-rfq-response/vendor-cbe-table/rfq-items-table/rfq-items-table-column.tsx | 62 | ||||
| -rw-r--r-- | lib/vendor-rfq-response/vendor-cbe-table/rfq-items-table/rfq-items-table.tsx | 86 |
2 files changed, 148 insertions, 0 deletions
diff --git a/lib/vendor-rfq-response/vendor-cbe-table/rfq-items-table/rfq-items-table-column.tsx b/lib/vendor-rfq-response/vendor-cbe-table/rfq-items-table/rfq-items-table-column.tsx new file mode 100644 index 00000000..bf4ae709 --- /dev/null +++ b/lib/vendor-rfq-response/vendor-cbe-table/rfq-items-table/rfq-items-table-column.tsx @@ -0,0 +1,62 @@ +"use client" +// Because columns rely on React state/hooks for row actions + +import * as React from "react" +import { ColumnDef, Row } from "@tanstack/react-table" +import { ClientDataTableColumnHeaderSimple } from "@/components/client-data-table/data-table-column-simple-header" +import { formatDate } from "@/lib/utils" +import { Checkbox } from "@/components/ui/checkbox" +import { ItemData } from "./rfq-items-table" + + +/** getColumns: return array of ColumnDef for 'vendors' data */ +export function getColumns(): ColumnDef<ItemData>[] { + return [ + + // Vendor Name + { + accessorKey: "itemCode", + header: ({ column }) => ( + <ClientDataTableColumnHeaderSimple column={column} title="Item Code" /> + ), + cell: ({ row }) => row.getValue("itemCode"), + }, + + // Vendor Code + { + accessorKey: "description", + header: ({ column }) => ( + <ClientDataTableColumnHeaderSimple column={column} title="Description" /> + ), + cell: ({ row }) => row.getValue("description"), + }, + + // Status + { + accessorKey: "quantity", + header: ({ column }) => ( + <ClientDataTableColumnHeaderSimple column={column} title="Quantity" /> + ), + cell: ({ row }) => row.getValue("quantity"), + }, + + + // Created At + { + accessorKey: "createdAt", + header: ({ column }) => ( + <ClientDataTableColumnHeaderSimple column={column} title="Created At" /> + ), + cell: ({ cell }) => formatDate(cell.getValue() as Date), + }, + + // Updated At + { + accessorKey: "updatedAt", + header: ({ column }) => ( + <ClientDataTableColumnHeaderSimple column={column} title="Updated At" /> + ), + cell: ({ cell }) => formatDate(cell.getValue() as Date), + }, + ] +}
\ No newline at end of file diff --git a/lib/vendor-rfq-response/vendor-cbe-table/rfq-items-table/rfq-items-table.tsx b/lib/vendor-rfq-response/vendor-cbe-table/rfq-items-table/rfq-items-table.tsx new file mode 100644 index 00000000..c5c67e54 --- /dev/null +++ b/lib/vendor-rfq-response/vendor-cbe-table/rfq-items-table/rfq-items-table.tsx @@ -0,0 +1,86 @@ +'use client' + +import * as React from "react" +import { ClientDataTable } from "@/components/client-data-table/data-table" +import { getColumns } from "./rfq-items-table-column" +import { DataTableAdvancedFilterField } from "@/types/table" +import { Loader2 } from "lucide-react" +import { useToast } from "@/hooks/use-toast" +import { getItemsByRfqId } from "../../service" + +export interface ItemData { + id: number + itemCode: string + description: string | null + quantity: number + uom: string | null + createdAt: Date + updatedAt: Date +} + +interface RFQItemsTableProps { + rfqId: number +} + +export function RfqItemsTable({ rfqId }: RFQItemsTableProps) { + const { toast } = useToast() + + const columns = React.useMemo( + () => getColumns(), + [] + ) + + const [rfqItems, setRfqItems] = React.useState<ItemData[]>([]) + const [isLoading, setIsLoading] = React.useState(false) + + React.useEffect(() => { + async function loadItems() { + setIsLoading(true) + try { + // Use the correct function name (camelCase) + const result = await getItemsByRfqId(rfqId) + if (result.success && result.data) { + setRfqItems(result.data as ItemData[]) + } else { + throw new Error(result.error || "Unknown error occurred") + } + } catch (error) { + console.error("RFQ 아이템 로드 오류:", error) + toast({ + title: "Error", + description: "Failed to load RFQ items", + variant: "destructive", + }) + } finally { + setIsLoading(false) + } + } + loadItems() + }, [toast, rfqId]) + + const advancedFilterFields: DataTableAdvancedFilterField<ItemData>[] = [ + { id: "itemCode", label: "Item Code", type: "text" }, + { id: "description", label: "Description", type: "text" }, + { id: "quantity", label: "Quantity", type: "number" }, + { id: "uom", label: "UoM", type: "text" }, + ] + + // If loading, show a flex container that fills the parent and centers the spinner + if (isLoading) { + return ( + <div className="flex h-full w-full items-center justify-center"> + <Loader2 className="h-8 w-8 animate-spin text-muted-foreground" /> + </div> + ) + } + + // Otherwise, show the table + return ( + <ClientDataTable + data={rfqItems} + columns={columns} + advancedFilterFields={advancedFilterFields} + > + </ClientDataTable> + ) +}
\ No newline at end of file |
