diff --git a/frontend/src/api-v2/guestReservation.ts b/frontend/src/api-v2/guestReservation.ts index fdb4cfb72..dd0dec603 100644 --- a/frontend/src/api-v2/guestReservation.ts +++ b/frontend/src/api-v2/guestReservation.ts @@ -1,4 +1,7 @@ import { AxiosResponse } from 'axios'; +import { QueryFunction, QueryKey } from 'react-query'; +import THROW_ERROR from 'constants/throwError'; +import { QueryGuestReservationsSuccessV2 } from 'types/response-v2'; import apiV2 from './apiv2'; interface DeleteGuestReservationParamsV2 { @@ -17,6 +20,15 @@ export interface GuestReservationParamsV2 { }; } +export interface QueryMapReservationsParamsV2 { + mapId: number; + date: string; +} + +export interface QuerySpaceReservationsParamsV2 extends QueryMapReservationsParamsV2 { + spaceId: number; +} + export interface PostGuestReservationParamsV2 extends GuestReservationParamsV2 { mapId: number; spaceId: number; @@ -28,6 +40,20 @@ interface PutGuestReservationParamsV2 extends GuestReservationParamsV2 { reservationId: number; } +export const queryGuestReservationsV2: QueryFunction< + AxiosResponse, + [QueryKey, QuerySpaceReservationsParamsV2] +> = ({ queryKey }) => { + const [, data] = queryKey; + const { mapId, spaceId, date } = data; + + if (!mapId) { + throw new Error(THROW_ERROR.INVALID_MAP_ID); + } + + return apiV2.get(`/api/maps/${mapId}/spaces/${spaceId}/reservations?date=${date}`); +}; + export const postGuestReservationV2 = ({ reservation, mapId, diff --git a/frontend/src/hooks/query-v2/useGuestReservationsV2.ts b/frontend/src/hooks/query-v2/useGuestReservationsV2.ts new file mode 100644 index 000000000..516bcc795 --- /dev/null +++ b/frontend/src/hooks/query-v2/useGuestReservationsV2.ts @@ -0,0 +1,18 @@ +import { AxiosError, AxiosResponse } from 'axios'; +import { QueryKey, useQuery, UseQueryOptions, UseQueryResult } from 'react-query'; +import { QuerySpaceReservationsParamsV2, queryGuestReservationsV2 } from 'api-v2/guestReservation'; +import { ErrorResponse } from 'types/response'; +import { QueryGuestReservationsSuccessV2 } from 'types/response-v2'; + +const useGuestReservationsV2 = >( + { mapId, spaceId, date }: QuerySpaceReservationsParamsV2, + options?: UseQueryOptions< + AxiosResponse, + AxiosError, + TData, + [QueryKey, QuerySpaceReservationsParamsV2] + > +): UseQueryResult> => + useQuery(['getGuestReservations', { mapId, spaceId, date }], queryGuestReservationsV2, options); + +export default useGuestReservationsV2; diff --git a/frontend/src/hooks/query-v2/useManagerMapReservationsV2.ts b/frontend/src/hooks/query-v2/useManagerMapReservationsV2.ts index dc5fbad34..cbc5a6f4d 100644 --- a/frontend/src/hooks/query-v2/useManagerMapReservationsV2.ts +++ b/frontend/src/hooks/query-v2/useManagerMapReservationsV2.ts @@ -16,6 +16,10 @@ const useManagerMapReservationsV2 = ): UseQueryResult> => - useQuery(['getManagerMapReservations', { mapId, date }], queryManagerMapReservationsV2, options); + useQuery( + ['getManagerMapReservationsV2', { mapId, date }], + queryManagerMapReservationsV2, + options + ); export default useManagerMapReservationsV2; diff --git a/frontend/src/pages/GuestMap/units/ReservationList.tsx b/frontend/src/pages/GuestMap/units/ReservationList.tsx index 591e34fad..8a0a0b3fe 100644 --- a/frontend/src/pages/GuestMap/units/ReservationList.tsx +++ b/frontend/src/pages/GuestMap/units/ReservationList.tsx @@ -9,6 +9,7 @@ import Input from 'components/Input/Input'; import ManagerReservationListItem from 'components/ManagerReservationListItem/ManagerReservationListItem'; import Select from 'components/Select/Select'; import DATE from 'constants/date'; +import useGuestReservationsV2 from 'hooks/query-v2/useGuestReservationsV2'; import useGuestReservations from 'hooks/query/useGuestReservations'; import useGuestSpace from 'hooks/query/useGuestSpace'; import { AccessTokenContext } from 'providers/AccessTokenProvider'; @@ -41,7 +42,7 @@ const ReservationList = ({ data: reservations, isLoadingError, isSuccess, - } = useGuestReservations( + } = useGuestReservationsV2( { mapId: mapId, spaceId: +selectedSpaceId, diff --git a/frontend/src/types/response-v2.ts b/frontend/src/types/response-v2.ts index c1654aeda..66aacd8e6 100644 --- a/frontend/src/types/response-v2.ts +++ b/frontend/src/types/response-v2.ts @@ -1,4 +1,4 @@ -import { MapItem, SpaceReservation } from './common'; +import { MapItem, Reservation, SpaceReservation } from './common'; export interface MapItemResponseV2 extends Omit { @@ -16,3 +16,7 @@ export type QueryManagerMapSuccessV2 = MapItemResponseV2; export interface QueryManagerMapReservationsSuccessV2 { data: SpaceReservation[]; } + +export interface QueryGuestReservationsSuccessV2 { + reservations: Reservation[]; +}