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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
"use client"
import * as React from "react"
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 { getSHIEvaluationSubmissions } from "../service"
import { getColumns } from "./evaluation-submissions-table-columns"
import { useRouter } from "next/navigation"
import { ReviewerEvaluationView } from "@/db/schema"
interface EvaluationSubmissionsTableProps {
promises: Promise<
[
Awaited<ReturnType<typeof getSHIEvaluationSubmissions>>,
]
>
}
export function SHIEvaluationSubmissionsTable({ promises }: EvaluationSubmissionsTableProps) {
// 1. 데이터 로딩 상태 관리
const [isLoading, setIsLoading] = React.useState(true)
const [tableData, setTableData] = React.useState<{
data: ReviewerEvaluationView[]
pageCount: number
}>({ data: [], pageCount: 0 })
const router = useRouter()
console.log(tableData)
// 2. 행 액션 상태 관리
const [rowAction, setRowAction] =
React.useState<DataTableRowAction<ReviewerEvaluationView> | null>(null)
// 3. Promise 해결을 useEffect로 처리
React.useEffect(() => {
promises
.then(([result]) => {
setTableData(result)
setIsLoading(false)
})
// .catch((error) => {
// console.error('Failed to load evaluation submissions:', error)
// setIsLoading(false)
// })
}, [promises])
// 4. 컬럼 정의
const columns = React.useMemo(
() => getColumns({ setRowAction , router}),
[setRowAction, router]
)
// 5. 필터 필드 정의
const filterFields: DataTableFilterField<ReviewerEvaluationView>[] = [
{
id: "isCompleted",
label: "완료상태",
placeholder: "완료상태 선택...",
},
{
id: "periodicStatus",
label: "정기평가 상태",
placeholder: "상태 선택...",
},
{
id: "evaluationYear",
label: "평가연도",
placeholder: "연도 선택...",
},
{
id: "departmentCode",
label: "담당부서",
placeholder: "부서 선택...",
},
]
const advancedFilterFields: DataTableAdvancedFilterField<ReviewerEvaluationView>[] = [
{
id: "reviewerEvaluationId",
label: "평가 ID",
type: "text",
},
{
id: "vendorName",
label: "협력업체명",
type: "text",
},
{
id: "vendorCode",
label: "협력업체 코드",
type: "text",
},
{
id: "evaluationYear",
label: "평가연도",
type: "number",
},
{
id: "departmentCode",
label: "부서코드",
type: "select",
options: [
{ label: "구매평가", value: "ORDER_EVAL" },
{ label: "조달평가", value: "PROCUREMENT_EVAL" },
{ label: "품질평가", value: "QUALITY_EVAL" },
{ label: "CS평가", value: "CS_EVAL" },
{ label: "관리자", value: "ADMIN_EVAL" },
],
},
{
id: "division",
label: "사업부",
type: "select",
options: [
{ label: "조선", value: "SHIP" },
{ label: "플랜트", value: "PLANT" },
],
},
{
id: "materialType",
label: "자재유형",
type: "select",
options: [
{ label: "장비", value: "EQUIPMENT" },
{ label: "벌크", value: "BULK" },
{ label: "장비+벌크", value: "EQUIPMENT_BULK" },
],
},
{
id: "domesticForeign",
label: "국내/해외",
type: "select",
options: [
{ label: "국내", value: "DOMESTIC" },
{ label: "해외", value: "FOREIGN" },
],
},
{
id: "isCompleted",
label: "평가완료 여부",
type: "select",
options: [
{ label: "완료", value: "true" },
{ label: "미완료", value: "false" },
],
},
{
id: "periodicStatus",
label: "정기평가 상태",
type: "select",
options: [
{ label: "대기중", value: "PENDING" },
{ label: "진행중", value: "IN_PROGRESS" },
{ label: "검토중", value: "REVIEW" },
{ label: "완료", value: "COMPLETED" },
],
},
{
id: "documentsSubmitted",
label: "문서 제출여부",
type: "select",
options: [
{ label: "제출완료", value: "true" },
{ label: "미제출", value: "false" },
],
},
{
id: "periodicFinalScore",
label: "최종점수",
type: "number",
},
{
id: "periodicFinalGrade",
label: "최종등급",
type: "text",
},
{
id: "ldClaimCount",
label: "LD 클레임 건수",
type: "number",
},
{
id: "submissionDate",
label: "제출일",
type: "date",
},
{
id: "submissionDeadline",
label: "제출마감일",
type: "date",
},
{
id: "completedAt",
label: "완료일시",
type: "date",
},
{
id: "reviewerEvaluationCreatedAt",
label: "생성일",
type: "date",
},
{
id: "reviewerEvaluationUpdatedAt",
label: "수정일",
type: "date",
},
]
// 6. 데이터 테이블 설정
const { table } = useDataTable({
data: tableData.data,
columns,
pageCount: tableData.pageCount,
filterFields,
enablePinning: true,
enableAdvancedFilter: true,
initialState: {
sorting: [{ id: "reviewerEvaluationUpdatedAt", desc: true }],
columnPinning: { left: ["select"], right: ["actions"] },
},
getRowId: (originalRow) => String(originalRow.reviewerEvaluationId),
shallow: false,
clearOnDefault: true,
})
// 7. 데이터 새로고침 함수
const handleRefresh = React.useCallback(() => {
setIsLoading(true)
router.refresh()
}, [router])
// 8. 각종 성공 핸들러
const handleActionSuccess = React.useCallback(() => {
setRowAction(null)
table.resetRowSelection()
handleRefresh()
}, [handleRefresh, table])
// 9. 로딩 상태 표시
if (isLoading) {
return (
<div className="flex items-center justify-center h-32">
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"></div>
<span className="ml-2">평가 제출 목록을 불러오는 중...</span>
</div>
)
}
return (
<>
{/* 메인 테이블 */}
<DataTable table={table}>
<DataTableAdvancedToolbar
table={table}
filterFields={advancedFilterFields}
shallow={false}
>
{/* 추가 툴바 버튼들이 필요하면 여기에 */}
</DataTableAdvancedToolbar>
</DataTable>
{/* 행 액션 모달들 - 필요에 따라 구현 */}
{/* {rowAction?.type === "view_detail" && (
<EvaluationDetailDialog
row={rowAction.row}
onClose={() => setRowAction(null)}
onSuccess={handleActionSuccess}
/>
)} */}
</>
)
}
|