Skip to content

Commit

Permalink
refactor: 예약 완료시 모달 창 끄기
Browse files Browse the repository at this point in the history
  • Loading branch information
chaeseungyun committed Apr 8, 2024
1 parent 1a158d1 commit c9d481e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/api/reservations/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { accessClient } from 'api';
import { GetReservationsResponse, Reservations, PostReservationRequest } from 'model/reservations';
import { GetReservationsResponse, Reservations } from 'model/reservations';

export const getReservations = () => accessClient.get<GetReservationsResponse[]>('/reservations');

export const postReservations = (data: PostReservationRequest) => accessClient.post('/reservations', data);
export const postReservations = (data: Reservations) => accessClient.post('/reservations', data);

export const deleteReservations = (id: number) => accessClient.delete(`/reservations/${id}`);

Expand Down
4 changes: 2 additions & 2 deletions src/model/reservations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ export interface Reservations {
detailedReason: string;
startDateTime: string;
endDateTime: string;
memberName: string;
}

export interface GetReservationsResponse extends Reservations {
id: number;
memberName: string;
}

export interface PostReservationRequest {
export interface Reservation {
memberCount: number;
reason: string;
detailedReason: string;
startDateTime: string;
endDateTime: string;
memberName: string;
}
4 changes: 2 additions & 2 deletions src/page/Reservation/view/Month.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
} from '@mui/material';
import { ArrowBackIosNewOutlined, ArrowForwardIosOutlined } from '@mui/icons-material';
import { useGetReservations } from 'query/reservations';
import { Reservations } from 'model/reservations';
import { Reservation } from 'model/reservations';
import { useEffect, useState } from 'react';
import * as S from './style';
// eslint-disable-next-line import/no-cycle
Expand All @@ -19,7 +19,7 @@ type Calendar = {
type Calendars = Calendar[];

export type CalendarContent = {
data: Reservations[],
data: Reservation[],
date: number | null,
today: string | null,
currentMonth: number,
Expand Down
1 change: 1 addition & 0 deletions src/page/Reservation/view/Month/DetailInfomation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface DetailInfomationProps extends Reservations {
id?: number;
// eslint-disable-next-line
passed?: boolean;
memberName: string;
}

export default function DetailInfomation({
Expand Down
23 changes: 15 additions & 8 deletions src/page/Reservation/view/Month/MonthModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function MonthModal({
}: ModalContent) {
const currentDate = new Date().getDate();
const nowMonth = new Date().getMonth();
const { mutate: reservation } = useCreateReservations();
const { mutate: reservation, isError } = useCreateReservations();
const [reserve, setReserve] = useState(initialState);
const { alignment, handleChange } = useToggleButtonGroup();
const canReserve = () => {
Expand Down Expand Up @@ -194,13 +194,20 @@ export default function MonthModal({
</div>
<Button
variant="outlined"
onClick={() => today && reserve.memberCount >= 1 && reservation({
memberCount: reserve.memberCount,
reason: reserve.reason,
detailedReason: reserve.detailedReason,
startDateTime: `${today.slice(0, 4)}-${today.slice(5, 7)}-${today.slice(8, 10)} ${reserve.startHour}:${reserve.startMinute}`,
endDateTime: `${today.slice(0, 4)}-${today.slice(5, 7)}-${today.slice(8, 10)} ${reserve.endHour}:${reserve.endMinute}`,
})}
onClick={() => {
if (today
&& reserve.memberCount >= 1
) {
reservation({
memberCount: reserve.memberCount,
reason: reserve.reason,
detailedReason: reserve.detailedReason,
startDateTime: `${today.slice(0, 4)}-${today.slice(5, 7)}-${today.slice(8, 10)} ${reserve.startHour}:${reserve.startMinute}`,
endDateTime: `${today.slice(0, 4)}-${today.slice(5, 7)}-${today.slice(8, 10)} ${reserve.endHour}:${reserve.endMinute}`,
});
if (!isError) handleClose();
}
}}
>
예약
</Button>
Expand Down
8 changes: 4 additions & 4 deletions src/query/reservations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
deleteReservations, getReservations, postReservations, putReservations, myReservation,
} from 'api/reservations';
import { AxiosError } from 'axios';
import { PostReservationRequest, Reservations } from 'model/reservations';
import { Reservations } from 'model/reservations';
import { useSnackBar } from 'ts/useSnackBar';

interface PutReservations {
Expand All @@ -23,9 +23,9 @@ export const useCreateReservations = () => {
const openSnackBar = useSnackBar();
const queryClient = useQueryClient();

const { mutate, isSuccess } = useMutation({
const { mutate, isSuccess, isError } = useMutation({
mutationKey: ['postReservations'],
mutationFn: (data: PostReservationRequest) => postReservations(data),
mutationFn: (data: Reservations) => postReservations(data),
onSuccess: () => {
openSnackBar({ type: 'success', message: '예약이 완료되었습니다.' });
queryClient.invalidateQueries({ queryKey: ['reservations'] });
Expand All @@ -37,7 +37,7 @@ export const useCreateReservations = () => {
}
},
});
return { mutate, isSuccess };
return { mutate, isSuccess, isError };
};

export const useDeleteReservations = () => {
Expand Down

0 comments on commit c9d481e

Please sign in to comment.