From 1a2241c40e10193c5ff7008a7b7b36cc1d855d96 Mon Sep 17 00:00:00 2001 From: joonhoekim <26rote@gmail.com> Date: Tue, 25 Mar 2025 15:55:45 +0900 Subject: initial commit --- lib/items/table/add-items-dialog.tsx | 156 +++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 lib/items/table/add-items-dialog.tsx (limited to 'lib/items/table/add-items-dialog.tsx') diff --git a/lib/items/table/add-items-dialog.tsx b/lib/items/table/add-items-dialog.tsx new file mode 100644 index 00000000..2224444c --- /dev/null +++ b/lib/items/table/add-items-dialog.tsx @@ -0,0 +1,156 @@ +"use client" + +import * as React from "react" +import { useForm } from "react-hook-form" +import { zodResolver } from "@hookform/resolvers/zod" + +import { Dialog, DialogTrigger, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from "@/components/ui/dialog" +import { Button } from "@/components/ui/button" +import { Input } from "@/components/ui/input" +// react-hook-form + shadcn/ui Form +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +// shadcn/ui Select +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select" +import { createItemSchema, CreateItemSchema } from "../validations" +import { createItem } from "../service" +import { Textarea } from "@/components/ui/textarea" + + + +export function AddItemDialog() { + const [open, setOpen] = React.useState(false) + + // react-hook-form 세팅 + const form = useForm({ + resolver: zodResolver(createItemSchema), + defaultValues: { + itemCode: "", + itemName: "", + description: "", + }, + }) + + async function onSubmit(data: CreateItemSchema) { + const result = await createItem(data) + if (result.error) { + alert(`에러: ${result.error}`) + return + } + // 성공 시 모달 닫고 폼 리셋 + form.reset() + setOpen(false) + } + + function handleDialogOpenChange(nextOpen: boolean) { + if (!nextOpen) { + form.reset() + } + setOpen(nextOpen) + } + + return ( + + {/* 모달을 열기 위한 버튼 */} + + + + + + + Create New Item + + 새 Item 정보를 입력하고 Create 버튼을 누르세요. + + + + {/* shadcn/ui Form을 이용해 react-hook-form과 연결 */} +
+ +
+ + ( + + Item Code + + + + + + )} + /> + ( + + Item Name + + + + + + )} + /> + + ( + + Description + +