summaryrefslogtreecommitdiff
path: root/lib/vendors/materials-table/item-table.tsx
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-06-01 13:52:21 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-06-01 13:52:21 +0000
commitbac0228d21b7195065e9cddcc327ae33659c7bcc (patch)
tree8f3016ae4533c8706d0c00a605d9b1d41968c2bc /lib/vendors/materials-table/item-table.tsx
parent2fdce8d7a57c792bba0ac36fa554dca9c9cc31e3 (diff)
(대표님) 20250601까지 작업사항
Diffstat (limited to 'lib/vendors/materials-table/item-table.tsx')
-rw-r--r--lib/vendors/materials-table/item-table.tsx92
1 files changed, 92 insertions, 0 deletions
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