summaryrefslogtreecommitdiff
path: root/lib/approval-log/table/approval-log-table.tsx
blob: 75955ec6c5b0303cd9b5a5641fbd4c95e8c76760 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"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 type {
  DataTableAdvancedFilterField,
  DataTableFilterField,
} from '@/types/table';

import { getColumns } from './approval-log-table-column';
import { getApprovalLogList } from '../service';
import { type ApprovalLog } from '../service';

interface ApprovalLogTableProps {
  promises: Promise<[
    Awaited<ReturnType<typeof getApprovalLogList>>,
  ]>;
}

type ApprovalLogRowAction = {
  type: "view";
  row: { original: ApprovalLog };
} | null;

export function ApprovalLogTable({ promises }: ApprovalLogTableProps) {
  const [{ data, pageCount }] = React.use(promises);

  const setRowAction = React.useState<ApprovalLogRowAction>(null)[1];

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

  // 기본 & 고급 필터 필드
  const filterFields: DataTableFilterField<ApprovalLog>[] = [];
  const advancedFilterFields: DataTableAdvancedFilterField<ApprovalLog>[] = [
    {
      id: 'subject',
      label: '결재 제목',
      type: 'text',
    },
    {
      id: 'status',
      label: '상태',
      type: 'text',
    },
    {
      id: 'userId',
      label: '사용자 ID',
      type: 'text',
    },
    {
      id: 'emailAddress',
      label: '이메일',
      type: 'text',
    },
    {
      id: 'urgYn',
      label: '긴급여부',
      type: 'text',
    },
    {
      id: 'docSecuType',
      label: '보안등급',
      type: 'text',
    },
    {
      id: 'createdAt',
      label: '생성일',
      type: 'date',
    },
    {
      id: 'updatedAt',
      label: '수정일',
      type: 'date',
    },
  ];

  const { table } = useDataTable({
    data,
    columns,
    pageCount,
    filterFields,
    enablePinning: true,
    enableAdvancedFilter: true,
    initialState: {
      sorting: [{ id: 'createdAt', desc: true }],
      columnPinning: { right: ['actions'] },
    },
    getRowId: (row) => row.apInfId,
    shallow: false,
    clearOnDefault: true,
  });

  return (
    <DataTable table={table}>
      <DataTableAdvancedToolbar
        table={table}
        filterFields={advancedFilterFields}
        shallow={false}
      />
    </DataTable>
  );
}