From 2eb717eb2bbfd97a5f149d13049aa336c26c393b Mon Sep 17 00:00:00 2001 From: dujinkim Date: Wed, 29 Oct 2025 07:43:44 +0000 Subject: (최겸) 구매 실사 개발(진행중) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../investigation/supplement-request-dialog.tsx | 336 ++++++++++++++ .../investigation/supplement-response-dialog.tsx | 483 +++++++++++++++++++++ 2 files changed, 819 insertions(+) create mode 100644 components/investigation/supplement-request-dialog.tsx create mode 100644 components/investigation/supplement-response-dialog.tsx (limited to 'components/investigation') diff --git a/components/investigation/supplement-request-dialog.tsx b/components/investigation/supplement-request-dialog.tsx new file mode 100644 index 00000000..c0af36c7 --- /dev/null +++ b/components/investigation/supplement-request-dialog.tsx @@ -0,0 +1,336 @@ +"use client" + +import * as React from "react" +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog" +import { Button } from "@/components/ui/button" +import { Textarea } from "@/components/ui/textarea" +import { Input } from "@/components/ui/input" +import { Label } from "@/components/ui/label" +import { Badge } from "@/components/ui/badge" +import { useToast } from "@/hooks/use-toast" +import { + requestSupplementReinspectionAction, + requestSupplementDocumentAction +} from "@/lib/vendor-investigation/service" + +interface SupplementRequestDialogProps { + open: boolean + onOpenChange: (open: boolean) => void + investigationId: number + investigationMethod: string + vendorName: string +} + +export function SupplementRequestDialog({ + open, + onOpenChange, + investigationId, + investigationMethod, + vendorName +}: SupplementRequestDialogProps) { + const { toast } = useToast() + const [isSubmitting, setIsSubmitting] = React.useState(false) + const [requestType, setRequestType] = React.useState<"REINSPECT" | "DOCUMENT">("REINSPECT") + + // 재실사 요청 데이터 + const [reinspectData, setReinspectData] = React.useState({ + inspectionDuration: 1.0, + requestedStartDate: "", + requestedEndDate: "", + additionalRequests: "" + }) + + // 서류제출 요청 데이터 + const [documentData, setDocumentData] = React.useState({ + requiredDocuments: [""], + additionalRequests: "" + }) + + // 보완 요청이 가능한 실사 방법인지 확인 + const canRequestSupplement = investigationMethod === "PRODUCT_INSPECTION" || + investigationMethod === "SITE_VISIT_EVAL" + + const handleSubmit = async () => { + if (!canRequestSupplement) { + toast({ + title: "보완 요청 불가", + description: "현재 실사 방법에서는 보완 요청을 할 수 없습니다.", + variant: "destructive" + }) + return + } + + try { + setIsSubmitting(true) + + if (requestType === "REINSPECT") { + const result = await requestSupplementReinspectionAction({ + investigationId, + siteVisitData: { + inspectionDuration: reinspectData.inspectionDuration, + requestedStartDate: reinspectData.requestedStartDate ? new Date(reinspectData.requestedStartDate) : undefined, + requestedEndDate: reinspectData.requestedEndDate ? new Date(reinspectData.requestedEndDate) : undefined, + additionalRequests: reinspectData.additionalRequests + } + }) + + if (result.success) { + toast({ + title: "보완-재실사 요청 완료", + description: "재실사 요청이 성공적으로 생성되었습니다.", + }) + onOpenChange(false) + } else { + toast({ + title: "요청 실패", + description: result.error || "재실사 요청 중 오류가 발생했습니다.", + variant: "destructive" + }) + } + } else { + const result = await requestSupplementDocumentAction({ + investigationId, + documentRequests: { + requiredDocuments: documentData.requiredDocuments.filter(doc => doc.trim() !== ""), + additionalRequests: documentData.additionalRequests + } + }) + + if (result.success) { + toast({ + title: "보완-서류제출 요청 완료", + description: "서류제출 요청이 성공적으로 생성되었습니다.", + }) + onOpenChange(false) + } else { + toast({ + title: "요청 실패", + description: result.error || "서류제출 요청 중 오류가 발생했습니다.", + variant: "destructive" + }) + } + } + } catch (error) { + console.error("보완 요청 오류:", error) + toast({ + title: "요청 실패", + description: "보완 요청 중 오류가 발생했습니다.", + variant: "destructive" + }) + } finally { + setIsSubmitting(false) + } + } + + const addDocument = () => { + setDocumentData(prev => ({ + ...prev, + requiredDocuments: [...prev.requiredDocuments, ""] + })) + } + + const removeDocument = (index: number) => { + setDocumentData(prev => ({ + ...prev, + requiredDocuments: prev.requiredDocuments.filter((_, i) => i !== index) + })) + } + + const updateDocument = (index: number, value: string) => { + setDocumentData(prev => ({ + ...prev, + requiredDocuments: prev.requiredDocuments.map((doc, i) => i === index ? value : doc) + })) + } + + if (!canRequestSupplement) { + return ( + + + + 보완 요청 불가 + + 현재 실사 방법({investigationMethod})에서는 보완 요청을 할 수 없습니다. + 보완 요청은 제품검사평가(PRODUCT_INSPECTION) 또는 방문실사평가(SITE_VISIT_EVAL)에서만 가능합니다. + + + + + + + + ) + } + + return ( + + + + 보완 요청 + + {vendorName}에 대한 보완 요청을 생성합니다. + + + +
+ {/* 요청 유형 선택 */} +
+ +
+ + +
+
+ + {/* 재실사 요청 폼 */} + {requestType === "REINSPECT" && ( +
+
+
+ + setReinspectData(prev => ({ + ...prev, + inspectionDuration: parseFloat(e.target.value) || 0 + }))} + /> +
+
+ + + {investigationMethod === "PRODUCT_INSPECTION" ? "제품검사평가" : "방문실사평가"} + +
+
+ +
+
+ + setReinspectData(prev => ({ + ...prev, + requestedStartDate: e.target.value + }))} + /> +
+
+ + setReinspectData(prev => ({ + ...prev, + requestedEndDate: e.target.value + }))} + /> +
+
+ +
+ +