Skip to content

Commit

Permalink
UI 로직 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
GwangjoGong committed Nov 30, 2021
1 parent 68a46f1 commit bce22eb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
50 changes: 38 additions & 12 deletions src/pages/ReservationConfirm/ReservationConfirmContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { useHistory } from 'react-router-dom';

import {
useCancelReservationMutation,
Expand All @@ -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 (
Expand Down
19 changes: 2 additions & 17 deletions src/pages/ReservationConfirm/ReservationConfirmPresenter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,12 @@ export const ReservationConfirmPresenter: React.FC<ReservationConfirmPresenterPr

const onPressConfirm = async () => {
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 ? (
Expand Down

0 comments on commit bce22eb

Please sign in to comment.