Skip to content

Commit

Permalink
Remove use of useLoans and useReservations in useReaderPlayer
Browse files Browse the repository at this point in the history
The use of `useLoans` and `useReservations` caused unexpected behavior, where the FBS API was called, leading to Cypress test failures. I was unable to get `enabled: !isUserAnonymous` to work properly with the FBS API. However, I believe it is also preferable to call Publizon directly from `useReaderPlayer`, as FBS materials are not relevant in this context.

Before this change, I temporarily fixed the Cypress test by adding fixtures for:

`cy.intercept("GET", "**/external/agencyid/patrons/patronid/loans/v2", {`inside src/components/reservation/reservation.test.ts.
  • Loading branch information
kasperbirch1 committed Jan 28, 2025
1 parent 7b8d14b commit ad4428a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/apps/material/material.entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ interface MaterialEntryConfigProps {
blacklistedInstantLoanBranchesConfig: string;
blacklistedPickupBranchesConfig?: string;
branchesConfig: string;
expirationWarningDaysBeforeConfig: string;
instantLoanConfig: string;
smsNotificationsForReservationsEnabledConfig: string;
}
Expand Down
5 changes: 0 additions & 5 deletions src/apps/material/material.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -664,10 +664,6 @@ const meta: Meta<typeof MaterialEntry> = {
description: "Instant loan underline description",
control: { type: "text" }
},
expirationWarningDaysBeforeConfig: {
description: "Expiration warning days before",
control: { type: "text" }
},
instantLoanConfig: {
description: "Instant loan config",
control: { type: "text" }
Expand Down Expand Up @@ -954,7 +950,6 @@ const meta: Meta<typeof MaterialEntry> = {
instantLoanSubTitleText: "Spring køen over og hent bogen nu på",
instantLoanUnderlineDescriptionText:
"Bogen er tilgængelig på disse biblioteker nær dig",
expirationWarningDaysBeforeConfig: "1",
instantLoanConfig:
'{ "threshold": "1", "matchStrings": ["Standard"], "enabled": "true" }',
interestPeriodsConfig:
Expand Down
34 changes: 24 additions & 10 deletions src/core/utils/useReaderPlayer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import useLoans from "./useLoans";
import useReservations from "./useReservations";
import { Manifestation } from "./types/entities";
import { getManifestationIsbn } from "../../apps/material/helper";
import {
Expand All @@ -10,6 +8,14 @@ import {
import { isAnonymous } from "./helpers/user";
import useOnlineAvailabilityData from "../../components/availability-label/useOnlineAvailabilityData";
import { hasCorrectAccess } from "../../components/material/material-buttons/helper";
import {
useGetV1UserLoans,
useGetV1UserReservations
} from "../publizon/publizon";
import {
mapPublizonLoanToLoanType,
mapPublizonReservationToReservationType
} from "./helpers/list-mapper";

const useReaderPlayer = (manifestations: Manifestation[] | null) => {
const isUserAnonymous = isAnonymous();
Expand All @@ -23,13 +29,19 @@ const useReaderPlayer = (manifestations: Manifestation[] | null) => {
? getManifestationIsbn(manifestations[0])
: null;

const {
publizon: { loans }
} = useLoans();

const {
publizon: { reservations }
} = useReservations();
const { data: loansPublizon } = useGetV1UserLoans(
{},
{ query: { enabled: !isUserAnonymous } }
);
const loans = loansPublizon?.loans
? mapPublizonLoanToLoanType(loansPublizon.loans)
: null;
const { data: reservationsPublizon } = useGetV1UserReservations({
query: { enabled: !isUserAnonymous }
});
const reservations = reservationsPublizon?.reservations
? mapPublizonReservationToReservationType(reservationsPublizon.reservations)
: null;

const availabilityData = useOnlineAvailabilityData({
enabled: !!identifier,
Expand All @@ -46,7 +58,9 @@ const useReaderPlayer = (manifestations: Manifestation[] | null) => {
loans && identifier ? getOrderIdByIdentifier({ loans, identifier }) : null;

const isAllReadyReservedButtonVisible =
identifier && isIdentifierReserved(identifier, reservations);
identifier && reservations
? isIdentifierReserved(identifier, reservations)
: false;
const isMaterialLoanedButtonVisible = !!orderId;
const isLoanButtonVisible = isUserAnonymous || isAvailable;
const isReserveButtonVisible = !isAvailable;
Expand Down

0 comments on commit ad4428a

Please sign in to comment.