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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
|
"use client"
import * as React from "react"
import { type DataTableRowAction } from "@/types/table"
import { type ColumnDef } from "@tanstack/react-table"
import { Ellipsis, Eye, Calendar, AlertTriangle, CheckCircle2, Clock, FileText } from "lucide-react"
import { formatDate, cn } from "@/lib/utils"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import { Progress } from "@/components/ui/progress"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { useRouter } from "next/navigation"
import { RfqDashboardView } from "@/db/schema"
import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header"
type NextRouter = ReturnType<typeof useRouter>;
interface GetRFQColumnsProps {
setRowAction: React.Dispatch<React.SetStateAction<DataTableRowAction<RfqDashboardView> | null>>;
router: NextRouter;
}
// 상태에 따른 Badge 변형 결정 함수
function getStatusBadge(status: string) {
switch (status) {
case "DRAFT":
return { variant: "outline" as const, label: "초안" };
case "Doc. Received":
return { variant: "secondary" as const, label: "문서접수" };
case "PIC Assigned":
return { variant: "secondary" as const, label: "담당자배정" };
case "Doc. Confirmed":
return { variant: "default" as const, label: "문서확정" };
case "Init. RFQ Sent":
return { variant: "default" as const, label: "초기RFQ발송" };
case "Init. RFQ Answered":
return { variant: "default" as const, label: "초기RFQ회신" };
case "TBE started":
return { variant: "secondary" as const, label: "TBE시작" };
case "TBE finished":
return { variant: "secondary" as const, label: "TBE완료" };
case "Final RFQ Sent":
return { variant: "default" as const, label: "최종RFQ발송" };
case "Quotation Received":
return { variant: "default" as const, label: "견적접수" };
case "Vendor Selected":
return { variant: "success" as const, label: "업체선정" };
default:
return { variant: "outline" as const, label: status };
}
}
function getProgressBadge(progress: number) {
if (progress >= 100) {
return { variant: "success" as const, label: "완료" };
} else if (progress >= 70) {
return { variant: "default" as const, label: "진행중" };
} else if (progress >= 30) {
return { variant: "secondary" as const, label: "초기진행" };
} else {
return { variant: "outline" as const, label: "시작" };
}
}
function getUrgencyLevel(daysToDeadline: number): "high" | "medium" | "low" {
if (daysToDeadline <= 3) return "high";
if (daysToDeadline <= 7) return "medium";
return "low";
}
export function getRFQColumns({ setRowAction, router }: GetRFQColumnsProps): ColumnDef<RfqDashboardView>[] {
// Select 컬럼
const selectColumn: ColumnDef<RfqDashboardView> = {
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,
};
// RFQ 코드 컬럼
const rfqCodeColumn: ColumnDef<RfqDashboardView> = {
accessorKey: "rfqCode",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="RFQ 코드" />
),
cell: ({ row }) => (
<div className="flex flex-col">
<span className="font-medium">{row.getValue("rfqCode")}</span>
{row.original.description && (
<span className="text-xs text-muted-foreground truncate max-w-[200px]">
{row.original.description}
</span>
)}
</div>
),
};
// 프로젝트 정보 컬럼
const projectColumn: ColumnDef<RfqDashboardView> = {
accessorKey: "projectName",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="프로젝트" />
),
cell: ({ row }) => {
const projectName = row.original.projectName;
const projectCode = row.original.projectCode;
if (!projectName) {
return <span className="text-muted-foreground">-</span>;
}
return (
<div className="flex flex-col">
<span className="font-medium">{projectName}</span>
<div className="flex items-center gap-2 text-xs text-muted-foreground">
{projectCode && <span>{projectCode}</span>}
</div>
</div>
);
},
};
// 패키지 정보 컬럼
const packageColumn: ColumnDef<RfqDashboardView> = {
accessorKey: "packageNo",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="패키지" />
),
cell: ({ row }) => {
const packageNo = row.original.packageNo;
const packageName = row.original.packageName;
if (!packageNo) {
return <span className="text-muted-foreground">-</span>;
}
return (
<div className="flex flex-col">
<span className="font-medium">{packageNo}</span>
{packageName && (
<span className="text-xs text-muted-foreground truncate max-w-[150px]">
{packageName}
</span>
)}
</div>
);
},
};
const updatedColumn: ColumnDef<RfqDashboardView> = {
accessorKey: "updatedBy",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="Updated By" />
),
cell: ({ row }) => {
const updatedByName = row.original.updatedByName;
const updatedByEmail = row.original.updatedByEmail;
if (!updatedByName) {
return <span className="text-muted-foreground">-</span>;
}
return (
<div className="flex flex-col">
<span className="font-medium">{updatedByName}</span>
{updatedByEmail && (
<span className="text-xs text-muted-foreground truncate max-w-[150px]">
{updatedByEmail}
</span>
)}
</div>
);
},
};
// 상태 컬럼
const statusColumn: ColumnDef<RfqDashboardView> = {
accessorKey: "status",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="상태" />
),
cell: ({ row }) => {
const statusBadge = getStatusBadge(row.original.status);
return <Badge variant={statusBadge.variant}>{statusBadge.label}</Badge>;
},
filterFn: (row, id, value) => {
return value.includes(row.getValue(id));
},
};
// 진행률 컬럼
const progressColumn: ColumnDef<RfqDashboardView> = {
accessorKey: "overallProgress",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="진행률" />
),
cell: ({ row }) => {
const progress = row.original.overallProgress;
const progressBadge = getProgressBadge(progress);
return (
<div className="flex flex-col gap-1 min-w-[120px]">
<div className="flex items-center justify-between">
<span className="text-sm font-medium">{progress}%</span>
<Badge variant={progressBadge.variant} className="text-xs">
{progressBadge.label}
</Badge>
</div>
<Progress value={progress} className="h-2" />
</div>
);
},
};
// 마감일 컬럼
const dueDateColumn: ColumnDef<RfqDashboardView> = {
accessorKey: "dueDate",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="마감일" />
),
cell: ({ row }) => {
const dueDate = row.original.dueDate;
const daysToDeadline = row.original.daysToDeadline;
const urgencyLevel = getUrgencyLevel(daysToDeadline);
if (!dueDate) {
return <span className="text-muted-foreground">-</span>;
}
return (
<div className="flex flex-col">
<div className="flex items-center gap-2">
<Calendar className="h-4 w-4 text-muted-foreground" />
<span>{formatDate(dueDate, 'KR')}</span>
</div>
<div className="flex items-center gap-1 text-xs">
{urgencyLevel === "high" && (
<AlertTriangle className="h-3 w-3 text-red-500" />
)}
{urgencyLevel === "medium" && (
<Clock className="h-3 w-3 text-yellow-500" />
)}
{urgencyLevel === "low" && (
<CheckCircle2 className="h-3 w-3 text-green-500" />
)}
<span className={cn(
urgencyLevel === "high" && "text-red-500",
urgencyLevel === "medium" && "text-yellow-600",
urgencyLevel === "low" && "text-green-600"
)}>
{daysToDeadline > 0 ? `${daysToDeadline}일 남음` :
daysToDeadline === 0 ? "오늘 마감" :
`${Math.abs(daysToDeadline)}일 지남`}
</span>
</div>
</div>
);
},
};
// 담당자 컬럼
const picColumn: ColumnDef<RfqDashboardView> = {
accessorKey: "picName",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="구매 담당자" />
),
cell: ({ row }) => {
const picName = row.original.picName;
return picName ? (
<span>{picName}</span>
) : (
<span className="text-muted-foreground">미배정</span>
);
},
};
const engPicColumn: ColumnDef<RfqDashboardView> = {
accessorKey: "engPicName",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="설계 담당자" />
),
cell: ({ row }) => {
const picName = row.original.engPicName;
return picName ? (
<span>{picName}</span>
) : (
<span className="text-muted-foreground">미배정</span>
);
},
};
const pjtCompanyColumn: ColumnDef<RfqDashboardView> = {
accessorKey: "projectCompany",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="프로젝트 Company" />
),
cell: ({ row }) => {
const projectCompany = row.original.projectCompany;
return projectCompany ? (
<span>{projectCompany}</span>
) : (
<span className="text-muted-foreground">-</span>
);
},
};
const pjtFlagColumn: ColumnDef<RfqDashboardView> = {
accessorKey: "projectFlag",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="프로젝트 Flag" />
),
cell: ({ row }) => {
const projectFlag = row.original.projectFlag;
return projectFlag ? (
<span>{projectFlag}</span>
) : (
<span className="text-muted-foreground">-</span>
);
},
};
const pjtSiteColumn: ColumnDef<RfqDashboardView> = {
accessorKey: "projectSite",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="프로젝트 Site" />
),
cell: ({ row }) => {
const projectSite = row.original.projectSite;
return projectSite ? (
<span>{projectSite}</span>
) : (
<span className="text-muted-foreground">-</span>
);
},
};
const remarkColumn: ColumnDef<RfqDashboardView> = {
accessorKey: "remark",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="비고" />
),
cell: ({ row }) => {
const remark = row.original.remark;
return remark ? (
<span>{remark}</span>
) : (
<span className="text-muted-foreground">-</span>
);
},
};
// 첨부파일 수 컬럼
const attachmentColumn: ColumnDef<RfqDashboardView> = {
accessorKey: "totalAttachments",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="첨부파일" />
),
cell: ({ row }) => {
const count = row.original.totalAttachments;
return (
<div className="flex items-center gap-2">
<FileText className="h-4 w-4 text-muted-foreground" />
<span>{count}</span>
</div>
);
},
};
// 벤더 현황 컬럼
const vendorStatusColumn: ColumnDef<RfqDashboardView> = {
accessorKey: "initialVendorCount",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="벤더 현황" />
),
cell: ({ row }) => {
const initial = row.original.initialVendorCount;
const final = row.original.finalVendorCount;
const initialRate = row.original.initialResponseRate;
const finalRate = row.original.finalResponseRate;
return (
<div className="flex flex-col gap-1 text-xs">
<div className="flex items-center justify-between">
<span className="text-muted-foreground">초기:</span>
<span>{initial}개사 ({initialRate}%)</span>
</div>
<div className="flex items-center justify-between">
<span className="text-muted-foreground">최종:</span>
<span>{final}개사 ({finalRate}%)</span>
</div>
</div>
);
},
};
// 생성일 컬럼
const createdAtColumn: ColumnDef<RfqDashboardView> = {
accessorKey: "createdAt",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="생성일" />
),
cell: ({ row }) => {
const dateVal = row.original.createdAt as Date;
return formatDate(dateVal, 'KR');
},
};
const updatedAtColumn: ColumnDef<RfqDashboardView> = {
accessorKey: "updatedAt",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="수정일" />
),
cell: ({ row }) => {
const dateVal = row.original.updatedAt as Date;
return formatDate(dateVal, 'KR');
},
};
// Actions 컬럼
const actionsColumn: ColumnDef<RfqDashboardView> = {
id: "detail",
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title="상세내용" />
),
// enableHiding: false,
cell: function Cell({ row }) {
const rfq = row.original;
const detailUrl = `/evcp/b-rfq/${rfq.rfqId}/initial`;
return (
<Button
aria-label="Open menu"
variant="ghost"
className="flex size-8 p-0 data-[state=open]:bg-muted"
onClick={() => router.push(detailUrl)}
>
<Ellipsis className="size-4" aria-hidden="true" />
</Button>
);
},
size: 40,
};
return [
selectColumn,
rfqCodeColumn,
projectColumn,
packageColumn,
statusColumn,
picColumn,
progressColumn,
dueDateColumn,
actionsColumn,
engPicColumn,
pjtCompanyColumn,
pjtFlagColumn,
pjtSiteColumn,
attachmentColumn,
vendorStatusColumn,
createdAtColumn,
updatedAtColumn,
updatedColumn,
remarkColumn
];
}
|