From 4eb7532f822c821fb6b69bf103bd075fefba769b Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Tue, 15 Jul 2025 10:07:09 +0000
Subject: (대표님) 20250715 협력사 정기평가, spreadJS, roles 서비스에 함수 추가
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 components/form-data/form-data-table.tsx | 50 ++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 22 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 57913192..d964b17b 100644
--- a/components/form-data/form-data-table.tsx
+++ b/components/form-data/form-data-table.tsx
@@ -317,10 +317,6 @@ export default function DynamicTable({
 
   // 새로 추가된 Template 가져오기 함수
   const handleGetTemplate = async () => {
-    if (selectedRowCount !== 1) {
-      toast.error("Please select exactly one row to view template");
-      return;
-    }
 
     if (!projectCode) {
       toast.error("Project code is not available");
@@ -329,12 +325,12 @@ export default function DynamicTable({
 
     try {
       setIsLoadingTemplate(true);
-      
+
       const templateResult = await fetchTemplateFromSEDP(projectCode, formCode);
-      
+
       setTemplateData(templateResult);
       setTemplateDialogOpen(true);
-      
+
       toast.success("Template data loaded successfully");
     } catch (error) {
       console.error("Error fetching template:", error);
@@ -818,7 +814,7 @@ export default function DynamicTable({
             variant="outline"
             size="sm"
             onClick={handleGetTemplate}
-            disabled={isAnyOperationPending || selectedRowCount !== 1}
+            disabled={isAnyOperationPending}
           >
             {isLoadingTemplate ? (
               <Loader className="mr-2 size-4 animate-spin" />
@@ -826,13 +822,9 @@ export default function DynamicTable({
               <Eye className="mr-2 size-4" />
             )}
             View Template
-            {selectedRowCount === 1 && (
-              <span className="ml-2 text-xs bg-green-100 text-green-700 px-2 py-1 rounded">
-                1
-              </span>
-            )}
           </Button>
 
+
           {/* COMPARE WITH SEDP 버튼 */}
           <Button
             variant="outline"
@@ -920,19 +912,33 @@ export default function DynamicTable({
         isOpen={templateDialogOpen}
         onClose={() => setTemplateDialogOpen(false)}
         templateData={templateData}
-        selectedRow={selectedRowsData[0]}
+        selectedRow={selectedRowsData[0]} // SPR_ITM_LST_SETUP용
+        tableData={tableData} // SPR_LST_SETUP용 - 새로 추가
         formCode={formCode}
         contractItemId={contractItemId}
         editableFieldsMap={editableFieldsMap}
         onUpdateSuccess={(updatedValues) => {
-          // SpreadSheets에서 업데이트된 값을 테이블에 반영
-          const tagNo = updatedValues.TAG_NO;
-          if (tagNo) {
-            setTableData(prev =>
-              prev.map(item =>
-                item.TAG_NO === tagNo ? updatedValues : item
-              )
-            );
+          // 업데이트 로직도 수정해야 함 - 단일 행 또는 복수 행 처리
+          if (Array.isArray(updatedValues)) {
+            // SPR_LST_SETUP의 경우 - 복수 행 업데이트
+            const updatedData = [...tableData];
+            updatedValues.forEach(updatedItem => {
+              const index = updatedData.findIndex(item => item.TAG_NO === updatedItem.TAG_NO);
+              if (index !== -1) {
+                updatedData[index] = updatedItem;
+              }
+            });
+            setTableData(updatedData);
+          } else {
+            // SPR_ITM_LST_SETUP의 경우 - 단일 행 업데이트
+            const tagNo = updatedValues.TAG_NO;
+            if (tagNo) {
+              setTableData(prev =>
+                prev.map(item =>
+                  item.TAG_NO === tagNo ? updatedValues : item
+                )
+              );
+            }
           }
         }}
       />
-- 
cgit v1.2.3

