From 95bbe9c583ff841220da1267630e7b2025fc36dc Mon Sep 17 00:00:00 2001 From: dujinkim Date: Thu, 19 Jun 2025 09:44:28 +0000 Subject: (대표님) 20250619 1844 KST 작업사항 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../table/payment-terms-add-dialog.tsx | 162 +++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 lib/payment-terms/table/payment-terms-add-dialog.tsx (limited to 'lib/payment-terms/table/payment-terms-add-dialog.tsx') diff --git a/lib/payment-terms/table/payment-terms-add-dialog.tsx b/lib/payment-terms/table/payment-terms-add-dialog.tsx new file mode 100644 index 00000000..9aa21485 --- /dev/null +++ b/lib/payment-terms/table/payment-terms-add-dialog.tsx @@ -0,0 +1,162 @@ +"use client"; + +import * as React from "react"; +import { useForm } from "react-hook-form"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { z } from "zod"; +import { Plus, Loader2 } from "lucide-react"; + +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 { createPaymentTerm } from "../service"; +import { toast } from "sonner"; + +const createPaymentTermSchema = z.object({ + code: z.string().min(1, "코드는 필수입니다."), + description: z.string().min(1, "설명은 필수입니다."), + isActive: z.boolean().default(true), +}); + +type CreatePaymentTermFormValues = z.infer; + +interface PaymentTermsAddDialogProps { + onSuccess?: () => void; +} + +export function PaymentTermsAddDialog({ onSuccess }: PaymentTermsAddDialogProps) { + const [open, setOpen] = React.useState(false); + const [isLoading, setIsLoading] = React.useState(false); + + const form = useForm({ + resolver: zodResolver(createPaymentTermSchema), + defaultValues: { + code: "", + description: "", + isActive: true, + }, + }); + + const handleOpenChange = (newOpen: boolean) => { + setOpen(newOpen); + if (!newOpen) { + form.reset(); + } + }; + + const handleCancel = () => { + form.reset(); + setOpen(false); + }; + + const onSubmit = async (data: CreatePaymentTermFormValues) => { + setIsLoading(true); + try { + const result = await createPaymentTerm(data); + if (result.data) { + toast.success("결제 조건이 추가되었습니다."); + setOpen(false); + if (onSuccess) { + onSuccess(); + } + } else { + toast.error(result.error || "생성 중 오류가 발생했습니다."); + } + } catch (error) { + console.error("결제 조건 생성 오류:", error); + toast.error("결제 조건 생성에 실패했습니다."); + } finally { + setIsLoading(false); + } + }; + + return ( + + + + + + + 결제 조건 추가 + + 새로운 결제 조건을 추가합니다. 필수 정보를 입력해주세요. + + + +
+ + ( + + + 코드 * + + + + + + + )} + /> + + ( + + + 설명 * + + + + + + + )} + /> + + + + + + + +
+
+ ); +} \ No newline at end of file -- cgit v1.2.3