diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-05-29 05:17:13 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-05-29 05:17:13 +0000 |
| commit | 37f55540833c2d5894513eca9fc8f7c6233fc2d2 (patch) | |
| tree | 6807978e7150358b3444c33b825c83e2c9cda8e8 /lib/tech-vendor-rfq-response/vendor-cbe-table/rfq-items-table/rfq-items-table.tsx | |
| parent | 4b9bdb29e637f67761beb2db7f75dab0432d6712 (diff) | |
(대표님) 0529 14시 16분 변경사항 저장 (Vendor Data, Docu)
Diffstat (limited to 'lib/tech-vendor-rfq-response/vendor-cbe-table/rfq-items-table/rfq-items-table.tsx')
| -rw-r--r-- | lib/tech-vendor-rfq-response/vendor-cbe-table/rfq-items-table/rfq-items-table.tsx | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/lib/tech-vendor-rfq-response/vendor-cbe-table/rfq-items-table/rfq-items-table.tsx b/lib/tech-vendor-rfq-response/vendor-cbe-table/rfq-items-table/rfq-items-table.tsx new file mode 100644 index 00000000..c5c67e54 --- /dev/null +++ b/lib/tech-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 |
