From 7305a614ca20d50e6ab50bbcfbb128a6f1f90e53 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Sun, 15 Jun 2025 04:41:55 +0000
Subject: (최겸) 기술영업 벤더 개발
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/tech-vendors/items-table/add-item-dialog.tsx | 39 +++++++++---------------
 1 file changed, 15 insertions(+), 24 deletions(-)

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

diff --git a/lib/tech-vendors/items-table/add-item-dialog.tsx b/lib/tech-vendors/items-table/add-item-dialog.tsx
index bd1c32f5..e4d74204 100644
--- a/lib/tech-vendors/items-table/add-item-dialog.tsx
+++ b/lib/tech-vendors/items-table/add-item-dialog.tsx
@@ -37,14 +37,14 @@ import {
   type CreateTechVendorItemSchema,
 } from "@/lib/tech-vendors/validations"
 
-import { createTechVendorItem, getItemsByVendorType, ItemDropdownOption } from "../service"
+import { createTechVendorItem, getItemsForTechVendor, ItemDropdownOption } from "../service"
 
 interface AddItemDialogProps {
   vendorId: number
-  vendorType: string
+  vendorType: string // UI에서 전달하지만 내부적으로는 사용하지 않음
 }
 
-export function AddItemDialog({ vendorId, vendorType }: AddItemDialogProps) {
+export function AddItemDialog({ vendorId }: AddItemDialogProps) {
   const router = useRouter()
   const [open, setOpen] = React.useState(false)
   const [commandOpen, setCommandOpen] = React.useState(false)
@@ -69,30 +69,21 @@ export function AddItemDialog({ vendorId, vendorType }: AddItemDialogProps) {
   const fetchItems = React.useCallback(async () => {
     if (items.length > 0) return
     
-    console.log(`[AddItemDialog] fetchItems - 벤더 타입: ${vendorType || '알 수 없음'}, 벤더 ID: ${vendorId} 시작`)
-    
-    if (!vendorType) {
-      console.error("[AddItemDialog] 벤더 타입이 지정되지 않았습니다. 아이템을 불러올 수 없습니다.")
-      toast.error("벤더 타입이 지정되지 않아 아이템을 불러올 수 없습니다.")
-      setIsLoading(false)
-      return
-    }
+    console.log(`[AddItemDialog] fetchItems - 벤더 ID: ${vendorId} 시작`)
     
     setIsLoading(true)
     try {
-      console.log(`[AddItemDialog] getItemsByVendorType 호출 - 타입: ${vendorType}`)
-      const result = await getItemsByVendorType(vendorType, "")
-      console.log(`[AddItemDialog] getItemsByVendorType 결과:`, result)
+      console.log(`[AddItemDialog] getItemsForTechVendor 호출 - vendorId: ${vendorId}`)
+      const result = await getItemsForTechVendor(vendorId)
+      console.log(`[AddItemDialog] getItemsForTechVendor 결과:`, result)
       
       if (result.data) {
-        const formattedItems = result.data.map(item => ({
-          itemCode: item.itemCode,
-          itemName: "기술영업",
-          description: ""
-        }))
-        console.log(`[AddItemDialog] 포맷된 아이템 목록:`, formattedItems)
-        setItems(formattedItems)
-        setFilteredItems(formattedItems)
+        console.log(`[AddItemDialog] 사용 가능한 아이템 목록:`, result.data)
+        setItems(result.data)
+        setFilteredItems(result.data)
+      } else if (result.error) {
+        console.error("[AddItemDialog] 아이템 조회 실패:", result.error)
+        toast.error(result.error)
       }
     } catch (err) {
       console.error("[AddItemDialog] 아이템 조회 실패:", err)
@@ -101,7 +92,7 @@ export function AddItemDialog({ vendorId, vendorType }: AddItemDialogProps) {
       setIsLoading(false)
       console.log(`[AddItemDialog] fetchItems 완료`)
     }
-  }, [items.length, vendorType, vendorId])
+  }, [items.length, vendorId])
 
   React.useEffect(() => {
     if (commandOpen) {
@@ -157,7 +148,7 @@ export function AddItemDialog({ vendorId, vendorType }: AddItemDialogProps) {
       console.log(`[AddItemDialog] createTechVendorItem 호출 - vendorId: ${data.vendorId}, itemCode: ${data.itemCode}`)
       const submitData = {
         ...data,
-        itemName: "기술영업"
+        itemName: selectedItem?.itemName || "기술영업"
       }
       console.log(`[AddItemDialog] 최종 제출 데이터:`, submitData)
       
-- 
cgit v1.2.3

