From bce22eb290caeea63a41b485ce99fac639eeda55 Mon Sep 17 00:00:00 2001 From: GwangjoGong Date: Wed, 1 Dec 2021 02:14:07 +0900 Subject: [PATCH] =?UTF-8?q?UI=20=EB=A1=9C=EC=A7=81=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReservationConfirmContainer.tsx | 50 ++++++++++++++----- .../ReservationConfirmPresenter.tsx | 19 +------ 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/pages/ReservationConfirm/ReservationConfirmContainer.tsx b/src/pages/ReservationConfirm/ReservationConfirmContainer.tsx index 6b1ac96..bf26373 100644 --- a/src/pages/ReservationConfirm/ReservationConfirmContainer.tsx +++ b/src/pages/ReservationConfirm/ReservationConfirmContainer.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import { useHistory } from 'react-router-dom'; import { useCancelReservationMutation, @@ -7,29 +8,54 @@ import { import { ReservationConfirmPresenter } from './ReservationConfirmPresenter'; export const ReservationConfirmContainer: React.FC = () => { + const history = useHistory(); + const [reserveSeatMutation, { loading: reserveLoading }] = useReserveSeatMutation(); const [cancelReservationMutation, { loading: cancelLoading }] = useCancelReservationMutation(); const reserveSeat = async (reservationId: string) => { - await reserveSeatMutation({ - variables: { - input: { - reservationId, + try { + const { data } = await reserveSeatMutation({ + variables: { + input: { + reservationId, + }, }, - }, - }); + }); + + if (data?.reserveSeat.ok) { + window.alert('예약이 확정되었습니다.'); + history.push('/reservations'); + } else if (data?.reserveSeat.error) { + window.alert(data.reserveSeat.error); + history.push('/reservation'); + } + } catch (err) { + window.alert(err); + } }; const cancelReservation = async (reservationId: string) => { - await cancelReservationMutation({ - variables: { - input: { - reservationId, + try { + const { data } = await cancelReservationMutation({ + variables: { + input: { + reservationId, + }, }, - }, - }); + }); + if (data?.cancelReservation.ok) { + window.alert('예약이 취소되었습니다.'); + history.push('/reservation'); + } else if (data?.cancelReservation.error) { + window.alert(data?.cancelReservation.error); + history.push('/reservation'); + } + } catch (err) { + window.alert(err); + } }; return ( diff --git a/src/pages/ReservationConfirm/ReservationConfirmPresenter.tsx b/src/pages/ReservationConfirm/ReservationConfirmPresenter.tsx index 274cfe0..ce95304 100644 --- a/src/pages/ReservationConfirm/ReservationConfirmPresenter.tsx +++ b/src/pages/ReservationConfirm/ReservationConfirmPresenter.tsx @@ -64,27 +64,12 @@ export const ReservationConfirmPresenter: React.FC { if (reserveLoading) return; - - try { - await reserveSeat(id); - window.alert('예약이 확정되었습니다.'); - history.push('/reservations'); - } catch (err) { - window.alert(err); - history.push('/reservation'); - } + await reserveSeat(id); }; const onPressCancel = async () => { if (cancelLoading) return; - - try { - await cancelReservation(id); - window.alert('예약이 취소되었습니다.'); - history.push('/reservation'); - } catch (err) { - window.alert(err); - } + await cancelReservation(id); }; return loading ? (