From 2650b7c0bb0ea12b68a58c0439f72d61df04b2f1 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Fri, 25 Jul 2025 07:51:15 +0000
Subject: (대표님) 정기평가 대상, 미들웨어 수정, nextauth 토큰 처리 개선, GTC
 등 (최겸) 기술영업
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../possible-items/add-item-dialog.tsx             | 29 +++++++++++-----------
 1 file changed, 14 insertions(+), 15 deletions(-)

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

diff --git a/lib/tech-vendors/possible-items/add-item-dialog.tsx b/lib/tech-vendors/possible-items/add-item-dialog.tsx
index ef15a5ce..0e6edd19 100644
--- a/lib/tech-vendors/possible-items/add-item-dialog.tsx
+++ b/lib/tech-vendors/possible-items/add-item-dialog.tsx
@@ -27,6 +27,7 @@ interface ItemData {
   workType: string | null;
   shipTypes?: string | null;
   subItemList?: string | null;
+  itemType: "SHIP" | "TOP" | "HULL";
   createdAt: Date;
   updatedAt: Date;
 }
@@ -80,7 +81,7 @@ export function AddItemDialog({ open, onOpenChange, vendorId }: AddItemDialogPro
       console.log("Loaded items:", result.data.length, result.data);
       // itemCode가 null이 아닌 항목만 필터링
       const validItems = result.data.filter(item => item.itemCode != null);
-      setItems(validItems);
+      setItems(validItems as ItemData[]);
     } catch (error) {
       console.error("Failed to load items:", error);
       toast.error("아이템 목록을 불러오는데 실패했습니다.");
@@ -93,13 +94,13 @@ export function AddItemDialog({ open, onOpenChange, vendorId }: AddItemDialogPro
     if (!item.itemCode) return; // itemCode가 null인 경우 처리하지 않음
     
     setSelectedItems(prev => {
-      // itemCode + shipTypes 조합으로 중복 체크
+      // id + itemType 조합으로 중복 체크
       const isSelected = prev.some(i => 
-        i.itemCode === item.itemCode && i.shipTypes === item.shipTypes
+        i.id === item.id && i.itemType === item.itemType
       );
       if (isSelected) {
         return prev.filter(i => 
-          !(i.itemCode === item.itemCode && i.shipTypes === item.shipTypes)
+          !(i.id === item.id && i.itemType === item.itemType)
         );
       } else {
         return [...prev, item];
@@ -120,11 +121,8 @@ export function AddItemDialog({ open, onOpenChange, vendorId }: AddItemDialogPro
         
         const result = await addTechVendorPossibleItem({
           vendorId: vendorId,
-          itemCode: item.itemCode,
-          workType: item.workType || undefined,
-          shipTypes: item.shipTypes || undefined,
-          itemList: item.itemList || undefined,
-          subItemList: item.subItemList || undefined,
+          itemId: item.id,
+          itemType: item.itemType,
         });
 
         if (result.success) {
@@ -197,10 +195,11 @@ export function AddItemDialog({ open, onOpenChange, vendorId }: AddItemDialogPro
                              <div className="flex flex-wrap gap-1 p-2 border rounded-md bg-muted/50 max-h-20 overflow-y-auto">
                  {selectedItems.map((item) => {
                    if (!item.itemCode) return null;
-                   const itemKey = `${item.itemCode}${item.shipTypes ? `-${item.shipTypes}` : ''}`;
+                   const itemKey = `${item.itemType}-${item.id}-${item.itemCode}${item.shipTypes ? `-${item.shipTypes}` : ''}`;
+                   const displayText = `[${item.itemType}] ${item.itemCode}${item.shipTypes ? `-${item.shipTypes}` : ''}`;
                    return (
                      <Badge key={`selected-${itemKey}`} variant="default" className="text-xs">
-                       {itemKey}
+                       {displayText}
                        <X 
                          className="ml-1 h-3 w-3 cursor-pointer" 
                          onClick={(e) => {
@@ -232,11 +231,11 @@ export function AddItemDialog({ open, onOpenChange, vendorId }: AddItemDialogPro
                 filteredItems.map((item) => {
                   if (!item.itemCode) return null; // itemCode가 null인 경우 렌더링하지 않음
                   
-                  // itemCode + shipTypes 조합으로 선택 여부 체크
+                  // id + itemType 조합으로 선택 여부 체크
                   const isSelected = selectedItems.some(i => 
-                    i.itemCode === item.itemCode && i.shipTypes === item.shipTypes
+                    i.id === item.id && i.itemType === item.itemType
                   );
-                  const itemKey = `${item.itemCode}${item.shipTypes ? `-${item.shipTypes}` : ''}`;
+                  const itemKey = `${item.itemType}-${item.id}-${item.itemCode}${item.shipTypes ? `-${item.shipTypes}` : ''}`;
                   
                   return (
                     <div
@@ -249,7 +248,7 @@ export function AddItemDialog({ open, onOpenChange, vendorId }: AddItemDialogPro
                       onClick={() => handleItemToggle(item)}
                     >
                       <div className="font-medium">
-                        {itemKey}
+                        {`[${item.itemType}] ${item.itemCode}${item.shipTypes ? `-${item.shipTypes}` : ''}`}
                       </div>
                       <div className="text-sm text-muted-foreground">
                         {item.itemList || "-"}
-- 
cgit v1.2.3

