From 36385dadbb471508457f86e3a0e9ee05922b90c6 Mon Sep 17 00:00:00 2001
From: joonhoekim <26rote@gmail.com>
Date: Mon, 10 Nov 2025 14:59:28 +0900
Subject: (김준회) 벤더데이터: 삭제건은 send to shi 로 보내지 않기로 필터링
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 components/form-data/form-data-table.tsx | 37 ++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 11 deletions(-)

(limited to 'components/form-data/form-data-table.tsx')

diff --git a/components/form-data/form-data-table.tsx b/components/form-data/form-data-table.tsx
index 465cb9a1..b691ee87 100644
--- a/components/form-data/form-data-table.tsx
+++ b/components/form-data/form-data-table.tsx
@@ -103,7 +103,10 @@ export default function DynamicTable({
 
   const [rowAction, setRowAction] =
     React.useState<DataTableRowAction<GenericData> | null>(null);
-  const [tableData, setTableData] = React.useState<GenericData[]>(dataJSON);
+  // Filter out deleted items from initial data
+  const [tableData, setTableData] = React.useState<GenericData[]>(
+    dataJSON.filter(item => item.status !== "Deleted")
+  );
 
   // 배치 선택 관련 상태
   const [selectedRowsData, setSelectedRowsData] = React.useState<GenericData[]>([]);
@@ -231,9 +234,9 @@ export default function DynamicTable({
     }
   }, [projectId, formCode]);
 
-  // Update tableData when dataJSON changes
+  // Update tableData when dataJSON changes (filter out deleted items)
   React.useEffect(() => {
-    setTableData(dataJSON);
+    setTableData(dataJSON.filter(item => item.status !== "Deleted"));
   }, [dataJSON]);
 
   // 폴링 상태 관리를 위한 ref
@@ -632,8 +635,11 @@ export default function DynamicTable({
     try {
       setIsSendingSEDP(true);
 
+      // Filter out deleted items (status="Deleted") - 삭제된 항목은 전송하지 않음
+      const dataToSend = tableData.filter((item) => item.status !== "Deleted");
+
       // Validate data
-      const invalidData = tableData.filter((item) => {
+      const invalidData = dataToSend.filter((item) => {
         const tagNo = item.TAG_NO;
         return !tagNo || (typeof tagNo === 'string' && !tagNo.trim());
       });
@@ -643,12 +649,18 @@ export default function DynamicTable({
         return;
       }
 
+      if (dataToSend.length === 0) {
+        toast.error("전송할 데이터가 없습니다.");
+        setSedpConfirmOpen(false);
+        return;
+      }
+
       // Then send to SEDP - pass formCode instead of formName
       const sedpResult = await sendFormDataToSEDP(
         formCode,        // Send formCode instead of formName
         projectId,       // Project ID
         contractItemId,
-        tableData,       // Table data
+        dataToSend,      // Send filtered data (excluding deleted items)
         columnsJSON      // Column definitions
       );
 
@@ -660,17 +672,17 @@ export default function DynamicTable({
         setSedpStatusData({
           status: 'success',
           message: "Data successfully sent to SEDP",
-          successCount: tableData.length,
+          successCount: dataToSend.length,
           errorCount: 0,
-          totalCount: tableData.length
+          totalCount: dataToSend.length
         });
       } else {
         setSedpStatusData({
           status: 'error',
           message: sedpResult.message || "Failed to send data to SEDP",
           successCount: 0,
-          errorCount: tableData.length,
-          totalCount: tableData.length
+          errorCount: dataToSend.length,
+          totalCount: dataToSend.length
         });
       }
 
@@ -683,13 +695,16 @@ export default function DynamicTable({
     } catch (err: unknown) {
       console.error("SEDP error:", err);
 
+      // Get dataToSend count (filter deleted items)
+      const dataToSend = tableData.filter((item) => item.status !== "Deleted");
+
       // Set error status
       setSedpStatusData({
         status: 'error',
         message: err instanceof Error ? err.message : "An unexpected error occurred",
         successCount: 0,
-        errorCount: tableData.length,
-        totalCount: tableData.length
+        errorCount: dataToSend.length,
+        totalCount: dataToSend.length
       });
 
       // Close confirmation and open status
-- 
cgit v1.2.3

