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
|
"use client";
import { ColumnDef } from "@tanstack/react-table";
import { DetailDwgReceiptItem } from "../actions";
import { formatDolceDateTime } from "../utils/date-formatter";
import { useState } from "react";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { Edit } from "lucide-react";
// Comment Dialog Component
function CommentDialog({ comment }: { comment: string }) {
const [open, setOpen] = useState(false);
return (
<>
<Button
variant="ghost"
className="h-auto py-1 px-2 text-left justify-start font-normal hover:bg-accent"
onClick={() => setOpen(true)}
>
<div className="truncate max-w-[200px]">{comment || "-"}</div>
</Button>
<Dialog open={open} onOpenChange={setOpen}>
<DialogContent className="max-w-2xl">
<DialogHeader>
<DialogTitle>Comment</DialogTitle>
</DialogHeader>
<div className="max-h-96 overflow-y-auto">
<p className="whitespace-pre-wrap text-sm">{comment || "코멘트가 없습니다."}</p>
</div>
</DialogContent>
</Dialog>
</>
);
}
// 다국어 지원 컬럼 생성 함수
export function createDetailDrawingColumns(
lng: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
t: any,
onEdit?: (detailDrawing: DetailDwgReceiptItem) => void
): ColumnDef<DetailDwgReceiptItem>[] {
return [
{
accessorKey: "RegisterSerialNo",
header: t("detailDrawing.columns.serialNo"),
minSize: 120,
cell: ({ row }) => {
const val = row.getValue("RegisterSerialNo") as number;
const status = row.getValue("Status") as string;
if (val === 0 || status === "EVCP Saved") {
return <div className="text-center">-</div>;
}
return <div className="text-center">{val}</div>;
},
},
{
accessorKey: "DrawingRevNo",
header: t("detailDrawing.columns.revNo"),
minSize: 100,
cell: ({ row }) => {
return <div className="font-medium">{row.getValue("DrawingRevNo")}</div>;
},
},
{
accessorKey: "Status",
header: t("detailDrawing.columns.status"),
minSize: 120,
cell: ({ row }) => {
return <div className="text-center">{row.getValue("Status")}</div>;
},
},
{
accessorKey: "CategoryENM",
header: t("detailDrawing.columns.category"),
minSize: 120,
cell: ({ row }) => {
// 항상 CategoryENM 필드를 보여줌
return <div>{row.getValue("CategoryENM")}</div>;
},
},
// RegisterKind 로 DrawingUsage를 알 수 있으므로 주석 처리
// {
// accessorKey: "DrawingUsage",
// header: t("detailDrawing.columns.drawingUsage"),
// minSize: 100,
// cell: ({ row }) => {
// // API 응답의 DrawingUsage는 코드값이므로 직접 매핑하여 번역
// const usageCode = row.getValue("DrawingUsage") as string;
// const translated = translateDrawingUsage(usageCode, lng);
// return <div>{translated}</div>;
// },
// },
{
accessorKey: "RegisterKindENM",
header: t("detailDrawing.columns.registerKind"),
minSize: 180,
cell: ({ row }) => {
// 항상 RegisterKindENM 필드를 보여줌
return <div>{row.getValue("RegisterKindENM") || row.original.RegisterKind}</div>;
},
},
{
accessorKey: "CreateUserNM",
header: t("detailDrawing.columns.createdBy"),
minSize: 150,
cell: ({ row }) => {
const userENM = row.original.CreateUserENM;
const userNM = row.getValue("CreateUserNM") as string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const localUserName = (row.original as any).userName;
if (localUserName) return <div>{localUserName}</div>;
return <div>{lng === "en" ? (userENM || userNM) : (userNM || userENM)}</div>;
},
},
{
accessorKey: "CreateDt",
header: t("detailDrawing.columns.createdAt"),
minSize: 200,
cell: ({ row }) => {
const date = row.getValue("CreateDt") as string;
return <div className="text-sm text-muted-foreground">{formatDolceDateTime(date)}</div>;
},
},
{
accessorKey: "RegisterDesc",
header: "Comment",
minSize: 200,
maxSize: 200,
cell: ({ row }) => {
const comment = row.getValue("RegisterDesc") as string;
return <CommentDialog comment={comment} />;
},
},
{
id: "actions",
header: t("detailDrawing.columns.actions"),
minSize: 100,
maxSize: 100,
cell: ({ row }) => {
const status = row.getValue("Status") as string;
const isEditable = status === "Submitted";
return (
<div
className="flex items-center justify-center"
onClick={(e) => e.stopPropagation()}
>
<Button
variant="ghost"
size="sm"
disabled={!isEditable || !onEdit}
onClick={(e) => {
e.stopPropagation();
if (onEdit) onEdit(row.original);
}}
title={!isEditable ? t("editDetailDialog.statusSubmittedOnly") : t("editDetailDialog.editButton")}
>
<Edit className="h-4 w-4" />
</Button>
</div>
);
},
},
];
}
|