summaryrefslogtreecommitdiff
path: root/lib/tech-vendor-possible-items/table/possible-items-data-table.tsx
blob: 5252684b371d9cc97477113020d7ec489ff1bd93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"use client";

import * as React from "react";

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 { getColumns } from "./possible-items-table-columns";
import { PossibleItemsTableToolbarActions } from "./possible-items-table-toolbar-actions";

// 타입만 import
type TechVendorPossibleItemsData = {
  id: number;
  vendorId: number;
  vendorCode: string | null;
  vendorName: string;
  techVendorType: string;
  itemCode: string;
  createdAt: Date;
  updatedAt: Date;
};
import type { DataTableAdvancedFilterField } from "@/types/table";

interface PossibleItemsDataTableProps {
  promises: Promise<[{
    data: TechVendorPossibleItemsData[];
    pageCount: number;
    totalCount: number;
  }, string[]]>;
}

export function PossibleItemsDataTable({ promises }: PossibleItemsDataTableProps) {
  const [{ data, pageCount }, vendorTypes] = React.use(promises);

  const columns = React.useMemo(() => getColumns(), []);

  const filterFields: DataTableAdvancedFilterField<TechVendorPossibleItemsData>[] = [
    {
      id: "vendorCode",
      label: "벤더코드",
      type: "text",
    },
    {
      id: "vendorName",
      label: "벤더명", 
      type: "text",
    },
    {
      id: "itemCode",
      label: "아이템코드",
      type: "text",
    },
    {
      id: "techVendorType",
      label: "벤더타입",
      type: "multi-select",
      options: Array.isArray(vendorTypes) ? vendorTypes.map((type: string) => ({
        label: type,
        value: type,
        count: 0,
      })) : [],
    },
  ];

  const { table } = useDataTable({
    data,
    columns,
    pageCount,
    filterFields,
    enableAdvancedFilter: true,
    initialState: {
      sorting: [{ id: "createdAt", desc: true }],
      pagination: { pageIndex: 0, pageSize: 10 },
    },
    getRowId: (originalRow) => String(originalRow.id),
    shallow: false,
    clearOnDefault: true,
  });

  return (
    <>
      <DataTable table={table}>
        <DataTableAdvancedToolbar table={table} filterFields={filterFields}>
          <PossibleItemsTableToolbarActions table={table} />
        </DataTableAdvancedToolbar>
      </DataTable>
    </>
  );
}