Skip to content

Commit

Permalink
예약 삭제 api 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
yeolyi committed Sep 18, 2023
1 parent 286ee41 commit 01ee99b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
12 changes: 9 additions & 3 deletions apis/reservation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import { cookies } from 'next/dist/client/components/headers';

import { Reservation, ReservationPostBody, ReservationPreview } from '@/types/reservation';

import { deleteRequest, getRequest, getRequestWithCookie, postRequestWithCookie } from '.';
import {
deleteRequest,
deleteRequestWithCookie,
getRequest,
getRequestWithCookie,
postRequestWithCookie,
} from '.';

const reservationPath = '/reservation';

Expand Down Expand Up @@ -32,11 +38,11 @@ export const getReservation = async (id: number) =>
getRequestWithCookie(`${reservationPath}/${id}`) as Promise<Reservation[]>;

export const deleteSingleReservation = async (id: number) => {
await deleteRequest(`${reservationPath}/${id}`);
await deleteRequestWithCookie(`${reservationPath}/${id}`);
};

export const deleteAllRecurringReservation = async (id: string) => {
await deleteRequest(`${reservationPath}/recurring/${id}`);
await deleteRequestWithCookie(`${reservationPath}/recurring/${id}`);
};

export const roomNameToId = {
Expand Down
23 changes: 16 additions & 7 deletions components/reservations/modals/ReservationDetailModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';

import { revalidatePath } from 'next/cache';
import { ButtonHTMLAttributes, DetailedHTMLProps, useState } from 'react';
import useSWR from 'swr';

Expand All @@ -17,7 +18,7 @@ import ModalFrame from '../../modal/ModalFrame';
import BasicButton from '../BasicButton';

export default function ReservationDetailModal({ reservationId }: { reservationId: number }) {
const { data: reservation } = useSWR<Reservation>(
const { data: reservation, mutate } = useSWR<Reservation>(
`/reservation/${reservationId}`,
getRequestWithCookie,
);
Expand Down Expand Up @@ -84,9 +85,9 @@ const DeleteButtons = ({
setSubmitting(true);
try {
await deleteAllRecurringReservation(recurrenceId);
closeModal();
} catch {
errorToast('문제가 발생했습니다');
window.location.reload();
} catch (e) {
toastError(e);
setSubmitting(false);
}
};
Expand All @@ -96,9 +97,9 @@ const DeleteButtons = ({
setSubmitting(true);
try {
await deleteSingleReservation(reservationId);
closeModal();
} catch {
errorToast('문제가 발생했습니다');
window.location.reload();
} catch (e) {
toastError(e);
setSubmitting(false);
}
};
Expand Down Expand Up @@ -132,3 +133,11 @@ export const ReservationDetailModalButton = ({
};

const padZero = (x: number) => (x + '').padStart(2, '0');

const toastError = (e: any) => {
if (e instanceof Error) {
errorToast(e.message);
} else {
errorToast('알 수 없는 문제가 발생했습니다.');
}
};

0 comments on commit 01ee99b

Please sign in to comment.