Merge branch 'feature/v2-unified-renewal' of http://39.117.244.52:3000/kjs/ERP-node into gbpark-node
; Please enter a commit message to explain why this merge is necessary, ; especially if it merges an updated upstream into a topic branch. ; ; Lines starting with ';' will be ignored, and an empty message aborts ; the commit.
This commit is contained in:
@@ -177,10 +177,18 @@ const FileUploadComponent: React.FC<FileUploadComponentProps> = ({
|
||||
// 🔑 레코드별 고유 키 사용
|
||||
const backupKey = getUniqueKey();
|
||||
const backupFiles = localStorage.getItem(backupKey);
|
||||
console.log("🔎 [DEBUG-MOUNT] localStorage 확인:", {
|
||||
backupKey,
|
||||
hasBackup: !!backupFiles,
|
||||
componentId: component.id,
|
||||
recordId: recordId,
|
||||
formDataId: formData?.id,
|
||||
stackTrace: new Error().stack?.split('\n').slice(1, 4).join(' <- '),
|
||||
});
|
||||
if (backupFiles) {
|
||||
const parsedFiles = JSON.parse(backupFiles);
|
||||
if (parsedFiles.length > 0) {
|
||||
console.log("🚀 컴포넌트 마운트 시 파일 즉시 복원:", {
|
||||
console.log("🚀 [DEBUG-MOUNT] 파일 즉시 복원:", {
|
||||
uniqueKey: backupKey,
|
||||
componentId: component.id,
|
||||
recordId: recordId,
|
||||
@@ -203,6 +211,50 @@ const FileUploadComponent: React.FC<FileUploadComponentProps> = ({
|
||||
}
|
||||
}, [component.id, getUniqueKey, recordId]); // 레코드별 고유 키 변경 시 재실행
|
||||
|
||||
// 🆕 모달 닫힘/저장 성공 시 localStorage 파일 캐시 정리 (등록 후 재등록 시 이전 파일 잔존 방지)
|
||||
useEffect(() => {
|
||||
const handleClearFileCache = (event: Event) => {
|
||||
const backupKey = getUniqueKey();
|
||||
const eventType = event.type;
|
||||
console.log("🧹 [DEBUG-CLEAR] 파일 캐시 정리 이벤트 수신:", {
|
||||
eventType,
|
||||
backupKey,
|
||||
componentId: component.id,
|
||||
currentFiles: uploadedFiles.length,
|
||||
hasLocalStorage: !!localStorage.getItem(backupKey),
|
||||
});
|
||||
try {
|
||||
localStorage.removeItem(backupKey);
|
||||
setUploadedFiles([]);
|
||||
setRepresentativeImageUrl(null);
|
||||
if (typeof window !== "undefined") {
|
||||
const globalFileState = (window as any).globalFileState || {};
|
||||
delete globalFileState[backupKey];
|
||||
(window as any).globalFileState = globalFileState;
|
||||
}
|
||||
console.log("🧹 [DEBUG-CLEAR] 정리 완료:", backupKey);
|
||||
} catch (e) {
|
||||
console.warn("파일 캐시 정리 실패:", e);
|
||||
}
|
||||
};
|
||||
|
||||
// EditModal 닫힘, ScreenModal 연속 등록 저장 성공, 일반 저장 성공 모두 처리
|
||||
window.addEventListener("closeEditModal", handleClearFileCache);
|
||||
window.addEventListener("saveSuccess", handleClearFileCache);
|
||||
window.addEventListener("saveSuccessInModal", handleClearFileCache);
|
||||
|
||||
console.log("🔎 [DEBUG-CLEAR] 이벤트 리스너 등록 완료:", {
|
||||
componentId: component.id,
|
||||
backupKey: getUniqueKey(),
|
||||
});
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("closeEditModal", handleClearFileCache);
|
||||
window.removeEventListener("saveSuccess", handleClearFileCache);
|
||||
window.removeEventListener("saveSuccessInModal", handleClearFileCache);
|
||||
};
|
||||
}, [getUniqueKey]);
|
||||
|
||||
// 🎯 화면설계 모드에서 실제 화면으로의 실시간 동기화 이벤트 리스너
|
||||
useEffect(() => {
|
||||
const handleDesignModeFileChange = (event: CustomEvent) => {
|
||||
@@ -363,6 +415,12 @@ const FileUploadComponent: React.FC<FileUploadComponentProps> = ({
|
||||
console.warn("파일 병합 중 오류:", e);
|
||||
}
|
||||
|
||||
console.log("🔎 [DEBUG-LOAD] API 응답 후 파일 설정:", {
|
||||
componentId: component.id,
|
||||
serverFiles: formattedFiles.length,
|
||||
finalFiles: finalFiles.length,
|
||||
files: finalFiles.map((f: any) => ({ objid: f.objid, name: f.realFileName })),
|
||||
});
|
||||
setUploadedFiles(finalFiles);
|
||||
|
||||
// 전역 상태에도 저장 (레코드별 고유 키 사용)
|
||||
|
||||
@@ -431,6 +431,11 @@ const FileUploadComponent: React.FC<FileUploadComponentProps> = ({
|
||||
return; // DB 로드 성공 시 localStorage 무시
|
||||
}
|
||||
|
||||
// 🆕 등록 모드(새 레코드)인 경우 fallback 로드도 스킵 - 항상 빈 상태 유지
|
||||
if (!isRecordMode || !recordId) {
|
||||
return;
|
||||
}
|
||||
|
||||
// DB 로드 실패 시에만 기존 로직 사용 (하위 호환성)
|
||||
|
||||
// 전역 상태에서 최신 파일 정보 가져오기 (🆕 고유 키 사용)
|
||||
|
||||
Reference in New Issue
Block a user