qcast-front/src/app/floor-plan/FloorPlanProvider.js
2024-11-25 10:32:48 +09:00

74 lines
2.1 KiB
JavaScript

'ues client'
import { correntObjectNoState } from '@/store/settingAtom'
import { notFound, usePathname, useSearchParams } from 'next/navigation'
// import { ErrorBoundary } from 'next/dist/client/components/error-boundary'
// import ServerError from '../error'
import { createContext, useEffect, useReducer, useState } 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: '',
}
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')
if (pathname === '/floor-plan') {
if (pid === undefined || pid === '' || objectNo === undefined || objectNo === '') {
notFound()
}
setCurrentObjectNo(objectNo)
}
const [floorPlanState, setFloorPlanState] = useState({
// 플랜 파일 업로드 모달 오픈 제어
refFileModalOpen: false,
// 플랜 회전 모드 제어
toggleRotate: false,
// 물건 번호
objectNo,
// 플랜 번호
pid,
})
useEffect(() => {
console.log('🚀 ~ FloorPlanProvider ~ floorPlanState:', floorPlanState)
}, [floorPlanState])
const [estimateContextState, setEstimateContextState] = useReducer(reducer, defaultEstimateData)
return (
<FloorPlanContext.Provider value={{ floorPlanState, setFloorPlanState, estimateContextState, setEstimateContextState }}>
{children}
</FloorPlanContext.Provider>
)
}
export default FloorPlanProvider