diff --git a/src/components/floor-plan/CanvasMenu.jsx b/src/components/floor-plan/CanvasMenu.jsx index 30a64e65..0e9055ab 100644 --- a/src/components/floor-plan/CanvasMenu.jsx +++ b/src/components/floor-plan/CanvasMenu.jsx @@ -296,7 +296,8 @@ export default function CanvasMenu(props) { }, [type, globalLocale]) useEffect(() => { - setMenuNumber(1) + if (Object.keys(basicSetting).length === 0) return + // setMenuNumber(1) // if ([2, 3].some((num) => num === canvasSetting?.roofSizeSet)) { // setMenuNumber(3) // setType('surface') @@ -306,7 +307,7 @@ export default function CanvasMenu(props) { // setType('outline') // setCurrentMenu(MENU.ROOF_COVERING.EXTERIOR_WALL_LINE) // } - }, [canvasSetting]) + }, [basicSetting]) const checkMenuState = (menu) => { return (['2', '3'].includes(canvasSetting?.roofSizeSet) && menu.index === 2) || (menuNumber === 4 && menu.index === 2) diff --git a/src/components/floor-plan/modal/placementShape/PlacementShapeSetting.jsx b/src/components/floor-plan/modal/placementShape/PlacementShapeSetting.jsx index c54d323f..866c6dea 100644 --- a/src/components/floor-plan/modal/placementShape/PlacementShapeSetting.jsx +++ b/src/components/floor-plan/modal/placementShape/PlacementShapeSetting.jsx @@ -43,60 +43,63 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set // 데이터를 최초 한 번만 조회 useEffect(() => { + if (!basicSetting || !currentRoof || Object.keys(currentRoof).length === 0 || Object.keys(basicSetting).length === 0) return const raftCodeList = findCommonCode('203800') setRaftCodes(raftCodeList) - setCurrentRoof({...currentRoof, roofSizeSet: basicSetting.roofMaterials.roofSizeSet, roofAngleSet: basicSetting.roofMaterials.roofAngleSet}) + // setCurrentRoof({ ...currentRoof, roofSizeSet: basicSetting.roofMaterials.roofSizeSet, roofAngleSet: basicSetting.roofMaterials.roofAngleSet }) }, []) useEffect(() => { - setBasicSettings({ - ...basicSetting, - roofSizeSet: String(currentRoof.roofSizeSet), - roofAngleSet: currentRoof.roofAngleSet, - roofsData: { - roofApply: true, - roofSeq: 0, - roofMatlCd: currentRoof.roofMatlCd, - roofWidth: currentRoof.width, - roofHeight: currentRoof.length, - roofHajebichi: currentRoof.hajebichi, - roofGap: currentRoof.raft, - roofLayout: currentRoof.layout, - roofPitch: currentRoof.pitch, - roofAngle: currentRoof.angle, - }, - }) + if (!currentRoof || Object.keys(currentRoof).length === 0) return + console.log(basicSetting) + setBasicSettings({ + ...basicSetting, + roofSizeSet: String(currentRoof.roofSizeSet), + roofAngleSet: currentRoof.roofAngleSet, + roofsData: { + roofApply: true, + roofSeq: 0, + roofMatlCd: currentRoof.roofMatlCd, + roofWidth: currentRoof.width, + roofHeight: currentRoof.length, + roofHajebichi: currentRoof.hajebichi, + roofGap: currentRoof.raft, + roofLayout: currentRoof.layout, + roofPitch: currentRoof.pitch, + roofAngle: currentRoof.angle, + }, + }) }, [currentRoof]) const handleRoofSizeSetChange = (value) => { - setCurrentRoof({...currentRoof, roofSizeSet: value}) + setCurrentRoof({ ...currentRoof, roofSizeSet: value }) } const handleRoofAngleSetChange = (value) => { - setCurrentRoof({...currentRoof, roofAngleSet: value}) + setCurrentRoof({ ...currentRoof, roofAngleSet: value }) } // Function to update the roofType and corresponding values const handleRoofTypeChange = (value) => { const selectedRoofMaterial = roofMaterials.find((roof) => roof.roofMatlCd === value) - setCurrentRoof({...selectedRoofMaterial, index: 0, roofSizeSet: String(currentRoof.roofSizeSet), roofAngleSet: currentRoof.roofAngleSet}) + setCurrentRoof({ ...selectedRoofMaterial, index: 0, roofSizeSet: String(currentRoof.roofSizeSet), roofAngleSet: currentRoof.roofAngleSet }) } const changeInput = (value, e) => { const { name } = e.target - setCurrentRoof({...currentRoof, [name]: Number(value)}) + setCurrentRoof({ ...currentRoof, [name]: Number(value) }) } const handleRafterChange = (value) => { - setCurrentRoof({...currentRoof, raft: value}) + setCurrentRoof({ ...currentRoof, raft: value }) } const handleRoofLayoutChange = (value) => { - setCurrentRoof({...currentRoof, layout: value}) + setCurrentRoof({ ...currentRoof, layout: value }) } const handleSaveBtn = () => { - const roofInfo = { + const roofInfo = { ...currentRoof, roofCd: roofRef.roofCd.current?.value, width: roofRef.width.current?.value, @@ -107,7 +110,7 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set layout: currentRoof.layout, index: 0, } - + const newAddedRoofs = [...addedRoofs] if (addedRoofs.length === 1) { newAddedRoofs[0] = { ...roofInfo } @@ -119,7 +122,7 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set selectedRoofMaterial: { // 선택된 지붕재 정보 roofInfo, - } + }, }) setBasicSettings({ @@ -184,7 +187,7 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set name="roofSizeSet" id="ra01" value="1" // roofSizeSet 값이 '1'인 경우 - checked={currentRoof.roofSizeSet === '1'} // 선택 여부 확인 + checked={currentRoof?.roofSizeSet === '1'} // 선택 여부 확인 //onChange={(e) => setBasicSettings({ ...basicSetting, roofSizeSet: e.target.value })} // 상태 업데이트 onClick={() => handleRoofSizeSetChange('1')} /> @@ -196,7 +199,7 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set name="roofSizeSet" id="ra02" value="2" // roofSizeSet 값이 '2'인 경우 - checked={currentRoof.roofSizeSet === '2'} // 선택 여부 확인 + checked={currentRoof?.roofSizeSet === '2'} // 선택 여부 확인 //onChange={(e) => setBasicSettings({ ...basicSetting, roofSizeSet: e.target.value })} // 상태 업데이트 onClick={() => handleRoofSizeSetChange('2')} /> @@ -208,7 +211,7 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set name="roofSizeSet" id="ra03" value="3" // roofSizeSet 값이 '3'인 경우 - checked={currentRoof.roofSizeSet === '3'} // 선택 여부 확인 + checked={currentRoof?.roofSizeSet === '3'} // 선택 여부 확인 //onChange={(e) => setBasicSettings({ ...basicSetting, roofSizeSet: e.target.value })} // 상태 업데이트 onClick={() => handleRoofSizeSetChange('3')} /> @@ -227,7 +230,7 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set name="roofAngleSet" id="ra04" value="slope" // 첫 번째 라디오 버튼의 값 - checked={currentRoof.roofAngleSet === 'slope'} // 현재 선택된 값인지 확인 + checked={currentRoof?.roofAngleSet === 'slope'} // 현재 선택된 값인지 확인 //onChange={(e) => setBasicSettings({ ...basicSetting, roofAngleSet: e.target.value })} // 상태 업데이트 onClick={() => handleRoofAngleSetChange('slope')} /> @@ -239,7 +242,7 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set name="roofAngleSet" id="ra05" value="flat" // 두 번째 라디오 버튼의 값 - checked={currentRoof.roofAngleSet === 'flat'} // 현재 선택된 값인지 확인 + checked={currentRoof?.roofAngleSet === 'flat'} // 현재 선택된 값인지 확인 //onChange={(e) => setBasicSettings({ ...basicSetting, roofAngleSet: e.target.value })} // 상태 업데이트 onClick={() => handleRoofAngleSetChange('flat')} /> @@ -259,17 +262,19 @@ export default function PlacementShapeSetting({ id, pos = { x: 50, y: 180 }, set