From 230d4f19ea6143614f1c138c40e986972dc671f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EA=B0=80=ED=98=84?= <81469686+gahyuun@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:16:13 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=EA=B0=9D=EC=8B=A4=20=EB=AA=A8=EB=91=90?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C=EB=90=98=EB=8A=94=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0=20(#234)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/api/index.ts | 1 + src/pages/room-management/index.tsx | 14 ++++++++++---- src/queries/room/index.ts | 6 +++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/constants/api/index.ts b/src/constants/api/index.ts index 5ae78631..e796c048 100644 --- a/src/constants/api/index.ts +++ b/src/constants/api/index.ts @@ -52,4 +52,5 @@ export const RESPONSE_CODE = { EMPTY_ACCOMMODATION_IMAGES: 2003, EMPTY_ROOM_IMAGES: 3007, EMPTY_ROOM_INFO: 3006, + LAST_ROOM_DELETE: 3008, } as const; diff --git a/src/pages/room-management/index.tsx b/src/pages/room-management/index.tsx index b7f8c4c2..400f3237 100644 --- a/src/pages/room-management/index.tsx +++ b/src/pages/room-management/index.tsx @@ -4,9 +4,9 @@ import { TextBox } from '@components/text-box'; import styled from 'styled-components'; import { useNavigate, useParams } from 'react-router-dom'; import { useDeleteRoom, useGetInfiniteRoomList } from '@queries/room'; -import { AxiosError } from 'axios'; import InfiniteScroll from 'react-infinite-scroll-component'; import { useEffect, useMemo } from 'react'; +import { RESPONSE_CODE } from '@/constants/api'; const RoomManagement = () => { const navigate = useNavigate(); @@ -50,14 +50,20 @@ const RoomManagement = () => { okText: '삭제', className: 'confirm-modal', onOk: () => { + if (roomItems?.length === 1) { + message.error('숙소당 최소 하나의 객실이 필요합니다'); + return; + } deleteRoom(roomId, { onSuccess: () => { message.success('삭제되었습니다'); refetch(); }, - onError: (error: unknown) => { - if (error instanceof AxiosError) - message.error('요청에 실패했습니다 잠시 후 다시 시도해주세요'); + onError: (error) => { + if (error.response?.data.code === RESPONSE_CODE.LAST_ROOM_DELETE) { + message.error('숙소당 최소 하나의 객실이 필요합니다'); + } + message.error('요청에 실패했습니다 잠시 후 다시 시도해주세요'); }, }); }, diff --git a/src/queries/room/index.ts b/src/queries/room/index.ts index f17db1c3..844e32f3 100644 --- a/src/queries/room/index.ts +++ b/src/queries/room/index.ts @@ -7,7 +7,7 @@ import { UseInfiniteQueryOptions, useInfiniteQuery, } from '@tanstack/react-query'; -import { Response } from '@/types/api'; +import { ErrorResponse, Response } from '@/types/api'; import { RoomData, RoomPostResponseData, @@ -63,13 +63,13 @@ export const useDeleteRoom = ( accommodationId: string, options?: UseMutationOptions< AxiosResponse>, - AxiosError, + AxiosError, number >, ) => { return useMutation< AxiosResponse>, - AxiosError, + AxiosError, number >((roomId) => ROOM_API.deleteRoom(roomId, accommodationId), { ...options,