"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 { Label } from "@/components/ui/label"; import { Checkbox } from "@/components/ui/checkbox"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; import { Separator } from "@/components/ui/separator"; import { Badge } from "@/components/ui/badge"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { FileText, Shield, Globe, Info, Loader2 } from "lucide-react"; import { toast } from "sonner"; import { updateVendorContractRequirements } from "../service"; interface EditContractDialogProps { open: boolean; onOpenChange: (open: boolean) => void; rfqId: number; vendor: { detailId: number; vendorId: number; vendorName: string; vendorCode?: string; vendorCountry?: string; agreementYn?: boolean; ndaYn?: boolean; generalGtcYn?: boolean; projectGtcYn?: boolean; gtcType?: "general" | "project" | "none"; }; onSuccess: () => void; } export function EditContractDialog({ open, onOpenChange, rfqId, vendor, onSuccess, }: EditContractDialogProps) { const [isLoading, setIsLoading] = React.useState(false); // 기본계약 상태 const [contractAgreement, setContractAgreement] = React.useState(false); const [contractNDA, setContractNDA] = React.useState(false); const [contractGTC, setContractGTC] = React.useState<"general" | "project" | "none">("none"); // 국외 업체 확인 const isInternational = React.useMemo(() => { return vendor?.vendorCountry && vendor.vendorCountry !== "KR" && vendor.vendorCountry !== "한국"; }, [vendor]); // 초기값 설정 React.useEffect(() => { if (open && vendor) { setContractAgreement(vendor.agreementYn || false); setContractNDA(vendor.ndaYn || false); // GTC 타입 결정 if (vendor.gtcType) { setContractGTC(vendor.gtcType); } else if (vendor.generalGtcYn) { setContractGTC("general"); } else if (vendor.projectGtcYn) { setContractGTC("project"); } else { setContractGTC("none"); } } }, [open, vendor]); // 제출 처리 const handleSubmit = async () => { setIsLoading(true); try { const result = await updateVendorContractRequirements({ rfqId, detailId: vendor.detailId, contractRequirements: { agreementYn: contractAgreement, ndaYn: contractNDA, gtcType: isInternational ? contractGTC : "none", }, }); if (result.success) { toast.success("기본계약 요구사항이 업데이트되었습니다."); onSuccess(); onOpenChange(false); } else { toast.error(result.error || "업데이트에 실패했습니다."); } } catch (error) { console.error("Update error:", error); toast.error("오류가 발생했습니다."); } finally { setIsLoading(false); } }; return ( 기본계약 수정
{vendor?.vendorCode} {vendor?.vendorName} {vendor?.vendorCountry && ( {vendor.vendorCountry} )}
{/* 필수 계약 */}
setContractAgreement(!!checked)} />
setContractNDA(!!checked)} />
{/* GTC 선택 (국외 업체만) */} {isInternational && ( <>
국외 업체
setContractGTC(value)} >
)} {/* 국내 업체 안내 */} {!isInternational && ( 국내 업체는 GTC가 적용되지 않습니다. )}
); }