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
|
"use client"
import * as React from "react"
import { useRouter } from "next/navigation"
import {
Card,
CardContent,
CardHeader,
CardTitle,
CardDescription,
CardFooter
} from "@/components/ui/card"
import { Button } from "@/components/ui/button"
import { Badge } from "@/components/ui/badge"
import { Textarea } from "@/components/ui/textarea"
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle
} from "@/components/ui/dialog"
import { useToast } from "@/hooks/use-toast"
import { CheckCircle, AlertCircle, FileText, Paperclip } from "lucide-react"
import { PQGroupData } from "@/lib/pq/service"
import { approvePQAction, rejectPQAction } from "@/lib/pq/service"
// PQ 제출 정보 타입
interface PQSubmission {
id: number
vendorId: number
vendorName: string
vendorCode: string
type: string
status: string
projectId: number | null
projectName: string | null
projectCode: string | null
submittedAt: Date | null
approvedAt: Date | null
rejectedAt: Date | null
rejectReason: string | null
}
interface PQReviewWrapperProps {
pqData: PQGroupData[]
vendorId: number
pqSubmission: PQSubmission
canReview: boolean
}
export function PQReviewWrapper({
pqData,
vendorId,
pqSubmission,
canReview
}: PQReviewWrapperProps) {
const router = useRouter()
const { toast } = useToast()
const [isApproving, setIsApproving] = React.useState(false)
const [isRejecting, setIsRejecting] = React.useState(false)
const [showApproveDialog, setShowApproveDialog] = React.useState(false)
const [showRejectDialog, setShowRejectDialog] = React.useState(false)
const [rejectReason, setRejectReason] = React.useState("")
// PQ 승인 처리
const handleApprove = async () => {
try {
setIsApproving(true)
const result = await approvePQAction({
pqSubmissionId: pqSubmission.id,
vendorId: vendorId
})
if (result.ok) {
toast({
title: "PQ 승인 완료",
description: "PQ가 성공적으로 승인되었습니다.",
})
// 페이지 새로고침
router.refresh()
} else {
toast({
title: "승인 실패",
description: result.error || "PQ 승인 중 오류가 발생했습니다.",
variant: "destructive"
})
}
} catch (error) {
console.error("PQ 승인 오류:", error)
toast({
title: "승인 실패",
description: "PQ 승인 중 오류가 발생했습니다.",
variant: "destructive"
})
} finally {
setIsApproving(false)
setShowApproveDialog(false)
}
}
// PQ 거부 처리
const handleReject = async () => {
if (!rejectReason.trim()) {
toast({
title: "거부 사유 필요",
description: "거부 사유를 입력해주세요.",
variant: "destructive"
})
return
}
try {
setIsRejecting(true)
const result = await rejectPQAction({
pqSubmissionId: pqSubmission.id,
vendorId: vendorId,
rejectReason: rejectReason
})
if (result.ok) {
toast({
title: "PQ 거부 완료",
description: "PQ가 거부되었습니다.",
})
// 페이지 새로고침
router.refresh()
} else {
toast({
title: "거부 실패",
description: result.error || "PQ 거부 중 오류가 발생했습니다.",
variant: "destructive"
})
}
} catch (error) {
console.error("PQ 거부 오류:", error)
toast({
title: "거부 실패",
description: "PQ 거부 중 오류가 발생했습니다.",
variant: "destructive"
})
} finally {
setIsRejecting(false)
setShowRejectDialog(false)
}
}
return (
<div className="space-y-6">
{/* 그룹별 PQ 항목 표시 */}
{pqData.map((group) => (
<div key={group.groupName} className="space-y-4">
<h3 className="text-lg font-medium">{group.groupName}</h3>
<div className="grid grid-cols-1 gap-4">
{group.items.map((item) => (
<Card key={item.criteriaId}>
<CardHeader>
<div className="flex justify-between items-start">
<div>
<CardTitle className="text-base">
{item.code} - {item.checkPoint}
</CardTitle>
{item.description && (
<CardDescription className="mt-1 whitespace-pre-wrap">
{item.description}
</CardDescription>
)}
</div>
{/* 항목 상태 표시 */}
{!!item.answer || item.attachments.length > 0 ? (
<Badge variant="outline" className="text-green-600 bg-green-50">
<CheckCircle className="h-3 w-3 mr-1" />
답변 있음
</Badge>
) : (
<Badge variant="outline" className="text-amber-600 bg-amber-50">
<AlertCircle className="h-3 w-3 mr-1" />
답변 없음
</Badge>
)}
</div>
</CardHeader>
<CardContent className="space-y-4">
{/* 프로젝트별 추가 정보 */}
{pqSubmission.projectId && item.contractInfo && (
<div className="space-y-1">
<p className="text-sm font-medium">계약 정보</p>
<div className="rounded-md bg-muted/30 p-3 text-sm whitespace-pre-wrap">
{item.contractInfo}
</div>
</div>
)}
{pqSubmission.projectId && item.additionalRequirement && (
<div className="space-y-1">
<p className="text-sm font-medium">추가 요구사항</p>
<div className="rounded-md bg-muted/30 p-3 text-sm whitespace-pre-wrap">
{item.additionalRequirement}
</div>
</div>
)}
{/* 벤더 답변 */}
<div className="space-y-1">
<p className="text-sm font-medium flex items-center gap-1">
<FileText className="h-4 w-4" />
벤더 답변
</p>
<div className="rounded-md border p-3 min-h-20 whitespace-pre-wrap">
{item.answer || <span className="text-muted-foreground">답변 없음</span>}
</div>
</div>
{/* 첨부 파일 */}
{item.attachments.length > 0 && (
<div className="space-y-1">
<p className="text-sm font-medium flex items-center gap-1">
<Paperclip className="h-4 w-4" />
첨부 파일 ({item.attachments.length})
</p>
<div className="rounded-md border p-3">
<ul className="space-y-1">
{item.attachments.map((attachment, idx) => (
<li key={idx} className="flex items-center gap-2">
<FileText className="h-4 w-4 text-muted-foreground" />
<a
href={attachment.filePath}
target="_blank"
rel="noopener noreferrer"
className="text-sm text-blue-600 hover:underline"
>
{attachment.fileName}
</a>
</li>
))}
</ul>
</div>
</div>
)}
</CardContent>
</Card>
))}
</div>
</div>
))}
{/* 검토 버튼 */}
{canReview && (
<div className="fixed bottom-4 right-4 bg-background p-4 rounded-lg shadow-md border">
<div className="flex gap-2">
<Button
variant="outline"
onClick={() => setShowRejectDialog(true)}
disabled={isRejecting}
>
{isRejecting ? "거부 중..." : "거부"}
</Button>
<Button
variant="default"
onClick={() => setShowApproveDialog(true)}
disabled={isApproving}
>
{isApproving ? "승인 중..." : "승인"}
</Button>
</div>
</div>
)}
{/* 승인 확인 다이얼로그 */}
<Dialog open={showApproveDialog} onOpenChange={setShowApproveDialog}>
<DialogContent>
<DialogHeader>
<DialogTitle>PQ 승인 확인</DialogTitle>
<DialogDescription>
{pqSubmission.vendorName}의 {pqSubmission.type === "GENERAL" ? "일반" : "프로젝트"} PQ를 승인하시겠습니까?
{pqSubmission.projectId && (
<span> 프로젝트: {pqSubmission.projectName}</span>
)}
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button variant="outline" onClick={() => setShowApproveDialog(false)}>
취소
</Button>
<Button onClick={handleApprove} disabled={isApproving}>
{isApproving ? "승인 중..." : "승인"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
{/* 거부 확인 다이얼로그 */}
<Dialog open={showRejectDialog} onOpenChange={setShowRejectDialog}>
<DialogContent>
<DialogHeader>
<DialogTitle>PQ 거부</DialogTitle>
<DialogDescription>
{pqSubmission.vendorName}의 {pqSubmission.type === "GENERAL" ? "일반" : "프로젝트"} PQ를 거부하는 이유를 입력해주세요.
{pqSubmission.projectId && (
<span> 프로젝트: {pqSubmission.projectName}</span>
)}
</DialogDescription>
</DialogHeader>
<Textarea
value={rejectReason}
onChange={(e) => setRejectReason(e.target.value)}
placeholder="거부 사유를 입력하세요"
className="min-h-24"
/>
<DialogFooter>
<Button variant="outline" onClick={() => setShowRejectDialog(false)}>
취소
</Button>
<Button
variant="destructive"
onClick={handleReject}
disabled={isRejecting || !rejectReason.trim()}
>
{isRejecting ? "거부 중..." : "거부"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
)
}
|