From 74843fe598702a9a55f914f2d2d291368a5abb13 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Wed, 1 Oct 2025 10:31:23 +0000
Subject: (대표님) dolce 수정, spreadjs 수정 등
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 components/form-data/spreadJS-dialog.tsx | 63 +++++++++++++++++++++++++++++++-
 1 file changed, 61 insertions(+), 2 deletions(-)

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

diff --git a/components/form-data/spreadJS-dialog.tsx b/components/form-data/spreadJS-dialog.tsx
index 91d5672c..af1a3dca 100644
--- a/components/form-data/spreadJS-dialog.tsx
+++ b/components/form-data/spreadJS-dialog.tsx
@@ -197,7 +197,38 @@ export function TemplateViewDialog({
   }, []);
 
   React.useEffect(() => {
-    if (!templateData) return;
+    // 템플릿 데이터가 없거나 빈 배열인 경우 기본 GRD_LIST 템플릿 생성
+    if (!templateData || (Array.isArray(templateData) && templateData.length === 0)) {
+      // columnsJSON이 있으면 기본 GRD_LIST 템플릿 생성
+      if (columnsJSON && columnsJSON.length > 0) {
+        const defaultGrdTemplate: TemplateItem = {
+          TMPL_ID: 'DEFAULT_GRD_LIST',
+          NAME: 'Default Grid View',
+          TMPL_TYPE: 'GRD_LIST',
+          SPR_LST_SETUP: {
+            ACT_SHEET: '',
+            HIDN_SHEETS: [],
+            DATA_SHEETS: []
+          },
+          GRD_LST_SETUP: {
+            REG_TYPE_ID: 'DEFAULT',
+            SPR_ITM_IDS: [],
+            ATTS: []
+          },
+          SPR_ITM_LST_SETUP: {
+            ACT_SHEET: '',
+            HIDN_SHEETS: [],
+            DATA_SHEETS: []
+          }
+        };
+        
+        setAvailableTemplates([defaultGrdTemplate]);
+        setSelectedTemplateId('DEFAULT_GRD_LIST');
+        setTemplateType('GRD_LIST');
+        console.log('📋 Created default GRD_LIST template');
+      }
+      return;
+    }
 
     let templates: TemplateItem[];
     if (Array.isArray(templateData)) {
@@ -207,6 +238,34 @@ export function TemplateViewDialog({
     }
 
     const validTemplates = templates.filter(isValidTemplate);
+    
+    // 유효한 템플릿이 없지만 columnsJSON이 있으면 기본 GRD_LIST 추가
+    if (validTemplates.length === 0 && columnsJSON && columnsJSON.length > 0) {
+      const defaultGrdTemplate: TemplateItem = {
+        TMPL_ID: 'DEFAULT_GRD_LIST',
+        NAME: 'Default Grid View',
+        TMPL_TYPE: 'GRD_LIST',
+        SPR_LST_SETUP: {
+          ACT_SHEET: '',
+          HIDN_SHEETS: [],
+          DATA_SHEETS: []
+        },
+        GRD_LST_SETUP: {
+          REG_TYPE_ID: 'DEFAULT',
+          SPR_ITM_IDS: [],
+          ATTS: []
+        },
+        SPR_ITM_LST_SETUP: {
+          ACT_SHEET: '',
+          HIDN_SHEETS: [],
+          DATA_SHEETS: []
+        }
+      };
+      
+      validTemplates.push(defaultGrdTemplate);
+      console.log('📋 Added default GRD_LIST template to empty template list');
+    }
+    
     setAvailableTemplates(validTemplates);
 
     if (validTemplates.length > 0 && !selectedTemplateId) {
@@ -215,7 +274,7 @@ export function TemplateViewDialog({
       setSelectedTemplateId(firstTemplate.TMPL_ID);
       setTemplateType(templateTypeToSet);
     }
-  }, [templateData, selectedTemplateId, isValidTemplate, determineTemplateType]);
+  }, [templateData, selectedTemplateId, isValidTemplate, determineTemplateType, columnsJSON]);
 
   const handleTemplateChange = (templateId: string) => {
     const template = availableTemplates.find(t => t.TMPL_ID === templateId);
-- 
cgit v1.2.3

