From 7305a614ca20d50e6ab50bbcfbb128a6f1f90e53 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Sun, 15 Jun 2025 04:41:55 +0000 Subject: (최겸) 기술영업 벤더 개발 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tech-vendors/table/add-vendor-dialog.tsx | 458 +++++++++++++++++++++++++++ 1 file changed, 458 insertions(+) create mode 100644 lib/tech-vendors/table/add-vendor-dialog.tsx (limited to 'lib/tech-vendors/table/add-vendor-dialog.tsx') diff --git a/lib/tech-vendors/table/add-vendor-dialog.tsx b/lib/tech-vendors/table/add-vendor-dialog.tsx new file mode 100644 index 00000000..bc260d51 --- /dev/null +++ b/lib/tech-vendors/table/add-vendor-dialog.tsx @@ -0,0 +1,458 @@ +"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 { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select" +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.enum(["조선", "해양TOP", "해양HULL"], { + required_error: "벤더 타입을 선택해주세요", + }), + representativeName: z.string().optional(), + representativeEmail: z.string().email("올바른 이메일 주소를 입력해주세요").optional().or(z.literal("")), + representativePhone: z.string().optional(), + representativeBirth: z.string().optional(), +}) + +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: undefined, + representativeName: "", + representativeEmail: "", + representativePhone: "", + representativeBirth: "", + }, + }) + + 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, + representativeName: data.representativeName || null, + representativeEmail: data.representativeEmail || null, + representativePhone: data.representativePhone || null, + representativeBirth: data.representativeBirth || null, + taxId: data.taxId || "", + }) + + 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 ( + + + + + + + 새 기술영업 벤더 추가 + + 새로운 기술영업 벤더 정보를 입력하고 사용자 계정을 생성합니다. + + + +
+ + {/* 기본 정보 */} +
+

기본 정보

+
+ ( + + 업체명 * + + + + + + )} + /> + ( + + 업체 코드 + + + + + + )} + /> +
+ +
+ ( + + 이메일 * + + + + + + )} + /> + ( + + 사업자등록번호 + + + + + + )} + /> +
+ + ( + + 벤더 타입 * + + + + )} + /> +
+ + {/* 연락처 정보 */} +
+

연락처 정보

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