From d4f055ebdbd2423cd326a2e52d65d2a50779fdea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Garn=C3=A6s?= Date: Mon, 23 Oct 2023 09:53:51 +0200 Subject: [PATCH] Use grouped reservations in menu --- .../menu-logged-in/MenuLoggedInContent.tsx | 13 +++---- src/core/utils/helpers/list-mapper.ts | 36 ++++++++++++++++++- src/core/utils/types/list-type.ts | 7 ++++ 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/apps/menu/menu-logged-in/MenuLoggedInContent.tsx b/src/apps/menu/menu-logged-in/MenuLoggedInContent.tsx index 927aee48ae..7383f036e0 100644 --- a/src/apps/menu/menu-logged-in/MenuLoggedInContent.tsx +++ b/src/apps/menu/menu-logged-in/MenuLoggedInContent.tsx @@ -6,14 +6,10 @@ import MenuNavigationItem, { } from "../menu-navigation-list/MenuNavigationItem"; import { AuthenticatedPatronV6 } from "../../../core/fbs/model"; import { useUrls } from "../../../core/utils/url"; -import { - useGetLoansV2, - useGetReservationsV2, - useGetFeesV2 -} from "../../../core/fbs/fbs"; +import { useGetLoansV2, useGetFeesV2 } from "../../../core/fbs/fbs"; import { mapFBSLoanToLoanType, - mapFBSReservationToReservationType + mapFBSReservationGroupToReservationType } from "../../../core/utils/helpers/list-mapper"; import { LoanType } from "../../../core/utils/types/loan-type"; import { @@ -27,6 +23,7 @@ import { usePatronData } from "../../../components/material/helper"; import { getReadyForPickup } from "../../reservation-list/utils/helpers"; import { ReservationType } from "../../../core/utils/types/reservation-type"; import DashboardNotificationList from "../../dashboard/dashboard-notification-list/dashboard-notification-list"; +import useGetReservationGroups from "../../../core/utils/useGetReservationGroups"; interface MenuLoggedInContentProps { pageSize: number; @@ -34,7 +31,7 @@ interface MenuLoggedInContentProps { const MenuLoggedInContent: FC = ({ pageSize }) => { const { data: patronData } = usePatronData(); - const { data: patronReservations } = useGetReservationsV2(); + const { reservations: patronReservations } = useGetReservationGroups(); const { data: fbsData } = useGetLoansV2(); const { data: fbsFees } = useGetFeesV2(); const t = useText(); @@ -95,7 +92,7 @@ const MenuLoggedInContent: FC = ({ pageSize }) => { useEffect(() => { if (patronReservations) { const mappedReservations = - mapFBSReservationToReservationType(patronReservations); + mapFBSReservationGroupToReservationType(patronReservations); setReservations(mappedReservations); setReservationsReadyForPickup( getReadyForPickup(mappedReservations).length diff --git a/src/core/utils/helpers/list-mapper.ts b/src/core/utils/helpers/list-mapper.ts index 0e82f7537b..7e3aae2053 100644 --- a/src/core/utils/helpers/list-mapper.ts +++ b/src/core/utils/helpers/list-mapper.ts @@ -1,3 +1,4 @@ +import { head, keys, values } from "lodash"; import { LoanV2, ReservationDetailsV2 } from "../../fbs/model"; import { FaustId } from "../types/ids"; import { GetManifestationViaMaterialByFaustQuery } from "../../dbc-gateway/generated/graphql"; @@ -7,6 +8,7 @@ import { LoanType } from "../types/loan-type"; import { store } from "../../store"; import { ReservationType } from "../types/reservation-type"; import { getContributors } from "./general"; +import { ReservationGroupDetails } from "../useGetReservationGroups"; function getYearFromDataString(date: string) { return new Date(date).getFullYear(); @@ -226,7 +228,39 @@ export const mapFBSReservationToReservationType = ( pickupBranch, pickupDeadline, pickupNumber, - reservationId + reservationId, + reservationIds: [reservationId] + }; + } + ); +}; + +export const mapFBSReservationGroupToReservationType = ( + list: ReservationGroupDetails[] +): ReservationType[] => { + return list.map( + ({ + dateOfReservation, + expiryDate, + numberInQueue, + state, + pickupBranch, + pickupDeadline, + pickupNumber, + periodical, + records + }) => { + return { + periodical: periodical?.displayText || "", + faust: head(keys(records)) as FaustId, + dateOfReservation, + expiryDate, + numberInQueue, + state: state === "readyForPickup" ? "readyForPickup" : "reserved", + pickupBranch, + pickupDeadline, + pickupNumber, + reservationIds: values(records) }; } ); diff --git a/src/core/utils/types/list-type.ts b/src/core/utils/types/list-type.ts index e5258d37a5..50d3b337ab 100644 --- a/src/core/utils/types/list-type.ts +++ b/src/core/utils/types/list-type.ts @@ -4,7 +4,14 @@ import { Nullable } from "./nullable"; export type ListIdsType = { faust: FaustId; identifier: string; + /** + * @deprecated Use reservationIds instead. + * + * This will be removed in the future when we have migrated to the new + * reservationId property which supports grouped / parallel reservations. + */ reservationId: number; + reservationIds: number[]; loanId: LoanId | null; };