Skip to content

Commit

Permalink
Fix: 객실 모두 삭제되는 에러 해결 (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
gahyuun authored Jan 28, 2024
1 parent fb1e2f4 commit 230d4f1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/constants/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
14 changes: 10 additions & 4 deletions src/pages/room-management/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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('요청에 실패했습니다 잠시 후 다시 시도해주세요');
},
});
},
Expand Down
6 changes: 3 additions & 3 deletions src/queries/room/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -63,13 +63,13 @@ export const useDeleteRoom = (
accommodationId: string,
options?: UseMutationOptions<
AxiosResponse<Response<RoomDeleteResponseData>>,
AxiosError,
AxiosError<ErrorResponse>,
number
>,
) => {
return useMutation<
AxiosResponse<Response<RoomDeleteResponseData>>,
AxiosError,
AxiosError<ErrorResponse>,
number
>((roomId) => ROOM_API.deleteRoom(roomId, accommodationId), {
...options,
Expand Down

0 comments on commit 230d4f1

Please sign in to comment.