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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
"use client"
import * as React from "react"
import { useRouter } from "next/navigation"
import type {
DataTableAdvancedFilterField,
DataTableFilterField,
DataTableRowAction,
} from "@/types/table"
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 "./tech-vendors-table-columns"
import { getTechVendors, getTechVendorStatusCounts } from "../service"
import { TechVendor, techVendors, TechVendorWithAttachments } from "@/db/schema/techVendors"
import { TechVendorsTableToolbarActions } from "./tech-vendors-table-toolbar-actions"
import { UpdateVendorSheet } from "./update-vendor-sheet"
import { getVendorStatusIcon } from "../utils"
// import { ViewTechVendorLogsDialog } from "./view-tech-vendors-logs-dialog"
interface TechVendorsTableProps {
promises: Promise<
[
Awaited<ReturnType<typeof getTechVendors>>,
Awaited<ReturnType<typeof getTechVendorStatusCounts>>
]
>
}
export function TechVendorsTable({ promises }: TechVendorsTableProps) {
// Suspense로 받아온 데이터
const [{ data, pageCount }, statusCounts] = React.use(promises)
const [isCompact, setIsCompact] = React.useState<boolean>(false)
const [rowAction, setRowAction] = React.useState<DataTableRowAction<TechVendor> | null>(null)
// **router** 획득
const router = useRouter()
// getColumns() 호출 시, router를 주입
const columns = React.useMemo(
() => getColumns({ setRowAction, router }),
[setRowAction, router]
)
// 상태 한글 변환 유틸리티 함수
const getStatusDisplay = (status: string): string => {
const statusMap: Record<string, string> = {
"ACTIVE": "활성 상태",
"INACTIVE": "비활성 상태",
"BLACKLISTED": "거래 금지",
"PENDING_REVIEW": "비교 견적",
};
return statusMap[status] || status;
};
const filterFields: DataTableFilterField<TechVendorWithAttachments>[] = [
{
id: "status",
label: "상태",
options: techVendors.status.enumValues.map((status) => ({
label: getStatusDisplay(status),
value: status,
count: statusCounts[status],
})),
},
{ id: "vendorCode", label: "업체 코드" },
]
const advancedFilterFields: DataTableAdvancedFilterField<TechVendorWithAttachments>[] = [
{ id: "vendorName", label: "업체명", type: "text" },
{ id: "vendorCode", label: "업체코드", type: "text" },
{ id: "email", label: "이메일", type: "text" },
{ id: "country", label: "국가", type: "text" },
{
id: "status",
label: "업체승인상태",
type: "multi-select",
options: techVendors.status.enumValues.map((status) => ({
label: getStatusDisplay(status),
value: status,
count: statusCounts[status],
icon: getVendorStatusIcon(status),
})),
},
{
id: "techVendorType",
label: "벤더 타입",
type: "multi-select",
options: [
{ label: "조선", value: "조선" },
{ label: "해양TOP", value: "해양TOP" },
{ label: "해양HULL", value: "해양HULL" },
],
},
{
id: "workTypes",
label: "Work Type",
type: "multi-select",
options: [
// 조선 workTypes
{ label: "기장", value: "기장" },
{ label: "전장", value: "전장" },
{ label: "선실", value: "선실" },
{ label: "배관", value: "배관" },
{ label: "철의", value: "철의" },
// 해양TOP workTypes
{ label: "TM", value: "TM" },
{ label: "TS", value: "TS" },
{ label: "TE", value: "TE" },
{ label: "TP", value: "TP" },
// 해양HULL workTypes
{ label: "HA", value: "HA" },
{ label: "HE", value: "HE" },
{ label: "HH", value: "HH" },
{ label: "HM", value: "HM" },
{ label: "NC", value: "NC" },
],
},
{ 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: (originalRow) => String(originalRow.id),
shallow: false,
clearOnDefault: true,
})
const handleCompactChange = React.useCallback((compact: boolean) => {
setIsCompact(compact)
}, [])
// 테이블 새로고침 핸들러
const handleRefresh = React.useCallback(() => {
router.refresh()
}, [router])
return (
<>
<DataTable
table={table}
compact={isCompact}
// floatingBar={<TechVendorsTableFloatingBar table={table} />}
>
<DataTableAdvancedToolbar
table={table}
filterFields={advancedFilterFields}
shallow={false}
enableCompactToggle={true}
compactStorageKey="techVendorsTableCompact"
onCompactChange={handleCompactChange}
>
<TechVendorsTableToolbarActions table={table} onRefresh={handleRefresh} />
</DataTableAdvancedToolbar>
</DataTable>
<UpdateVendorSheet
open={rowAction?.type === "update"}
onOpenChange={() => setRowAction(null)}
vendor={rowAction?.row.original ?? null}
/>
</>
)
}
|