From 4edef1c87d871c6d4bba68b50eb313c01c4e5840 Mon Sep 17 00:00:00 2001 From: Daseul Kim Date: Mon, 20 Jan 2025 11:18:54 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20plan=20=EC=B4=88=EA=B8=B0=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EC=8B=9C=20=EC=9D=B4=EC=A0=84=20=EB=AC=BC=EA=B1=B4?= =?UTF-8?q?=20=20plan=EC=9D=B4=20=EA=B0=99=EC=9D=B4=20=EB=B3=B4=EC=9D=B4?= =?UTF-8?q?=EB=8A=94=20=ED=98=84=EC=83=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/usePlan.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/hooks/usePlan.js b/src/hooks/usePlan.js index 510b7874..6a25fd50 100644 --- a/src/hooks/usePlan.js +++ b/src/hooks/usePlan.js @@ -14,6 +14,7 @@ import { SAVE_KEY } from '@/common/common' import { readImage, removeImage } from '@/lib/fileAction' import { FloorPlanContext } from '@/app/floor-plan/FloorPlanProvider' import { useEstimateController } from '@/hooks/floorPlan/estimate/useEstimateController' + export function usePlan(params = {}) { const { floorPlanState } = useContext(FloorPlanContext) @@ -159,7 +160,7 @@ export function usePlan(params = {}) { /** * 신규 canvas 데이터를 저장 */ - const postCanvasStatus = async (userId, objectNo, canvasStatus) => { + const postCanvasStatus = async (userId, objectNo, canvasStatus, isInitPlan = false) => { const planNo = await postObjectPlan(userId, objectNo) if (!planNo) return @@ -173,7 +174,12 @@ export function usePlan(params = {}) { } await promisePost({ url: '/api/canvas-management/canvas-statuses', data: planData }) .then((res) => { - setPlans((plans) => [...plans, { id: res.data, objectNo: objectNo, planNo: planNo, userId: userId, canvasStatus: canvasStatus }]) + if (isInitPlan) { + // 초기 플랜 생성인 경우 플랜 목록 초기화 + setPlans([{ id: res.data, objectNo: objectNo, planNo: planNo, userId: userId, canvasStatus: canvasStatus }]) + } else { + setPlans((plans) => [...plans, { id: res.data, objectNo: objectNo, planNo: planNo, userId: userId, canvasStatus: canvasStatus }]) + } updateCurrentPlan(res.data) }) .catch((error) => { @@ -313,13 +319,13 @@ export function usePlan(params = {}) { text: `Plan ${currentCanvasPlan.planNo} ` + getMessage('plan.message.confirm.copy'), type: 'confirm', confirmFn: async () => { - await postCanvasStatus(userId, objectNo, currentCanvasData()) + await postCanvasStatus(userId, objectNo, currentCanvasData(), false) }, denyFn: async () => { - await postCanvasStatus(userId, objectNo, '') + await postCanvasStatus(userId, objectNo, '', false) }, }) - : await postCanvasStatus(userId, objectNo, '') + : await postCanvasStatus(userId, objectNo, '', false) } /** @@ -373,7 +379,7 @@ export function usePlan(params = {}) { setPlans(res) updateCurrentPlan(res.find((plan) => plan.planNo === planNo).id) } else { - postCanvasStatus(userId, objectNo, '') + postCanvasStatus(userId, objectNo, '', true) } }) }