From 7a1524ba54f43d0f2a19e4bca2c6a2e0b01c5ef1 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Tue, 17 Jun 2025 09:02:32 +0000 Subject: (대표님) 20250617 18시 작업사항 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/b-rfq/vendor-response/comment-edit-dialog.tsx | 187 ++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 lib/b-rfq/vendor-response/comment-edit-dialog.tsx (limited to 'lib/b-rfq/vendor-response/comment-edit-dialog.tsx') diff --git a/lib/b-rfq/vendor-response/comment-edit-dialog.tsx b/lib/b-rfq/vendor-response/comment-edit-dialog.tsx new file mode 100644 index 00000000..0c2c0c62 --- /dev/null +++ b/lib/b-rfq/vendor-response/comment-edit-dialog.tsx @@ -0,0 +1,187 @@ +// components/rfq/comment-edit-dialog.tsx +"use client"; + +import { useState } from "react"; +import { Button } from "@/components/ui/button"; +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 { MessageSquare, Loader2 } from "lucide-react"; +import { useToast } from "@/hooks/use-toast"; +import { useRouter } from "next/navigation"; + +const commentFormSchema = z.object({ + responseComment: z.string().optional(), + vendorComment: z.string().optional(), +}); + +type CommentFormData = z.infer; + +interface CommentEditDialogProps { + responseId: number; + currentResponseComment?: string; + currentVendorComment?: string; + trigger?: React.ReactNode; + onSuccess?: () => void; +} + +export function CommentEditDialog({ + responseId, + currentResponseComment, + currentVendorComment, + trigger, + onSuccess, +}: CommentEditDialogProps) { + const [open, setOpen] = useState(false); + const [isSaving, setIsSaving] = useState(false); + const { toast } = useToast(); + const router = useRouter(); + + const form = useForm({ + resolver: zodResolver(commentFormSchema), + defaultValues: { + responseComment: currentResponseComment || "", + vendorComment: currentVendorComment || "", + }, + }); + + const onSubmit = async (data: CommentFormData) => { + setIsSaving(true); + + try { + const response = await fetch("/api/vendor-responses/update-comment", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + responseId, + responseComment: data.responseComment, + vendorComment: data.vendorComment, + }), + }); + + if (!response.ok) { + const error = await response.json(); + throw new Error(error.message || "코멘트 업데이트 실패"); + } + + toast({ + title: "코멘트 업데이트 완료", + description: "코멘트가 성공적으로 업데이트되었습니다.", + }); + + setOpen(false); + + router.refresh(); + onSuccess?.(); + + } catch (error) { + console.error("Comment update error:", error); + toast({ + title: "업데이트 실패", + description: error instanceof Error ? error.message : "알 수 없는 오류가 발생했습니다.", + variant: "destructive", + }); + } finally { + setIsSaving(false); + } + }; + + return ( + + + {trigger || ( + + )} + + + + + + 코멘트 수정 + + + +
+ + {/* 응답 코멘트 */} + ( + + 응답 코멘트 + +