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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
// lib/vendor-responses/table/vendor-responses-table-columns.tsx
"use client"
import * as React from "react"
import { type DataTableRowAction } from "@/types/table"
import { type ColumnDef } from "@tanstack/react-table"
import {
Ellipsis, FileText, Pencil, Edit, Trash2,
Eye, MessageSquare, Clock, CheckCircle, AlertTriangle, FileX
} from "lucide-react"
import { formatDate, formatDateTime } from "@/lib/utils"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip"
import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header"
import Link from "next/link"
import { useRouter } from "next/navigation"
import { VendorResponseDetail } from "../service"
import { VendorRfqResponseSummary } from "../validations"
// 응답 상태에 따른 배지 컴포넌트
function ResponseStatusBadge({ status }: { status: string }) {
switch (status) {
case "NOT_RESPONDED":
return (
<Badge variant="outline" className="text-orange-600 border-orange-600">
<Clock className="mr-1 h-3 w-3" />
미응답
</Badge>
)
case "RESPONDED":
return (
<Badge variant="default" className="bg-green-600 text-white">
<CheckCircle className="mr-1 h-3 w-3" />
응답완료
</Badge>
)
case "REVISION_REQUESTED":
return (
<Badge variant="secondary" className="text-yellow-600 border-yellow-600">
<AlertTriangle className="mr-1 h-3 w-3" />
수정요청
</Badge>
)
case "WAIVED":
return (
<Badge variant="outline" className="text-gray-600 border-gray-600">
<FileX className="mr-1 h-3 w-3" />
포기
</Badge>
)
default:
return <Badge>{status}</Badge>
}
}
type NextRouter = ReturnType<typeof useRouter>;
interface GetColumnsProps {
router: NextRouter
}
/**
* tanstack table 컬럼 정의
*/
export function getColumns({
router,
}: GetColumnsProps): ColumnDef<VendorResponseDetail>[] {
// ----------------------------------------------------------------
// 1) select 컬럼 (체크박스)
// ----------------------------------------------------------------
const selectColumn: ColumnDef<VendorRfqResponseSummary> = {
id: "select",
header: ({ table }) => (
<Checkbox
checked={
table.getIsAllPageRowsSelected() ||
(table.getIsSomePageRowsSelected() && "indeterminate")
}
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
className="translate-y-0.5"
/>
),
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(value) => row.toggleSelected(!!value)}
aria-label="Select row"
className="translate-y-0.5"
/>
),
size: 40,
enableSorting: false,
enableHiding: false,
}
// ----------------------------------------------------------------
// 2) actions 컬럼 (작성하기 버튼만)
// ----------------------------------------------------------------
const actionsColumn: ColumnDef<VendorRfqResponseSummary> = {
id: "actions",
enableHiding: false,
cell: ({ row }) => {
const vendorId = row.original.vendorId
const rfqRecordId = row.original.rfqRecordId
const rfqType = row.original.rfqType
const rfqCode = row.original.rfq?.rfqCode || "RFQ"
return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="sm"
onClick={() => router.push(`/partners/rfq-answer/${vendorId}/${rfqRecordId}`)}
className="h-8 px-3"
>
<Edit className="h-4 w-4 mr-1" />
작성하기
</Button>
</TooltipTrigger>
<TooltipContent>
<p>{rfqCode} 응답 작성하기</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
)
},
size: 100,
minSize: 100,
maxSize: 150,
}
// ----------------------------------------------------------------
// 3) 컬럼 정의 배열
// ----------------------------------------------------------------
const columnDefinitions = [
{
id: "rfqCode",
label: "RFQ 번호",
group: "RFQ 정보",
size: 120,
minSize: 100,
maxSize: 150,
},
{
id: "rfqDueDate",
label: "RFQ 마감일",
group: "RFQ 정보",
size: 120,
minSize: 100,
maxSize: 150,
},
{
id: "overallStatus",
label: "전체 상태",
group: null,
size: 80,
minSize: 60,
maxSize: 100,
},
{
id: "totalAttachments",
label: "총 첨부파일",
group: "응답 통계",
size: 100,
minSize: 80,
maxSize: 120,
},
{
id: "respondedCount",
label: "응답완료",
group: "응답 통계",
size: 100,
minSize: 80,
maxSize: 120,
},
{
id: "pendingCount",
label: "미응답",
group: "응답 통계",
size: 100,
minSize: 80,
maxSize: 120,
},
{
id: "responseRate",
label: "응답률",
group: "진행률",
size: 100,
minSize: 80,
maxSize: 120,
},
{
id: "completionRate",
label: "완료율",
group: "진행률",
size: 100,
minSize: 80,
maxSize: 120,
},
{
id: "requestedAt",
label: "요청일",
group: "날짜 정보",
size: 120,
minSize: 100,
maxSize: 150,
},
{
id: "lastRespondedAt",
label: "최종 응답일",
group: "날짜 정보",
size: 120,
minSize: 100,
maxSize: 150,
},
];
// ----------------------------------------------------------------
// 4) 그룹별로 컬럼 정리 (중첩 헤더 생성)
// ----------------------------------------------------------------
const groupMap: Record<string, ColumnDef<VendorRfqResponseSummary>[]> = {}
columnDefinitions.forEach((cfg) => {
const groupName = cfg.group || "_noGroup"
if (!groupMap[groupName]) {
groupMap[groupName] = []
}
// 개별 컬럼 정의
const columnDef: ColumnDef<VendorRfqResponseSummary> = {
accessorKey: cfg.id,
enableResizing: true,
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title={cfg.label} />
),
cell: ({ row, cell }) => {
// 각 컬럼별 특별한 렌더링 처리
switch (cfg.id) {
case "rfqCode":
return row.original.rfq?.rfqCode || "-"
case "rfqDueDate":
const dueDate = row.original.rfq?.dueDate;
return dueDate ? formatDate(new Date(dueDate)) : "-";
case "overallStatus":
return <ResponseStatusBadge status={row.original.overallStatus} />
case "totalAttachments":
return (
<div className="text-center font-medium">
{row.original.totalAttachments}
</div>
)
case "respondedCount":
return (
<div className="text-center text-green-600 font-medium">
{row.original.respondedCount}
</div>
)
case "pendingCount":
return (
<div className="text-center text-orange-600 font-medium">
{row.original.pendingCount}
</div>
)
case "responseRate":
const responseRate = row.original.responseRate;
return (
<div className="text-center">
<span className={`font-medium ${responseRate >= 80 ? 'text-green-600' : responseRate >= 50 ? 'text-yellow-600' : 'text-red-600'}`}>
{responseRate}%
</span>
</div>
)
case "completionRate":
const completionRate = row.original.completionRate;
return (
<div className="text-center">
<span className={`font-medium ${completionRate >= 80 ? 'text-green-600' : completionRate >= 50 ? 'text-yellow-600' : 'text-red-600'}`}>
{completionRate}%
</span>
</div>
)
case "requestedAt":
return formatDateTime(new Date(row.original.requestedAt))
case "lastRespondedAt":
const lastRespondedAt = row.original.lastRespondedAt;
return lastRespondedAt ? formatDateTime(new Date(lastRespondedAt)) : "-";
default:
return row.getValue(cfg.id) ?? ""
}
},
size: cfg.size,
minSize: cfg.minSize,
maxSize: cfg.maxSize,
}
groupMap[groupName].push(columnDef)
})
// ----------------------------------------------------------------
// 5) 그룹별 중첩 컬럼 생성
// ----------------------------------------------------------------
const nestedColumns: ColumnDef<VendorRfqResponseSummary>[] = []
Object.entries(groupMap).forEach(([groupName, colDefs]) => {
if (groupName === "_noGroup") {
// 그룹이 없는 컬럼들은 직접 추가
nestedColumns.push(...colDefs)
} else {
// 그룹이 있는 컬럼들은 중첩 구조로 추가
nestedColumns.push({
id: groupName,
header: groupName,
columns: colDefs,
})
}
})
// ----------------------------------------------------------------
// 6) 최종 컬럼 배열
// ----------------------------------------------------------------
return [
selectColumn,
...nestedColumns,
actionsColumn,
]
}
|