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
|
// components/rfq/request-revision-dialog.tsx
"use client";
import { useState, useTransition } from "react";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import {
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form";
import { Textarea } from "@/components/ui/textarea";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import * as z from "zod";
import { AlertTriangle, Loader2 } from "lucide-react";
import { useToast } from "@/hooks/use-toast";
import { requestRevision } from "../service";
const revisionFormSchema = z.object({
revisionReason: z
.string()
.min(10, "수정 요청 사유를 최소 10자 이상 입력해주세요")
.max(500, "수정 요청 사유는 500자를 초과할 수 없습니다"),
});
type RevisionFormData = z.infer<typeof revisionFormSchema>;
interface RequestRevisionDialogProps {
responseId: number;
attachmentType: string;
serialNo: string;
vendorName?: string;
currentRevision: string;
trigger?: React.ReactNode;
onSuccess?: () => void;
}
export function RequestRevisionDialog({
responseId,
attachmentType,
serialNo,
vendorName,
currentRevision,
trigger,
onSuccess,
}: RequestRevisionDialogProps) {
const [open, setOpen] = useState(false);
const [isPending, startTransition] = useTransition();
const { toast } = useToast();
const form = useForm<RevisionFormData>({
resolver: zodResolver(revisionFormSchema),
defaultValues: {
revisionReason: "",
},
});
const handleOpenChange = (newOpen: boolean) => {
setOpen(newOpen);
// 다이얼로그가 닫힐 때 form 리셋
if (!newOpen) {
form.reset();
}
};
const handleCancel = () => {
form.reset();
setOpen(false);
};
const onSubmit = async (data: RevisionFormData) => {
startTransition(async () => {
try {
const result = await requestRevision(responseId, data.revisionReason);
if (!result.success) {
throw new Error(result.message);
}
toast({
title: "수정 요청 완료",
description: result.message,
});
setOpen(false);
form.reset();
onSuccess?.();
} catch (error) {
console.error("Request revision error:", error);
toast({
title: "수정 요청 실패",
description: error instanceof Error ? error.message : "알 수 없는 오류가 발생했습니다.",
variant: "destructive",
});
}
});
};
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogTrigger asChild>
{trigger || (
<Button size="sm" variant="outline">
<AlertTriangle className="h-3 w-3 mr-1" />
수정요청
</Button>
)}
</DialogTrigger>
<DialogContent className="max-w-lg">
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<AlertTriangle className="h-5 w-5 text-orange-600" />
수정 요청
</DialogTitle>
<div className="flex items-center gap-2 text-sm text-muted-foreground">
<Badge variant="outline">{serialNo}</Badge>
<span>{attachmentType}</span>
<Badge variant="secondary">{currentRevision}</Badge>
{vendorName && (
<>
<span>•</span>
<span>{vendorName}</span>
</>
)}
</div>
</DialogHeader>
<div className="space-y-4">
<div className="bg-orange-50 border border-orange-200 rounded-lg p-4">
<div className="flex items-start gap-2">
<AlertTriangle className="h-4 w-4 text-orange-600 mt-0.5 flex-shrink-0" />
<div className="text-sm text-orange-800">
<p className="font-medium mb-1">수정 요청 안내</p>
<p>
벤더에게 현재 제출된 응답에 대한 수정을 요청합니다.
수정 요청 후 벤더는 새로운 파일을 다시 제출할 수 있습니다.
</p>
</div>
</div>
</div>
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
<FormField
control={form.control}
name="revisionReason"
render={({ field }) => (
<FormItem>
<FormLabel className="text-base font-medium">
수정 요청 사유 <span className="text-red-500">*</span>
</FormLabel>
<FormControl>
<Textarea
placeholder="수정이 필요한 구체적인 사유를 입력해주세요... 예: 제출된 도면에서 치수 정보가 누락되었습니다."
className="resize-none"
rows={4}
disabled={isPending}
{...field}
/>
</FormControl>
<div className="flex justify-between text-xs text-muted-foreground">
<FormMessage />
<span>{field.value?.length || 0}/500</span>
</div>
</FormItem>
)}
/>
<div className="flex justify-end gap-2 pt-2">
<Button
type="button"
variant="outline"
onClick={handleCancel}
disabled={isPending}
>
취소
</Button>
<Button
type="submit"
disabled={isPending}
// className="bg-orange-600 hover:bg-orange-700"
>
{isPending && <Loader2 className="h-4 w-4 mr-2 animate-spin" />}
{isPending ? "요청 중..." : "수정 요청"}
</Button>
</div>
</form>
</Form>
</div>
</DialogContent>
</Dialog>
);
}
|