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/add-check-list-dialog.tsx | 112 +++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 lib/general-check-list/table/add-check-list-dialog.tsx (limited to 'lib/general-check-list/table/add-check-list-dialog.tsx') diff --git a/lib/general-check-list/table/add-check-list-dialog.tsx b/lib/general-check-list/table/add-check-list-dialog.tsx new file mode 100644 index 00000000..5721bd59 --- /dev/null +++ b/lib/general-check-list/table/add-check-list-dialog.tsx @@ -0,0 +1,112 @@ +"use client"; +import * as React from "react"; +import { z } from "zod"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { useForm } from "react-hook-form"; +import { Dialog, DialogTrigger, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from "@/components/ui/dialog"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { Form, FormField, FormItem, FormLabel, FormControl, FormMessage } from "@/components/ui/form"; +import { Plus } from "lucide-react"; +import { toast } from "sonner"; +import { createGeneralEvaluation } from "@/lib/general-check-list/service"; +import { useRouter } from "next/navigation"; + +const schema = z.object({ + category: z.string().min(1, "카테고리를 입력하세요"), + inspectionItem: z.string().min(1, "점검 항목을 입력하세요"), + remarks: z.string().optional(), +}); + +type FormValues = z.infer; + +export function CreateEvaluationDialog({ onSuccess }: { onSuccess?: () => void }) { + const [open, setOpen] = React.useState(false); + const [pending, setPending] = React.useState(false); + const router = useRouter(); // ⬅️ + + const form = useForm({ + resolver: zodResolver(schema), + defaultValues: { category: "", inspectionItem: "", remarks: "" }, + }); + + async function onSubmit(values: FormValues) { + setPending(true); + const res = await createGeneralEvaluation(values); + if (res.success) { + toast.success(res.message); + router.refresh(); // ❷ 새로고침 + + onSuccess?.(); + setOpen(false); + form.reset(); + } else { + toast.error(res.message); + } + setPending(false); + } + + return ( + !pending && setOpen(v)}> + + + + + + 새 정기평가 체크리스트 + 점검 항목을 추가합니다. + +
+ + ( + + 카테고리 + + + + + + )} + /> + ( + + 점검 항목 + + + + + + )} + /> + ( + + 비고 (선택) + + + + + + )} + /> + + + + + +
+
+ ); +} \ No newline at end of file -- cgit v1.2.3