From 762ab8e684d57a56723dc19b521edf320207f6b8 Mon Sep 17 00:00:00 2001 From: kjs Date: Wed, 19 Nov 2025 13:51:24 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20Zustand=20modalDataStore=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=B6=80=EB=AA=A8=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=EA=B0=80=EC=A0=B8=EC=98=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: - modalDataStore가 window 전역 변수가 아닌 Zustand store임 - window.__modalDataRegistry로 접근 시도했으나 빈 객체 반환 - 거래처 데이터를 찾을 수 없어 customer_code 매핑 실패 해결: - useModalDataStore.getState().dataRegistry로 Zustand store 직접 접근 - ModalDataItem[] 배열에서 originalData 추출 - 각 테이블별 데이터를 modalDataStore 객체로 변환 - 거래처(customer_mng), 품목(item_info) 데이터 모두 접근 가능 기술적 변경: - dynamic import로 Zustand store 로드 - ModalDataItem 구조 이해 및 originalData 추출 - 에러 핸들링 (store 로드 실패 시) - 상세한 디버깅 로그 (테이블별 데이터 count) --- frontend/lib/utils/buttonActions.ts | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/frontend/lib/utils/buttonActions.ts b/frontend/lib/utils/buttonActions.ts index 58a3b288..c56a9dd4 100644 --- a/frontend/lib/utils/buttonActions.ts +++ b/frontend/lib/utils/buttonActions.ts @@ -543,9 +543,25 @@ export class ButtonActionExecutor { // 🆕 modalDataStore에서 누적된 모든 테이블 데이터 가져오기 // (여러 단계 모달에서 전달된 데이터 접근용) - const modalDataStore = typeof window !== 'undefined' - ? (window as any).__modalDataRegistry || {} - : {}; + let modalDataStoreRegistry: Record = {}; + if (typeof window !== 'undefined') { + try { + // Zustand store에서 데이터 가져오기 + const { useModalDataStore } = await import('@/stores/modalDataStore'); + modalDataStoreRegistry = useModalDataStore.getState().dataRegistry; + } catch (error) { + console.warn("⚠️ modalDataStore 로드 실패:", error); + } + } + + // 각 테이블의 첫 번째 항목을 modalDataStore로 변환 + const modalDataStore: Record = {}; + Object.entries(modalDataStoreRegistry).forEach(([key, items]) => { + if (Array.isArray(items) && items.length > 0) { + // ModalDataItem[] → originalData 추출 + modalDataStore[key] = items.map(item => item.originalData || item); + } + }); console.log(`🔍 [handleBatchSave] 부모 데이터:`, { hasParentData: Object.keys(parentData).length > 0, @@ -554,6 +570,12 @@ export class ButtonActionExecutor { selectedRowsData, originalData, modalDataStoreKeys: Object.keys(modalDataStore), + modalDataStoreDetails: Object.fromEntries( + Object.entries(modalDataStore).map(([key, data]) => [ + key, + { count: Array.isArray(data) ? data.length : 1, hasData: !!data } + ]) + ), }); // 각 SelectedItemsDetailInput 컴포넌트의 데이터 처리