diff --git a/src/components/estimate/Estimate.jsx b/src/components/estimate/Estimate.jsx index 71affac4..9604e7ba 100644 --- a/src/components/estimate/Estimate.jsx +++ b/src/components/estimate/Estimate.jsx @@ -19,7 +19,10 @@ import { convertNumberToPriceDecimal, convertNumberToPriceDecimalToFixed } from import ProductFeaturesPop from './popup/ProductFeaturesPop' import { v4 as uuidv4 } from 'uuid' import { correntObjectNoState } from '@/store/settingAtom' -import { useSearchParams } from 'next/navigation' +import { useRouter, useSearchParams } from 'next/navigation' +import { FloorPlanContext } from '@/app/floor-plan/FloorPlanProvider' +import { usePlan } from '@/hooks/usePlan' +import { usePopup } from '@/hooks/usePopup' export default function Estimate({}) { const [uniqueData, setUniqueData] = useState([]) @@ -70,6 +73,9 @@ export default function Estimate({}) { //견적서 상세데이터 const { estimateContextState, setEstimateContextState, addItem, handleEstimateFileDownload } = useEstimateController(currentPid) + const { selectedPlan } = usePlan() + const router = useRouter() + //견적특이사항 List const [specialNoteList, setSpecialNoteList] = useState([]) const [popShowSpecialNoteList, setPopShowSpecialNoteList] = useState([]) @@ -81,6 +87,8 @@ export default function Estimate({}) { const { setMenuNumber } = useCanvasMenu() + const { closeAll } = usePopup() + const currentObjectNo = searchParams.get('objectNo') setCurrentObjectNo(currentObjectNo) @@ -90,11 +98,12 @@ export default function Estimate({}) { setUploadFiles: setFiles, } - useEffect(() => { + const initEstimate = (currPid = currentPid) => { + console.log('🚀 ~ initEstimate ~ currPid:', currPid) setMenuNumber(5) setObjectNo(objectRecoil.floorPlanObjectNo) - setPlanNo(currentPid) + setPlanNo(currPid) // 공통코드 const code1 = findCommonCode(200800) @@ -121,6 +130,16 @@ export default function Estimate({}) { setPopShowSpecialNoteList(res) } }) + } + + useEffect(() => { + console.log('🚀 ~ Estimate ~ selectedPlan:', selectedPlan) + if (selectedPlan) initEstimate(selectedPlan.ordering) + }, [selectedPlan]) + + useEffect(() => { + closeAll() + initEstimate() }, []) useEffect(() => { diff --git a/src/components/simulator/Simulator.jsx b/src/components/simulator/Simulator.jsx index 24fa6d3b..ef752582 100644 --- a/src/components/simulator/Simulator.jsx +++ b/src/components/simulator/Simulator.jsx @@ -15,6 +15,8 @@ import { useMessage } from '@/hooks/useMessage' import { useCanvasMenu } from '@/hooks/common/useCanvasMenu' import { convertNumberToPriceDecimal } from '@/util/common-utils' +import { usePlan } from '@/hooks/usePlan' +import { usePopup } from '@/hooks/usePopup' // import { useSearchParams } from 'next/navigation' export default function Simulator() { @@ -24,6 +26,7 @@ export default function Simulator() { // const searchParams = useSearchParams() // const objectNo = searchParams.get('objectNo') // const pid = searchParams.get('pid') + const { selectedPlan } = usePlan() const chartRef = useRef(null) @@ -40,6 +43,12 @@ export default function Simulator() { // 차트 관련 const [chartData, setChartData] = useState([]) + const { closeAll } = usePopup() + + useEffect(() => { + closeAll() + }, []) + const data = { labels: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'], datasets: [ @@ -105,6 +114,7 @@ export default function Simulator() { } useEffect(() => { + console.log('🚀 ~ useEffect ~ selectedPlan:', selectedPlan) /* 초기화 작업 */ setChartData([]) setObjectDetail({}) @@ -121,7 +131,7 @@ export default function Simulator() { setPwrGnrSimType('D') setPwrRecoil({ ...pwrRecoil, type: 'D' }) } - }, [objectNo, pid]) + }, [objectNo, pid, selectedPlan]) // 물건 상세 정보 조회 const [objectDetail, setObjectDetail] = useState({}) diff --git a/src/hooks/usePlan.js b/src/hooks/usePlan.js index cd2b662d..f7848be5 100644 --- a/src/hooks/usePlan.js +++ b/src/hooks/usePlan.js @@ -1,7 +1,7 @@ 'use client' import { useContext, useEffect, useState } from 'react' -import { usePathname, useRouter } from 'next/navigation' +import { usePathname, useRouter, useSearchParams } from 'next/navigation' import { useRecoilState } from 'recoil' import { v4 as uuidv4 } from 'uuid' @@ -218,16 +218,18 @@ export function usePlan(params = {}) { }), ) } + useEffect(() => { setCurrentCanvasPlan(plans.find((plan) => plan.isCurrent) || null) setSelectedPlan(plans.find((plan) => plan.isCurrent)) + handleCurrentPlanUrl() // setBgImage() }, [plans]) - // 현재 plan이 변경될 때 마다 현재 plan의 링크로 이동 - useEffect(() => { - handlePlanMove() - }, [currentCanvasPlan]) + const handleCurrentPlanUrl = () => { + const currentPlan = plans.find((plan) => plan.isCurrent) + if (currentPlan) router.push(`${pathname}?pid=${currentPlan?.ordering}&objectNo=${floorPlanState?.objectNo}`) + } const setBgImage = () => { // readImage(selectedPlan?.id)