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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
"use client";
import * as React from "react";
import { useRouter } from "next/navigation";
import { DataTable } from "@/components/data-table/data-table";
import { useDataTable } from "@/hooks/use-data-table";
import { DataTableAdvancedToolbar } from "@/components/data-table/data-table-advanced-toolbar";
import type {
DataTableAdvancedFilterField,
DataTableRowAction,
} from "@/types/table"
import { getBasicContractTemplates} from "../service";
import { getColumns } from "./basic-contract-template-columns";
import { DeleteTemplatesDialog } from "./delete-basicContract-dialog";
import { UpdateTemplateSheet } from "./update-basicContract-sheet";
import { CreateRevisionDialog } from "./create-revision-dialog";
import { DisposeDocumentsDialog } from "./dispose-documents-dialog";
import { TemplateTableToolbarActions } from "./basicContract-table-toolbar-actions";
import { BasicContractTemplate } from "@/db/schema";
interface BasicTemplateTableProps {
promises: Promise<
[
Awaited<ReturnType<typeof getBasicContractTemplates>>,
]
>
}
export function BasicContractTemplateTable({ promises }: BasicTemplateTableProps) {
const router = useRouter();
const [rowAction, setRowAction] =
React.useState<DataTableRowAction<BasicContractTemplate> | null>(null)
const [selectedRows, setSelectedRows] = React.useState<BasicContractTemplate[]>([])
const [{ data, pageCount }] =
React.use(promises)
// 컬럼 설정 - router를 전달
const columns = React.useMemo(
() => getColumns({ setRowAction, router }),
[setRowAction, router]
)
// config 기반으로 필터 필드 설정
const advancedFilterFields: DataTableAdvancedFilterField<BasicContractTemplate>[] = [
{ id: "templateName", label: "템플릿명", type: "text" },
{
id: "status", label: "상태", type: "select", options: [
{ label: "활성", value: "ACTIVE" },
{ label: "폐기", value: "DISPOSED" },
]
},
{ id: "fileName", label: "파일명", type: "text" },
{ id: "createdAt", label: "생성일", type: "date" },
{ id: "updatedAt", label: "수정일", type: "date" },
];
const { table } = useDataTable({
data,
columns,
pageCount,
filterFields: advancedFilterFields,
enablePinning: true,
enableAdvancedFilter: true,
initialState: {
sorting: [{ id: "createdAt", desc: true }],
columnPinning: { right: ["actions"] },
},
getRowId: (originalRow) => String(originalRow.id),
shallow: false,
clearOnDefault: true,
})
return (
<>
<DataTable table={table}>
<DataTableAdvancedToolbar
table={table}
filterFields={advancedFilterFields}
shallow={false}
>
<TemplateTableToolbarActions table={table} />
</DataTableAdvancedToolbar>
</DataTable>
<DeleteTemplatesDialog
open={rowAction?.type === "delete"}
onOpenChange={() => setRowAction(null)}
templates={rowAction?.row.original ? [rowAction?.row.original] : []}
showTrigger={false}
onSuccess={() => rowAction?.row.toggleSelected(false)}
/>
<UpdateTemplateSheet
open={rowAction?.type === "update"}
onOpenChange={() => setRowAction(null)}
template={rowAction?.row.original ?? null}
/>
<CreateRevisionDialog
open={rowAction?.type === "createRevision"}
onOpenChange={() => setRowAction(null)}
baseTemplate={rowAction?.row.original ?? null}
onSuccess={() => {
setRowAction(null);
router.refresh();
}}
/>
<DisposeDocumentsDialog
open={rowAction?.type === "dispose" || rowAction?.type === "restore"}
onOpenChange={() => setRowAction(null)}
documents={rowAction?.row.original ? [rowAction?.row.original] : []}
showTrigger={false}
onSuccess={() => {
setRowAction(null);
router.refresh();
}}
/>
</>
);
}
|