From bac0228d21b7195065e9cddcc327ae33659c7bcc Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Sun, 1 Jun 2025 13:52:21 +0000
Subject: (대표님) 20250601까지 작업사항
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/vendors/materials-table/item-table.tsx | 92 ++++++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)
 create mode 100644 lib/vendors/materials-table/item-table.tsx

(limited to 'lib/vendors/materials-table/item-table.tsx')

diff --git a/lib/vendors/materials-table/item-table.tsx b/lib/vendors/materials-table/item-table.tsx
new file mode 100644
index 00000000..066d8de5
--- /dev/null
+++ b/lib/vendors/materials-table/item-table.tsx
@@ -0,0 +1,92 @@
+"use client"
+
+import * as React from "react"
+import type {
+  DataTableAdvancedFilterField,
+  DataTableFilterField,
+  DataTableRowAction,
+} from "@/types/table"
+
+import { toSentenceCase } from "@/lib/utils"
+import { useDataTable } from "@/hooks/use-data-table"
+import { DataTable } from "@/components/data-table/data-table"
+import { DataTableAdvancedToolbar } from "@/components/data-table/data-table-advanced-toolbar"
+import { useFeatureFlags } from "./feature-flags-provider"
+import {   getVendorMaterials,  } from "../service"
+import { VendorMaterialsView, vendors } from "@/db/schema/vendors"
+import { VendorsTableToolbarActions } from "./item-table-toolbar-actions"
+import { getColumns } from "./item-table-columns"
+import { ItemActionsDialogs } from "./item-action-dialog"
+
+interface VendorsTableProps {
+  promises: Promise<
+    [
+      Awaited<ReturnType<typeof getVendorMaterials>>,
+    ]
+  >, 
+  vendorId:number
+}
+
+export function VendorMaterialsTable({ promises , vendorId}: VendorsTableProps) {
+  const { featureFlags } = useFeatureFlags()
+
+  // Suspense로 받아온 데이터
+  const [{ data, pageCount }] = React.use(promises)
+  const [rowAction, setRowAction] = React.useState<DataTableRowAction<VendorMaterialsView> | null>(null)
+
+  // getColumns() 호출 시, router를 주입
+  const columns = React.useMemo(
+    () => getColumns({ setRowAction }),
+    [setRowAction]
+  )
+
+  const filterFields: DataTableFilterField<VendorMaterialsView>[] = [
+    
+  ]
+
+  const advancedFilterFields: DataTableAdvancedFilterField<VendorMaterialsView>[] = [
+    { id: "itemName", label: "Item Name", type: "text" },
+    { id: "itemCode", label: "Item Code", type: "text" },
+    { id: "description", label: "Description", type: "text" },
+    { id: "createdAt", label: "Created at", type: "date" },
+    { id: "updatedAt", label: "Updated at", type: "date" },
+  ]
+
+  const { table } = useDataTable({
+    data,
+    columns,
+    pageCount,
+    filterFields,
+    enablePinning: true,
+    enableAdvancedFilter: true,
+    initialState: {
+      sorting: [{ id: "createdAt", desc: true }],
+      columnPinning: { right: ["actions"] },
+    },
+    getRowId: (originalRow) => String(originalRow.itemCode),
+    shallow: false,
+    clearOnDefault: true,
+  })
+
+  return (
+    <>
+      <DataTable
+        table={table}
+      >
+        <DataTableAdvancedToolbar
+          table={table}
+          filterFields={advancedFilterFields}
+          shallow={false}
+        >
+          <VendorsTableToolbarActions table={table} vendorId={vendorId} />
+        </DataTableAdvancedToolbar>
+      </DataTable>
+
+      <ItemActionsDialogs
+        vendorId={vendorId}
+        rowAction={rowAction}
+        setRowAction={setRowAction}
+      />
+    </>
+  )
+}
\ No newline at end of file
-- 
cgit v1.2.3

