Skip to content

Commit

Permalink
Use grouped reservations in menu
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperg committed Oct 23, 2023
1 parent 84213f4 commit d4f055e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
13 changes: 5 additions & 8 deletions src/apps/menu/menu-logged-in/MenuLoggedInContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -27,14 +23,15 @@ 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;
}

const MenuLoggedInContent: FC<MenuLoggedInContentProps> = ({ pageSize }) => {
const { data: patronData } = usePatronData();
const { data: patronReservations } = useGetReservationsV2();
const { reservations: patronReservations } = useGetReservationGroups();
const { data: fbsData } = useGetLoansV2();
const { data: fbsFees } = useGetFeesV2();
const t = useText();
Expand Down Expand Up @@ -95,7 +92,7 @@ const MenuLoggedInContent: FC<MenuLoggedInContentProps> = ({ pageSize }) => {
useEffect(() => {
if (patronReservations) {
const mappedReservations =
mapFBSReservationToReservationType(patronReservations);
mapFBSReservationGroupToReservationType(patronReservations);
setReservations(mappedReservations);
setReservationsReadyForPickup(
getReadyForPickup(mappedReservations).length
Expand Down
36 changes: 35 additions & 1 deletion src/core/utils/helpers/list-mapper.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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();
Expand Down Expand Up @@ -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)
};
}
);
Expand Down
7 changes: 7 additions & 0 deletions src/core/utils/types/list-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down

0 comments on commit d4f055e

Please sign in to comment.