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,