"use client" import * as React from "react" import { zodResolver } from "@hookform/resolvers/zod" import { useForm } from "react-hook-form" import { toast } from "sonner" import { z } from "zod" import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog" import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form" import { Input } from "@/components/ui/input" import { Textarea } from "@/components/ui/textarea" import { Plus, Loader2 } from "lucide-react" import { addTechVendor } from "../service" // 폼 스키마 정의 const addVendorSchema = z.object({ vendorName: z.string().min(1, "업체명을 입력해주세요"), vendorCode: z.string().optional(), email: z.string().email("올바른 이메일 주소를 입력해주세요"), taxId: z.string().optional(), country: z.string().optional(), countryEng: z.string().optional(), countryFab: z.string().optional(), agentName: z.string().optional(), agentPhone: z.string().optional(), agentEmail: z.string().email("올바른 이메일 주소를 입력해주세요").optional().or(z.literal("")), address: z.string().optional(), phone: z.string().optional(), website: z.string().optional(), techVendorType: z.array(z.enum(["조선", "해양TOP", "해양HULL"])).min(1, "최소 하나의 벤더 타입을 선택해주세요"), representativeName: z.string().optional(), representativeEmail: z.string().email("올바른 이메일 주소를 입력해주세요").optional().or(z.literal("")), representativePhone: z.string().optional(), representativeBirth: z.string().optional(), isQuoteComparison: z.boolean().default(false), }) type AddVendorFormData = z.infer interface AddVendorDialogProps { onSuccess?: () => void } export function AddVendorDialog({ onSuccess }: AddVendorDialogProps) { const [open, setOpen] = React.useState(false) const [isLoading, setIsLoading] = React.useState(false) const form = useForm({ resolver: zodResolver(addVendorSchema), defaultValues: { vendorName: "", vendorCode: "", email: "", taxId: "", country: "", countryEng: "", countryFab: "", agentName: "", agentPhone: "", agentEmail: "", address: "", phone: "", website: "", techVendorType: [], representativeName: "", representativeEmail: "", representativePhone: "", representativeBirth: "", isQuoteComparison: false, }, }) const onSubmit = async (data: AddVendorFormData) => { setIsLoading(true) try { const result = await addTechVendor({ ...data, vendorCode: data.vendorCode || null, country: data.country || null, countryEng: data.countryEng || null, countryFab: data.countryFab || null, agentName: data.agentName || null, agentPhone: data.agentPhone || null, agentEmail: data.agentEmail || null, address: data.address || null, phone: data.phone || null, website: data.website || null, techVendorType: data.techVendorType.join(','), representativeName: data.representativeName || null, representativeEmail: data.representativeEmail || null, representativePhone: data.representativePhone || null, representativeBirth: data.representativeBirth || null, taxId: data.taxId || "", isQuoteComparison: data.isQuoteComparison, }) if (result.success) { toast.success("벤더가 성공적으로 추가되었습니다.") form.reset() setOpen(false) onSuccess?.() } else { toast.error(result.error || "벤더 추가 중 오류가 발생했습니다.") } } catch (error) { console.error("벤더 추가 오류:", error) toast.error("벤더 추가 중 오류가 발생했습니다.") } finally { setIsLoading(false) } } return ( 새 기술영업 벤더 추가 새로운 기술영업 벤더 정보를 입력하고 사용자 계정을 생성합니다.
{/* 기본 정보 */}

기본 정보

( 업체명 * )} /> ( 업체 코드 )} />
( 이메일 * )} /> ( 사업자등록번호 )} />
( 벤더 타입 *
{["조선", "해양TOP", "해양HULL"].map((type) => (
{ const currentValue = field.value || []; if (e.target.checked) { field.onChange([...currentValue, type]); } else { field.onChange(currentValue.filter((v) => v !== type)); } }} className="w-4 h-4" />
))}
)} /> (
견적비교용 벤더

체크 시 초대 메일을 발송하고 벤더가 직접 가입할 수 있습니다.

)} />
{/* 연락처 정보 */}

연락처 정보

( 전화번호 )} /> ( 웹사이트 )} />
( 주소