85 lines
2.4 KiB
JavaScript
85 lines
2.4 KiB
JavaScript
'ues client'
|
|
|
|
import { correntObjectNoState } from '@/store/settingAtom'
|
|
import { notFound, usePathname, useSearchParams } from 'next/navigation'
|
|
import { createContext, useReducer, useState, useEffect } from 'react'
|
|
import { useSetRecoilState } from 'recoil'
|
|
|
|
const reducer = (prevState, nextState) => {
|
|
return { ...prevState, ...nextState }
|
|
}
|
|
|
|
const defaultEstimateData = {
|
|
estimateDate: new Date(), //견적일
|
|
charger: '', //담당자
|
|
objectName: '', //안건명
|
|
objectNameOmit: '', //경칭코드
|
|
estimateType: '', //주문분류
|
|
remarks: '', //비고
|
|
estimateOption: '', //견적특이사항
|
|
itemList: [],
|
|
fileList: [],
|
|
fileFlg: '0', //후일 자료 제출 (체크 1 노체크 0)
|
|
priceCd: '',
|
|
}
|
|
|
|
/**
|
|
* 모듈,회로 구성 상태 데이터
|
|
* 각 설정 팝업 상태를 저장하는 데이터
|
|
*/
|
|
const defaultProcessStep = {
|
|
gnbStep: 0,
|
|
processStep: 0,
|
|
moduleCofigureData: {},
|
|
pcsConfigureData: {},
|
|
}
|
|
|
|
export const FloorPlanContext = createContext({
|
|
floorPlanState: {},
|
|
setFloorPlanState: () => {},
|
|
estimateContextState: {},
|
|
setEstimateContextState: () => {},
|
|
})
|
|
|
|
const FloorPlanProvider = ({ children }) => {
|
|
const pathname = usePathname()
|
|
const setCurrentObjectNo = useSetRecoilState(correntObjectNoState)
|
|
const searchParams = useSearchParams()
|
|
const objectNo = searchParams.get('objectNo')
|
|
const pid = searchParams.get('pid')
|
|
|
|
//useEffect(() => { // 오류 발생으로 useEffect 사용
|
|
if (pathname === '/floor-plan') {
|
|
if (pid === undefined || pid === '' || pid === null || objectNo === undefined || objectNo === '' || objectNo === null) {
|
|
notFound()
|
|
}
|
|
setCurrentObjectNo(objectNo)
|
|
}
|
|
//}, [pid, objectNo])
|
|
|
|
const [floorPlanState, setFloorPlanState] = useState({
|
|
// 플랜 파일 업로드 모달 오픈 제어
|
|
refFileModalOpen: false,
|
|
// 플랜 회전 모드 제어
|
|
toggleRotate: false,
|
|
// 물건 번호
|
|
objectNo,
|
|
// 플랜 번호
|
|
pid,
|
|
})
|
|
|
|
const [estimateContextState, setEstimateContextState] = useReducer(reducer, defaultEstimateData)
|
|
|
|
const [processStepState, setProcessStepState] = useReducer(reducer, defaultProcessStep)
|
|
|
|
return (
|
|
<FloorPlanContext.Provider
|
|
value={{ floorPlanState, setFloorPlanState, estimateContextState, setEstimateContextState, processStepState, setProcessStepState }}
|
|
>
|
|
{children}
|
|
</FloorPlanContext.Provider>
|
|
)
|
|
}
|
|
|
|
export default FloorPlanProvider
|