fix: Zustand modalDataStore에서 부모 데이터 가져오기
문제: - 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)
This commit is contained in:
parent
97b5cd7a5b
commit
762ab8e684
|
|
@ -543,9 +543,25 @@ export class ButtonActionExecutor {
|
|||
|
||||
// 🆕 modalDataStore에서 누적된 모든 테이블 데이터 가져오기
|
||||
// (여러 단계 모달에서 전달된 데이터 접근용)
|
||||
const modalDataStore = typeof window !== 'undefined'
|
||||
? (window as any).__modalDataRegistry || {}
|
||||
: {};
|
||||
let modalDataStoreRegistry: Record<string, any[]> = {};
|
||||
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<string, any> = {};
|
||||
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 컴포넌트의 데이터 처리
|
||||
|
|
|
|||
Loading…
Reference in New Issue