diff --git a/frontend/components/common/ScreenModal.tsx b/frontend/components/common/ScreenModal.tsx index f44e2227..65dbf84c 100644 --- a/frontend/components/common/ScreenModal.tsx +++ b/frontend/components/common/ScreenModal.tsx @@ -57,16 +57,18 @@ export const ScreenModal: React.FC = ({ className }) => { // 폼 데이터 상태 추가 const [formData, setFormData] = useState>({}); - // 연속 등록 모드 상태 (localStorage에 저장하여 리렌더링에 영향받지 않도록) - const continuousModeRef = useRef(false); - const [, setForceUpdate] = useState(0); // 강제 리렌더링용 (값은 사용하지 않음) + // 연속 등록 모드 상태 (state로 변경 - 체크박스 UI 업데이트를 위해) + const [continuousMode, setContinuousMode] = useState(false); + + // 화면 리셋 키 (컴포넌트 강제 리마운트용) + const [resetKey, setResetKey] = useState(0); // localStorage에서 연속 모드 상태 복원 useEffect(() => { const savedMode = localStorage.getItem("screenModal_continuousMode"); if (savedMode === "true") { - continuousModeRef.current = true; - // console.log("🔄 연속 모드 복원: true"); + setContinuousMode(true); + console.log("🔄 연속 모드 복원: true"); } }, []); @@ -162,29 +164,39 @@ export const ScreenModal: React.FC = ({ className }) => { }); setScreenData(null); setFormData({}); - continuousModeRef.current = false; + setContinuousMode(false); localStorage.setItem("screenModal_continuousMode", "false"); // localStorage에 저장 - // console.log("🔄 연속 모드 초기화: false"); + console.log("🔄 연속 모드 초기화: false"); }; // 저장 성공 이벤트 처리 (연속 등록 모드 지원) const handleSaveSuccess = () => { - const isContinuousMode = continuousModeRef.current; - // console.log("💾 저장 성공 이벤트 수신"); - // console.log("📌 현재 연속 모드 상태 (ref):", isContinuousMode); - // console.log("📌 localStorage:", localStorage.getItem("screenModal_continuousMode")); + const isContinuousMode = continuousMode; + console.log("💾 저장 성공 이벤트 수신"); + console.log("📌 현재 연속 모드 상태:", isContinuousMode); + console.log("📌 localStorage:", localStorage.getItem("screenModal_continuousMode")); if (isContinuousMode) { // 연속 모드: 폼만 초기화하고 모달은 유지 - // console.log("✅ 연속 모드 활성화 - 폼만 초기화"); + console.log("✅ 연속 모드 활성화 - 폼 초기화 및 화면 리셋"); - // 폼만 초기화 (연속 모드 상태는 localStorage에 저장되어 있으므로 유지됨) + // 1. 폼 데이터 초기화 setFormData({}); + + // 2. 리셋 키 변경 (컴포넌트 강제 리마운트) + setResetKey(prev => prev + 1); + console.log("🔄 resetKey 증가 - 컴포넌트 리마운트"); + + // 3. 화면 데이터 다시 로드 (채번 규칙 새로 생성) + if (modalState.screenId) { + console.log("🔄 화면 데이터 다시 로드:", modalState.screenId); + loadScreenData(modalState.screenId); + } toast.success("저장되었습니다. 계속 입력하세요."); } else { // 일반 모드: 모달 닫기 - // console.log("❌ 일반 모드 - 모달 닫기"); + console.log("❌ 일반 모드 - 모달 닫기"); handleCloseModal(); } }; @@ -198,7 +210,7 @@ export const ScreenModal: React.FC = ({ className }) => { window.removeEventListener("closeSaveModal", handleCloseModal); window.removeEventListener("saveSuccessInModal", handleSaveSuccess); }; - }, []); // 의존성 제거 (ref 사용으로 최신 상태 참조) + }, [continuousMode]); // continuousMode 의존성 추가 // 화면 데이터 로딩 useEffect(() => { @@ -415,18 +427,21 @@ export const ScreenModal: React.FC = ({ className }) => { setFormData({}); // 폼 데이터 초기화 }; - // 모달 크기 설정 - 화면 내용에 맞게 동적 조정 + // 모달 크기 설정 - 화면관리 설정 크기 + 헤더/푸터 const getModalStyle = () => { if (!screenDimensions) { return { className: "w-fit min-w-[400px] max-w-4xl max-h-[90vh] overflow-hidden p-0", - style: {}, + style: undefined, // undefined로 변경 - defaultWidth/defaultHeight 사용 }; } - // 헤더 높이를 최소화 (제목 영역만) - const headerHeight = 60; // DialogHeader 최소 높이 (타이틀 + 최소 패딩) - const totalHeight = screenDimensions.height + headerHeight; + // 화면관리에서 설정한 크기 = 컨텐츠 영역 크기 + // 실제 모달 크기 = 컨텐츠 + 헤더 + 연속등록 체크박스 + const headerHeight = 60; // DialogHeader (타이틀 + 패딩) + const footerHeight = 52; // 연속 등록 모드 체크박스 영역 + + const totalHeight = screenDimensions.height + headerHeight + footerHeight; return { className: "overflow-hidden p-0", @@ -504,7 +519,7 @@ export const ScreenModal: React.FC = ({ className }) => { = ({ className }) => { -
+
{loading ? (
@@ -568,7 +583,7 @@ export const ScreenModal: React.FC = ({ className }) => { return ( = ({ className }) => {
{ const isChecked = checked === true; - continuousModeRef.current = isChecked; + setContinuousMode(isChecked); localStorage.setItem("screenModal_continuousMode", String(isChecked)); - setForceUpdate((prev) => prev + 1); // 체크박스 UI 업데이트를 위한 강제 리렌더링 - // console.log("🔄 연속 모드 변경:", isChecked); + console.log("🔄 연속 모드 변경:", isChecked); }} />