From 6ad8a0cb8a434084ed09921a34687c152faac524 Mon Sep 17 00:00:00 2001 From: Daseul Kim Date: Thu, 5 Dec 2024 10:59:28 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20usePlan=20=EB=82=B4=20api=20?= =?UTF-8?q?=ED=98=B8=EC=B6=9C=20=EA=B4=80=EB=A0=A8=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=EB=93=A4=20await=20=ED=82=A4=EC=9B=8C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/usePlan.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/hooks/usePlan.js b/src/hooks/usePlan.js index 7e76cac5..b12468b4 100644 --- a/src/hooks/usePlan.js +++ b/src/hooks/usePlan.js @@ -1,6 +1,6 @@ import { useEffect, useState } from 'react' import { useRecoilState } from 'recoil' -import { v4 as uuidv4, validate as isValidUUID } from 'uuid' +import { v4 as uuidv4 } from 'uuid' import { canvasState, currentCanvasPlanState, plansState, modifiedPlansState, modifiedPlanFlagState } from '@/store/canvasAtom' import { useAxios } from '@/hooks/useAxios' import { useMessage } from '@/hooks/useMessage' @@ -177,7 +177,7 @@ export function usePlan() { * objectNo에 해당하는 canvas 목록을 조회 */ const getCanvasByObjectNo = async (userId, objectNo) => { - return get({ url: `/api/canvas-management/canvas-statuses/by-object/${objectNo}/${userId}` }).then((res) => + return await get({ url: `/api/canvas-management/canvas-statuses/by-object/${objectNo}/${userId}` }).then((res) => res.map((item, index) => ({ id: item.id, userId: item.userId, @@ -234,15 +234,15 @@ export function usePlan() { /** * id에 해당하는 canvas 데이터를 삭제 */ - const delCanvasById = (id) => { - return promiseDel({ url: `/api/canvas-management/canvas-statuses/by-id/${id}` }) + const delCanvasById = async (id) => { + return await promiseDel({ url: `/api/canvas-management/canvas-statuses/by-id/${id}` }) } /** * objectNo에 해당하는 canvas 데이터들을 삭제 */ - const delCanvasByObjectNo = (objectNo) => { - return promiseDel({ url: `/api/canvas-management/canvas-statuses/by-object/${objectNo}` }) + const delCanvasByObjectNo = async (objectNo) => { + return await promiseDel({ url: `/api/canvas-management/canvas-statuses/by-object/${objectNo}` }) } /** @@ -279,19 +279,19 @@ export function usePlan() { * 새로운 plan 생성 * 현재 plan의 데이터가 있을 경우 복제 여부를 확인 */ - const handleAddPlan = (userId, objectNo) => { + const handleAddPlan = async (userId, objectNo) => { JSON.parse(currentCanvasData()).objects.length > 0 ? swalFire({ text: `Plan ${currentCanvasPlan.ordering} ` + getMessage('plan.message.confirm.copy'), type: 'confirm', - confirmFn: () => { - postCanvasStatus(userId, objectNo, currentCanvasData()) + confirmFn: async () => { + await postCanvasStatus(userId, objectNo, currentCanvasData()) }, - denyFn: () => { - postCanvasStatus(userId, objectNo, '') + denyFn: async () => { + await postCanvasStatus(userId, objectNo, '') }, }) - : postCanvasStatus(userId, objectNo, '') + : await postCanvasStatus(userId, objectNo, '') } /** @@ -314,10 +314,10 @@ export function usePlan() { /** * plan 삭제 */ - const handleDeletePlan = (e, id) => { + const handleDeletePlan = async (e, id) => { e.stopPropagation() // 이벤트 버블링 방지 - delCanvasById(id) + await delCanvasById(id) .then((res) => { setPlans((plans) => plans.filter((plan) => plan.id !== id)) setModifiedPlans((modifiedPlans) => modifiedPlans.filter((planId) => planId !== currentCanvasPlan.id)) @@ -340,8 +340,8 @@ export function usePlan() { /** * plan 조회 */ - const loadCanvasPlanData = (userId, objectNo, pid) => { - getCanvasByObjectNo(userId, objectNo).then((res) => { + const loadCanvasPlanData = async (userId, objectNo, pid) => { + await getCanvasByObjectNo(userId, objectNo).then((res) => { // console.log('canvas 목록 ', res) if (res.length > 0) { setPlans(res)