From 09507122be23f8c83212c56e3cc969d118207efa Mon Sep 17 00:00:00 2001 From: Daseul Kim Date: Tue, 4 Feb 2025 18:18:53 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=8F=84=EB=A9=B4=20=EA=B2=AC=EC=A0=81?= =?UTF-8?q?=EC=84=9C=20=EC=A0=80=EC=9E=A5=20api=20=ED=98=B8=EC=B6=9C=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../circuitTrestle/CircuitTrestleSetting.jsx | 6 +- src/hooks/module/useTrestle.js | 12 ++-- src/hooks/useEstimate.js | 59 +++++++++++++++++++ 3 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 src/hooks/useEstimate.js 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, + } +}