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
|
"use client"
import * as React from "react"
import { type DataTableRowAction } from "@/types/table"
import { type ColumnDef } from "@tanstack/react-table"
import { Ellipsis } from "lucide-react"
import Link from "next/link"
import { formatDate } from "@/lib/utils"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header"
import { techVendorRfqHistoryColumnsConfig } from "@/config/techVendorRfqHistoryColumnsConfig"
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
export interface TechVendorRfqHistoryRow {
id: number;
rfqCode: string | null;
description: string | null;
projectCode: string | null;
projectName: string | null;
projectType: string | null; // 프로젝트 타입 추가
status: string;
totalAmount: string | null;
currency: string | null;
dueDate: Date | null;
createdAt: Date;
quotationCode: string | null;
submittedAt: Date | null;
}
// 프로젝트 타입에 따른 RFQ 페이지 URL 생성 함수
function getRfqPageUrl(projectType: string | null, description: string | null): string {
const baseUrls = {
'SHIP': '/evcp/budgetary-tech-sales-ship',
'TOP': '/evcp/budgetary-tech-sales-top',
'HULL': '/evcp/budgetary-tech-sales-hull'
};
const url = baseUrls[projectType as keyof typeof baseUrls] || '/evcp/budgetary-tech-sales-ship';
// description이 있으면 search 파라미터로 추가
if (description) {
return `${url}?search=${encodeURIComponent(description)}`;
}
return url;
}
// 프로젝트 타입 표시 함수
function getProjectTypeDisplay(projectType: string | null): string {
const typeMap = {
'SHIP': '조선',
'TOP': '해양TOP',
'HULL': '해양HULL'
};
return typeMap[projectType as keyof typeof typeMap] || projectType || '-';
}
interface GetColumnsProps {
setRowAction: React.Dispatch<React.SetStateAction<DataTableRowAction<TechVendorRfqHistoryRow> | null>>;
}
export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef<TechVendorRfqHistoryRow>[] {
// ----------------------------------------------------------------
// 1) select 컬럼 (체크박스)
// ----------------------------------------------------------------
const selectColumn: ColumnDef<TechVendorRfqHistoryRow> = {
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 컬럼 (Dropdown 메뉴)
// ----------------------------------------------------------------
// const actionsColumn: ColumnDef<TechVendorRfqHistoryRow> = {
// id: "actions",
// enableHiding: false,
// cell: function Cell({ row }) {
// return (
// <DropdownMenu>
// <DropdownMenuTrigger asChild>
// <Button
// aria-label="Open menu"
// variant="ghost"
// className="flex size-8 p-0 data-[state=open]:bg-muted"
// >
// <Ellipsis className="size-4" aria-hidden="true" />
// </Button>
// </DropdownMenuTrigger>
// <DropdownMenuContent align="end" className="w-40">
// <DropdownMenuItem
// onSelect={() => setRowAction({ row, type: "update" })}
// >
// View Details
// </DropdownMenuItem>
// </DropdownMenuContent>
// </DropdownMenu>
// )
// },
// size: 40,
// }
// ----------------------------------------------------------------
// 3) 일반 컬럼들
// ----------------------------------------------------------------
const basicColumns: ColumnDef<TechVendorRfqHistoryRow>[] = techVendorRfqHistoryColumnsConfig.map((cfg) => {
const column: ColumnDef<TechVendorRfqHistoryRow> = {
accessorKey: cfg.id,
header: ({ column }) => (
<DataTableColumnHeaderSimple column={column} title={cfg.label} />
),
size: cfg.size,
}
if (cfg.id === "rfqCode") {
column.cell = ({ row }) => {
const rfqCode = row.original.rfqCode
const projectType = row.original.projectType
if (!rfqCode) return null
const rfqUrl = getRfqPageUrl(projectType, rfqCode);
return (
<Tooltip>
<TooltipTrigger asChild>
<Link
href={rfqUrl}
className="break-words whitespace-normal line-clamp-2 hover:underline cursor-pointer"
>
{rfqCode}
</Link>
</TooltipTrigger>
<TooltipContent side="bottom" className="max-w-[400px] whitespace-pre-wrap break-words">
<div>
<div className="font-medium">{rfqCode}</div>
<div className="text-xs text-muted-foreground mt-1">
클릭하여 RFQ 페이지로 이동
</div>
</div>
</TooltipContent>
</Tooltip>
)
}
}
if (cfg.id === "projectType") {
column.cell = ({ row }) => {
const projectType = row.original.projectType
return (
<div className="whitespace-nowrap">
{getProjectTypeDisplay(projectType)}
</div>
)
}
}
if (cfg.id === "status") {
column.cell = ({ row }) => {
const statusVal = row.original.status
if (!statusVal) return null
return (
<div className="flex items-center">
<span className="capitalize">{statusVal}</span>
</div>
)
}
}
if (cfg.id === "totalAmount") {
column.cell = ({ row }) => {
const amount = row.original.totalAmount
const currency = row.original.currency
if (!amount || !currency) return <span className="text-gray-400">-</span>
return (
<div className="whitespace-nowrap">
{`${currency} ${Number(amount).toLocaleString()}`}
</div>
)
}
}
if (cfg.id === "dueDate" || cfg.id === "createdAt") {
column.cell = ({ row }) => {
const dateValue = row.getValue(cfg.id) as Date
if (!dateValue) return <span className="text-gray-400">-</span>
return (
<div className="whitespace-nowrap">
{formatDate(dateValue)}
</div>
)
}
}
if (cfg.id === "projectCode" || cfg.id === "projectName") {
column.cell = ({ row }) => {
const value = row.getValue(cfg.id) as string | null
if (!value) return <span className="text-gray-400">-</span>
return value
}
column.size = 100;
}
return column
})
// ----------------------------------------------------------------
// 4) 최종 컬럼 배열
// ----------------------------------------------------------------
return [
selectColumn,
...basicColumns,
// actionsColumn,
]
}
|