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-edit-sheet.tsx     | 84 ++++++++++------------
 1 file changed, 37 insertions(+), 47 deletions(-)

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

diff --git a/lib/docu-list-rule/document-class/table/document-class-option-edit-sheet.tsx b/lib/docu-list-rule/document-class/table/document-class-option-edit-sheet.tsx
index 6f6e7a87..bc2318c6 100644
--- a/lib/docu-list-rule/document-class/table/document-class-option-edit-sheet.tsx
+++ b/lib/docu-list-rule/document-class/table/document-class-option-edit-sheet.tsx
@@ -5,12 +5,10 @@ import { zodResolver } from "@hookform/resolvers/zod"
 import { useForm } from "react-hook-form"
 import { toast } from "sonner"
 import * as z from "zod"
-import { Loader } from "lucide-react"
 
 import { Button } from "@/components/ui/button"
 import {
   Sheet,
-  SheetClose,
   SheetContent,
   SheetDescription,
   SheetFooter,
@@ -26,14 +24,15 @@ import {
   FormMessage,
 } from "@/components/ui/form"
 import { Input } from "@/components/ui/input"
+
 import { updateDocumentClassOption } from "@/lib/docu-list-rule/document-class/service"
-import { documentClassOptions } from "@/db/schema/documentClasses"
+import { documentClassOptions } from "@/db/schema"
 
-const updateDocumentClassOptionSchema = z.object({
-  optionValue: z.string().min(1, "옵션 값은 필수입니다."),
+const updateOptionSchema = z.object({
+  optionCode: z.string().min(1, "코드는 필수입니다."),
 })
 
-type UpdateDocumentClassOptionSchema = z.infer<typeof updateDocumentClassOptionSchema>
+type UpdateOptionSchema = z.infer<typeof updateOptionSchema>
 
 interface DocumentClassOptionEditSheetProps {
   open: boolean
@@ -48,91 +47,82 @@ export function DocumentClassOptionEditSheet({
   data,
   onSuccess,
 }: DocumentClassOptionEditSheetProps) {
-  const [isUpdatePending, startUpdateTransition] = React.useTransition()
+  const [isPending, startTransition] = React.useTransition()
 
-  const form = useForm<UpdateDocumentClassOptionSchema>({
-    resolver: zodResolver(updateDocumentClassOptionSchema),
+  const form = useForm<UpdateOptionSchema>({
+    resolver: zodResolver(updateOptionSchema),
     defaultValues: {
-      optionValue: data?.optionValue || "",
+      optionCode: "",
     },
-    mode: "onChange"
   })
 
   React.useEffect(() => {
     if (data) {
       form.reset({
-        optionValue: data.optionValue || "",
+        optionCode: data.optionCode || "",
       })
     }
   }, [data, form])
 
-  async function onSubmit(input: UpdateDocumentClassOptionSchema) {
+  const handleSubmit = (formData: UpdateOptionSchema) => {
     if (!data) return
 
-    startUpdateTransition(async () => {
+    startTransition(async () => {
       try {
         const result = await updateDocumentClassOption({
           id: data.id,
-          optionValue: input.optionValue,
+          optionCode: formData.optionCode,
         })
-        
+
         if (result.success) {
-          toast.success("Document Class 옵션이 성공적으로 수정되었습니다.")
-          onSuccess?.()
+          toast.success("옵션이 성공적으로 수정되었습니다.")
           onOpenChange(false)
+          onSuccess?.()
         } else {
-          toast.error(result.error || "수정에 실패했습니다.")
+          toast.error(`옵션 수정 실패: ${result.error}`)
         }
       } catch (error) {
         console.error("Update error:", error)
-        toast.error("Document Class 옵션 수정 중 오류가 발생했습니다.")
+        toast.error("옵션 수정 중 오류가 발생했습니다.")
       }
     })
   }
 
+  const handleCancel = () => {
+    onOpenChange(false)
+    form.reset()
+  }
+
   return (
     <Sheet open={open} onOpenChange={onOpenChange}>
-      <SheetContent className="flex flex-col gap-6 sm:max-w-md">
-        <SheetHeader className="text-left">
-          <SheetTitle>Document Class 옵션 수정</SheetTitle>
+      <SheetContent>
+        <SheetHeader>
+          <SheetTitle>옵션 수정</SheetTitle>
           <SheetDescription>
-            Document Class 옵션 정보를 수정하고 변경사항을 저장하세요
+            Document Class 옵션을 수정합니다.
           </SheetDescription>
         </SheetHeader>
         <Form {...form}>
-          <form onSubmit={form.handleSubmit(onSubmit)} className="flex flex-col gap-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 placeholder="옵션 값을 입력하세요" {...field} />
+                    <Input {...field} placeholder="옵션 코드" />
                   </FormControl>
                   <FormMessage />
                 </FormItem>
               )}
             />
-
-
-            <SheetFooter className="gap-2 pt-2 sm:space-x-0">
-              <SheetClose asChild>
-                <Button type="button" variant="outline">
-                  취소
-                </Button>
-              </SheetClose>
-              <Button 
-                type="submit" 
-                disabled={isUpdatePending || !form.formState.isValid}
-              >
-                {isUpdatePending && (
-                  <Loader
-                    className="mr-2 size-4 animate-spin"
-                    aria-hidden="true"
-                  />
-                )}
-                저장
+            <SheetFooter>
+              <Button type="button" variant="outline" onClick={handleCancel}>
+                취소
+              </Button>
+              <Button type="submit" disabled={isPending || !form.formState.isValid}>
+                수정
               </Button>
             </SheetFooter>
           </form>
-- 
cgit v1.2.3

