From f8f769fd49c43d2fb327320360e52d839b7f0977 Mon Sep 17 00:00:00 2001 From: nalpari Date: Mon, 4 Nov 2024 13:40:42 +0900 Subject: [PATCH 1/2] feat: add useEstimateController --- .../estimate/useEstimateController.js | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/hooks/floorPlan/estimate/useEstimateController.js diff --git a/src/hooks/floorPlan/estimate/useEstimateController.js b/src/hooks/floorPlan/estimate/useEstimateController.js new file mode 100644 index 00000000..280c70da --- /dev/null +++ b/src/hooks/floorPlan/estimate/useEstimateController.js @@ -0,0 +1,60 @@ +import { useAxios } from '@/hooks/useAxios' +import { useReducer } from 'react' + +const reducer = (prevState, nextState) => { + return { ...prevState, ...nextState } +} + +// Constants +const ESTIMATE_API_ENDPOINT = '/api/estimates' // API 엔드포인트 정의 + +const defaultEstimateData = { + name: '', + objectName: '', + estimateDate: '', + itemList: [{ id: 1, name: '' }], +} + +// Helper functions +const updateItemInList = (itemList, id, updates) => { + return itemList.map((item) => (item.id === id ? { ...item, ...updates } : item)) +} + +export const useEstimateController = () => { + const { promisePost } = useAxios() + const [state, setState] = useReducer(reducer, defaultEstimateData) + + const updateItem = (id, updates) => { + setState({ + itemList: updateItemInList(state.itemList, id, updates), + }) + } + + const addItem = () => { + const newId = Math.max(...state.itemList.map((item) => item.id)) + 1 + setState({ + itemList: [...state.itemList, { id: newId, name: '' }], + }) + } + + const handleEstimateSubmit = async () => { + try { + const result = await promisePost({ + url: ESTIMATE_API_ENDPOINT, + data: state, + }) + return result + } catch (error) { + console.error('Failed to submit estimate:', error) + throw error + } + } + + return { + state, + setState, + updateItem, + addItem, + handleEstimateSubmit, + } +} From c476709850506fb106b79801d95ac5e826479e74 Mon Sep 17 00:00:00 2001 From: basssy Date: Mon, 4 Nov 2024 14:11:27 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=EA=B2=AC=EC=A0=81=EC=84=9C=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=ED=99=94=EB=A9=B4=20=EB=A9=94=EC=84=B8=EC=A7=80=20&?= =?UTF-8?q?=20=EA=B2=AC=EC=A0=81=EC=84=9C=20=EC=83=81=EC=84=B8=ED=99=94?= =?UTF-8?q?=EB=A9=B4=20=EC=83=81=EB=8B=A8=20CanvasMenu=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=20=EB=B2=84=ED=8A=BC=20=EA=B4=80=EB=A0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/floor-plan/CanvasMenu.jsx | 5 ++++- src/locales/ja.json | 5 ++++- src/locales/ko.json | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/floor-plan/CanvasMenu.jsx b/src/components/floor-plan/CanvasMenu.jsx index 6ac20787..09253f72 100644 --- a/src/components/floor-plan/CanvasMenu.jsx +++ b/src/components/floor-plan/CanvasMenu.jsx @@ -32,6 +32,8 @@ import { menusState, menuTypeState } from '@/store/menuAtom' import useMenu from '@/hooks/common/useMenu' import { MENU } from '@/common/common' +import { useEstimateController } from '@/hooks/floorPlan/estimate/useEstimateController' + export default function CanvasMenu(props) { const { menuNumber, setMenuNumber } = props const pathname = usePathname() @@ -51,6 +53,7 @@ export default function CanvasMenu(props) { const canvas = useRecoilValue(canvasState) const { handleZoomClear } = useCanvasEvent() const { handleMenu } = useMenu() + const { handleEstimateSubmit } = useEstimateController() const { getMessage } = useMessage() const { currentCanvasPlan, saveCanvas } = usePlan() @@ -222,7 +225,7 @@ export default function CanvasMenu(props) { {getMessage('plan.menu.estimate.docDown')} - diff --git a/src/locales/ja.json b/src/locales/ja.json index c57582b2..e4605537 100644 --- a/src/locales/ja.json +++ b/src/locales/ja.json @@ -814,7 +814,10 @@ "estimate.detail.sepcialEstimateProductInfo.calcFormula2": "PKG単価 (W)×PKG容量(W)", "estimate.detail.header.showPrice": "価格表示", "estimate.detail.showPrice.btn1": "Pricing", - "estimate.detail.showPrice.description": "クリックして製品の特異性を確認する", + "estimate.detail.showPrice.description1": "製品価格 OPEN", + "estimate.detail.showPrice.description2": "追加, 変更資材", + "estimate.detail.showPrice.description3": "添付必須", + "estimate.detail.showPrice.description4": "クリックして製品の特異性を確認する", "estimate.detail.showPrice.btn2": "製品を追加", "estimate.detail.showPrice.btn3": "製品削除" } diff --git a/src/locales/ko.json b/src/locales/ko.json index 1cb2c279..03443a0b 100644 --- a/src/locales/ko.json +++ b/src/locales/ko.json @@ -820,7 +820,10 @@ "estimate.detail.sepcialEstimateProductInfo.calcFormula2": "PKG단가(W) * PKG용량(W)", "estimate.detail.header.showPrice": "가격표시", "estimate.detail.showPrice.btn1": "Pricing", - "estimate.detail.showPrice.description": "클릭하여 제품 특이사항 확인", + "estimate.detail.showPrice.description1": "제품 가격 OPEN", + "estimate.detail.showPrice.description2": "추가, 변경 자재", + "estimate.detail.showPrice.description3": "첨부필수", + "estimate.detail.showPrice.description4": "클릭하여 제품 특이사항 확인", "estimate.detail.showPrice.btn2": "제품추가", "estimate.detail.showPrice.btn3": "제품삭제" }