From 59b5715ebb3e1fd7bd4eb02ce50399715734f865 Mon Sep 17 00:00:00 2001
From: 0-Zz-ang <s1998319@gmail.com>
Date: Mon, 4 Aug 2025 14:59:15 +0900
Subject: (박서영) docu-list-rule detail sheet 컴포넌트 추가 및 검색 필터 기능
 오류 수정
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../table/document-class-option-add-dialog.tsx     | 66 +++++++++-------------
 1 file changed, 27 insertions(+), 39 deletions(-)

(limited to 'lib/docu-list-rule/document-class/table/document-class-option-add-dialog.tsx')

diff --git a/lib/docu-list-rule/document-class/table/document-class-option-add-dialog.tsx b/lib/docu-list-rule/document-class/table/document-class-option-add-dialog.tsx
index 5bfcbd33..93681c09 100644
--- a/lib/docu-list-rule/document-class/table/document-class-option-add-dialog.tsx
+++ b/lib/docu-list-rule/document-class/table/document-class-option-add-dialog.tsx
@@ -28,105 +28,93 @@ import {
 import { Input } from "@/components/ui/input"
 
 import { createDocumentClassOptionItem } from "@/lib/docu-list-rule/document-class/service"
-import { documentClasses } from "@/db/schema/documentClasses"
 
-const createDocumentClassOptionSchema = z.object({
-  optionValue: z.string().min(1, "옵션 값은 필수입니다."),
+const createOptionSchema = z.object({
+  optionCode: z.string().min(1, "코드는 필수입니다."),
 })
 
-type CreateDocumentClassOptionSchema = z.infer<typeof createDocumentClassOptionSchema>
+type CreateOptionSchema = z.infer<typeof createOptionSchema>
 
 interface DocumentClassOptionAddDialogProps {
-  selectedDocumentClass: typeof documentClasses.$inferSelect | null
+  documentClassId: number
   onSuccess?: () => void
 }
 
-export function DocumentClassOptionAddDialog({
-  selectedDocumentClass,
-  onSuccess,
-}: DocumentClassOptionAddDialogProps) {
+export function DocumentClassOptionAddDialog({ documentClassId, onSuccess }: DocumentClassOptionAddDialogProps) {
   const [open, setOpen] = React.useState(false)
   const [isPending, startTransition] = React.useTransition()
 
-  const form = useForm<CreateDocumentClassOptionSchema>({
-    resolver: zodResolver(createDocumentClassOptionSchema),
+  const form = useForm<CreateOptionSchema>({
+    resolver: zodResolver(createOptionSchema),
     defaultValues: {
-      optionValue: "",
+      optionCode: "",
     },
-    mode: "onChange"
   })
 
-  async function onSubmit(input: CreateDocumentClassOptionSchema) {
-    if (!selectedDocumentClass) {
-      toast.error("Document Class가 선택되지 않았습니다.")
-      return
-    }
-
+  const handleSubmit = (data: CreateOptionSchema) => {
     startTransition(async () => {
       try {
         const result = await createDocumentClassOptionItem({
-          documentClassId: selectedDocumentClass.id,
-          optionValue: input.optionValue,
+          documentClassId,
+          optionCode: data.optionCode,
         })
-        
+
         if (result.success) {
-          toast.success("Document Class 옵션이 생성되었습니다.")
-          form.reset()
+          toast.success("옵션이 성공적으로 추가되었습니다.")
           setOpen(false)
+          form.reset()
           onSuccess?.()
         } else {
-          toast.error(result.error || "생성에 실패했습니다.")
+          toast.error(`옵션 추가 실패: ${result.error}`)
         }
       } catch (error) {
         console.error("Create error:", error)
-        toast.error("Document Class 옵션 생성 중 오류가 발생했습니다.")
+        toast.error("옵션 추가 중 오류가 발생했습니다.")
       }
     })
   }
 
   const handleCancel = () => {
-    form.reset()
     setOpen(false)
+    form.reset()
   }
 
   return (
-    <Dialog open={open && !!selectedDocumentClass} onOpenChange={setOpen}>
+    <Dialog open={open} onOpenChange={setOpen}>
       <DialogTrigger asChild>
-        <Button variant="outline" size="sm" disabled={!selectedDocumentClass}>
+        <Button variant="outline" size="sm">
           <Plus className="mr-2 h-4 w-4" />
           옵션 추가
         </Button>
       </DialogTrigger>
-      <DialogContent className="sm:max-w-[425px]">
+      <DialogContent>
         <DialogHeader>
-          <DialogTitle>Document Class 옵션 추가</DialogTitle>
+          <DialogTitle>옵션 추가</DialogTitle>
           <DialogDescription>
-            {selectedDocumentClass?.description || "Document Class"}에 새로운 옵션을 추가합니다.
-            <span className="text-red-500 mt-1 block text-sm">* 표시된 항목은 필수 입력사항입니다.</span>
+            새로운 Document Class 옵션을 추가합니다.
           </DialogDescription>
         </DialogHeader>
         <Form {...form}>
-          <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
+          <form onSubmit={form.handleSubmit(handleSubmit)} className="space-y-4">
             <FormField
               control={form.control}
-              name="optionValue"
+              name="optionCode"
               render={({ field }) => (
                 <FormItem>
-                  <FormLabel>옵션 값 *</FormLabel>
+                  <FormLabel>코드</FormLabel>
                   <FormControl>
-                    <Input {...field} placeholder="옵션 값을 입력하세요" />
+                    <Input {...field} placeholder="옵션 코드" />
                   </FormControl>
                   <FormMessage />
                 </FormItem>
               )}
             />
-
             <DialogFooter>
               <Button type="button" variant="outline" onClick={handleCancel}>
                 취소
               </Button>
               <Button type="submit" disabled={isPending || !form.formState.isValid}>
-                {isPending ? "추가 중..." : "추가"}
+                추가
               </Button>
             </DialogFooter>
           </form>
-- 
cgit v1.2.3

