diff --git a/src/components/floor-plan/modal/circuitTrestle/CircuitTrestleSetting.jsx b/src/components/floor-plan/modal/circuitTrestle/CircuitTrestleSetting.jsx index adeb0300..e53c8619 100644 --- a/src/components/floor-plan/modal/circuitTrestle/CircuitTrestleSetting.jsx +++ b/src/components/floor-plan/modal/circuitTrestle/CircuitTrestleSetting.jsx @@ -21,6 +21,7 @@ import { selectedModuleState } from '@/store/selectedModuleOptions' import { v4 as uuidv4 } from 'uuid' import { stepUpListDataState } from '@/store/circuitTrestleAtom' +import { useEstimate } from '@/hooks/useEstimate' const ALLOCATION_TYPE = { AUTO: 'auto', @@ -31,6 +32,7 @@ export default function CircuitTrestleSetting({ id }) { const { closePopup } = usePopup() const { apply } = useTrestle() const { swalFire } = useSwal() + const { saveEstimate } = useEstimate() const canvas = useRecoilValue(canvasState) const [makers, setMakers] = useRecoilState(makersState) @@ -336,8 +338,10 @@ export default function CircuitTrestleSetting({ id }) { }) const result = await apply() + if (result) { + await saveEstimate(result) + } removeNotAllocationModules() - apply() } const removeNotAllocationModules = () => { diff --git a/src/hooks/module/useTrestle.js b/src/hooks/module/useTrestle.js index 083c24c3..f39d3057 100644 --- a/src/hooks/module/useTrestle.js +++ b/src/hooks/module/useTrestle.js @@ -1,18 +1,16 @@ -import { useRecoilState, useRecoilValue } from 'recoil' +import { useRecoilValue } from 'recoil' import { canvasState, currentAngleTypeSelector } from '@/store/canvasAtom' import { POLYGON_TYPE } from '@/common/common' import { moduleSelectionDataState } from '@/store/selectedModuleOptions' import { getDegreeByChon, getTrestleLength } from '@/util/canvas-util' import { v4 as uuidv4 } from 'uuid' import { useMasterController } from '@/hooks/common/useMasterController' -import { estimateParamAtom } from '@/store/estimateAtom' // 회로 및 가대설정 export const useTrestle = () => { const canvas = useRecoilValue(canvasState) const moduleSelectionData = useRecoilValue(moduleSelectionDataState) //다음으로 넘어가는 최종 데이터 const { getQuotationItem } = useMasterController() - const [estimateParam, setEstimateParam] = useRecoilState(estimateParamAtom) const currentAngleType = useRecoilValue(currentAngleTypeSelector) const apply = () => { @@ -462,7 +460,7 @@ export const useTrestle = () => { return setEstimateData() } catch (e) { - return false + return null } } @@ -480,7 +478,7 @@ export const useTrestle = () => { //견적서 itemList 조회 const res = await getQuotationItem(params) if (!res.data) { - return false + return null } const itemList = res.data //northArrangement 북면 설치 여부 @@ -540,10 +538,10 @@ export const useTrestle = () => { } }) - setEstimateParam({ ...estimateParam, itemList, northArrangement, roofSurfaceList, circuitItemList }) + const estimateParam = { itemList, northArrangement, roofSurfaceList, circuitItemList } // 정상적으로 완료 되면 true 반환 - return true + return estimateParam } const getNorthArrangement = () => { diff --git a/src/hooks/useEstimate.js b/src/hooks/useEstimate.js new file mode 100644 index 00000000..7fa4ff60 --- /dev/null +++ b/src/hooks/useEstimate.js @@ -0,0 +1,59 @@ +import { useContext } from 'react' + +import { useRecoilValue } from 'recoil' + +import { useAxios } from '@/hooks/useAxios' +import { useSwal } from '@/hooks/useSwal' +import { GlobalDataContext } from '@/app/GlobalDataProvider' +import { currentCanvasPlanState } from '@/store/canvasAtom' +import { loginUserStore } from '@/store/commonAtom' + +export function useEstimate() { + const { managementStateLoaded } = useContext(GlobalDataContext) + + const loginUserState = useRecoilValue(loginUserStore) + const currentCanvasPlan = useRecoilValue(currentCanvasPlanState) + + const { swalFire } = useSwal() + const { promisePost } = useAxios() + + /** + * 도면 견적서 저장 + */ + const saveEstimate = async (estimateParam) => { + const userId = loginUserState.userId + const saleStoreId = managementStateLoaded.saleStoreId + const objectNo = currentCanvasPlan.objectNo + const planNo = currentCanvasPlan.planNo + const slope = estimateParam.roofSurfaceList[0].slope + const angle = estimateParam.roofSurfaceList[0].angle + const surfaceType = managementStateLoaded.surfaceType + const setupHeight = managementStateLoaded.installHeight + const standardWindSpeedId = managementStateLoaded.standardWindSpeedId + const snowfall = managementStateLoaded.verticalSnowCover + const drawingFlg = '1' + + const saveEstimateData = { + ...estimateParam, + userId: userId, + saleStoreId: saleStoreId, + objectNo: objectNo, + planNo: planNo, + slope: slope, + angle: angle, + surfaceType: surfaceType, + setupHeight: setupHeight, + standardWindSpeedId: standardWindSpeedId, + snowfall: snowfall, + drawingFlg: drawingFlg, + } + + await promisePost({ url: '/api/estimate/save-estimate', data: saveEstimateData }).catch((error) => { + swalFire({ text: error.message, icon: 'error' }) + }) + } + + return { + saveEstimate, + } +}