From 2ef02e27dbe639876fa3b90c30307dda183545ec Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Thu, 17 Jul 2025 10:50:52 +0000
Subject: (최겸) 기술영업 변경사항 적용
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/items-tech/table/add-items-dialog.tsx | 108 +++++++++++++++++-------------
 1 file changed, 61 insertions(+), 47 deletions(-)

(limited to 'lib/items-tech/table/add-items-dialog.tsx')

diff --git a/lib/items-tech/table/add-items-dialog.tsx b/lib/items-tech/table/add-items-dialog.tsx
index ee8ee8b8..1b0d00c7 100644
--- a/lib/items-tech/table/add-items-dialog.tsx
+++ b/lib/items-tech/table/add-items-dialog.tsx
@@ -4,7 +4,7 @@ import * as React from "react"
 import { useRouter } from "next/navigation"
 import { zodResolver } from "@hookform/resolvers/zod"
 import { useForm } from "react-hook-form"
-import { Plus } from "lucide-react"
+import { Plus, Loader } from "lucide-react"
 import * as z from "zod"
 
 import { Button } from "@/components/ui/button"
@@ -44,6 +44,7 @@ const shipbuildingWorkTypes = [
   { label: "선실", value: "선실" },
   { label: "배관", value: "배관" },
   { label: "철의", value: "철의" },
+  { label: "선체", value: "선체" },
 ] as const
 
 // 해양 TOP 공종 유형 정의
@@ -60,12 +61,14 @@ const offshoreHullWorkTypes = [
   { label: "HE", value: "HE" },
   { label: "HH", value: "HH" },
   { label: "HM", value: "HM" },
+  { label: "HO", value: "HO" },
+  { label: "HP", value: "HP" },
   { label: "NC", value: "NC" },
 ] as const
 
 // 기본 아이템 스키마
 const itemFormSchema = z.object({
-  itemCode: z.string().min(1, "아이템 코드는 필수입니다"),
+  itemCode: z.string().optional(),
   workType: z.string().min(1, "공종은 필수입니다"),
   // 조선 및 해양 아이템 공통 필드
   itemList: z.string().optional(),
@@ -83,6 +86,7 @@ interface AddItemDialogProps {
 export function AddItemDialog({ itemType }: AddItemDialogProps) {
   const router = useRouter()
   const [open, setOpen] = React.useState(false)
+  const [isAddPending, startAddTransition] = React.useTransition()
 
   // 기본값 설정
   const getDefaultValues = () => {
@@ -120,53 +124,55 @@ export function AddItemDialog({ itemType }: AddItemDialogProps) {
   })
 
   const onSubmit = async (data: ItemFormValues) => {
-    try {
-      switch (itemType) {
-        case 'shipbuilding':
-          if (!data.shipTypes) {
-            toast.error("선종은 필수입니다")
-            return
-          }
+    startAddTransition(async () => {
+      try {
+        switch (itemType) {
+          case 'shipbuilding':
+            if (!data.shipTypes) {
+              toast.error("선종은 필수입니다")
+              return
+            }
+            
+            await createShipbuildingItem({
+              itemCode: data.itemCode || "",
+              workType: data.workType as "기장" | "전장" | "선실" | "배관" | "철의" | "선체",
+              shipTypes: data.shipTypes,
+              itemList: data.itemList || null,
+            });
+            break;
           
-          await createShipbuildingItem({
-            itemCode: data.itemCode,
-            workType: data.workType,
-            shipTypes: data.shipTypes,
-            itemList: data.itemList || null,
-          });
-          break;
-        
-        case 'offshoreTop':
-          await createOffshoreTopItem({
-            itemCode: data.itemCode,
-            workType: data.workType as "TM" | "TS" | "TE" | "TP",
-            itemList: data.itemList || null,
-            subItemList: data.subItemList || null
-          });
-          break;
-        
-        case 'offshoreHull':
-          await createOffshoreHullItem({
-            itemCode: data.itemCode,
-            workType: data.workType as "HA" | "HE" | "HH" | "HM" | "NC",
-            itemList: data.itemList || null,
-            subItemList: data.subItemList || null
-          });
-          break;
+          case 'offshoreTop':
+            await createOffshoreTopItem({
+              itemCode: data.itemCode || "",
+              workType: data.workType as "TM" | "TS" | "TE" | "TP",
+              itemList: data.itemList || null,
+              subItemList: data.subItemList || null
+            });
+            break;
+          
+          case 'offshoreHull':
+            await createOffshoreHullItem({
+              itemCode: data.itemCode || "",
+              workType: data.workType as "HA" | "HE" | "HH" | "HM" | "HO" | "HP" | "NC",
+              itemList: data.itemList || null,
+              subItemList: data.subItemList || null
+            });
+            break;
+          
+          default:
+            toast.error("지원하지 않는 아이템 타입입니다");
+            return;
+        }
         
-        default:
-          toast.error("지원하지 않는 아이템 타입입니다");
-          return;
+        toast.success("아이템이 성공적으로 추가되었습니다")
+        setOpen(false)
+        form.reset(getDefaultValues())
+        router.refresh()
+      } catch (error) {
+        toast.error("아이템 추가 중 오류가 발생했습니다")
+        console.error(error)
       }
-      
-      toast.success("아이템이 성공적으로 추가되었습니다")
-      setOpen(false)
-      form.reset(getDefaultValues())
-      router.refresh()
-    } catch (error) {
-      toast.error("아이템 추가 중 오류가 발생했습니다")
-      console.error(error)
-    }
+    })
   }
 
   const getItemTypeLabel = () => {
@@ -315,7 +321,15 @@ export function AddItemDialog({ itemType }: AddItemDialogProps) {
               <Button type="button" variant="outline" onClick={() => setOpen(false)}>
                 취소
               </Button>
-              <Button type="submit">추가</Button>
+              <Button type="submit" disabled={isAddPending}>
+                {isAddPending && (
+                  <Loader
+                    className="mr-2 size-4 animate-spin"
+                    aria-hidden="true"
+                  />
+                )}
+                추가
+              </Button>
             </div>
           </form>
         </Form>
-- 
cgit v1.2.3

