Skip to content

Commit

Permalink
Move logic for display MaterialButtonReservableFromAnotherLibrary
Browse files Browse the repository at this point in the history
If the material only can be reserved on another library, we don't want to show other buttons like `MaterialButtonFindOnShelf`
  • Loading branch information
kasperbirch1 committed Nov 13, 2023
1 parent 0d8c510 commit 821f23b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
21 changes: 20 additions & 1 deletion src/components/material/material-buttons/MaterialButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import * as React from "react";
import { FC } from "react";
import { AccessTypeCode } from "../../../core/dbc-gateway/generated/graphql";
import { getAllFaustIds } from "../../../core/utils/helpers/general";
import {
getAllFaustIds,
getManifestationType,
getReservablePidsFromAnotherLibrary
} from "../../../core/utils/helpers/general";
import { ButtonSize } from "../../../core/utils/types/button";
import { Manifestation } from "../../../core/utils/types/entities";
import { hasCorrectAccess, hasCorrectAccessType, isArticle } from "./helper";
import { WorkId } from "../../../core/utils/types/ids";
import MaterialButtonsOnline from "./online/MaterialButtonsOnline";
import MaterialButtonsFindOnShelf from "./physical/MaterialButtonsFindOnShelf";
import MaterialButtonsPhysical from "./physical/MaterialButtonsPhysical";
import MaterialButtonReservableFromAnotherLibrary from "./physical/MaterialButtonReservableFromAnotherLibrary";

export interface MaterialButtonsProps {
manifestations: Manifestation[];
Expand All @@ -29,6 +34,20 @@ const MaterialButtons: FC<MaterialButtonsProps> = ({
// We don't want to show physical buttons/find on shelf for articles because
// articles appear as a part of journal/periodical publications and can't be
// physically loaned for themseleves.

const isReservableFromAnotherLibrary =
getReservablePidsFromAnotherLibrary(manifestations).length > 0;

if (isReservableFromAnotherLibrary) {
return (
<MaterialButtonReservableFromAnotherLibrary
size={size}
manifestationMaterialType={getManifestationType(manifestations)}
faustIds={faustIds}
/>
);
}

return (
<>
{hasCorrectAccessType(AccessTypeCode.Physical, manifestations) &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from "react";
import {
getAllFaustIds,
getManifestationType,
getReservablePidsFromAnotherLibrary
getManifestationType
} from "../../../../core/utils/helpers/general";
import { isBlocked, usePatronData } from "../../../../core/utils/helpers/user";
import { ButtonSize } from "../../../../core/utils/types/button";
Expand All @@ -13,7 +12,6 @@ import MaterialButtonReservePhysical from "./MaterialButtonPhysical";
import MaterialButtonLoading from "../generic/MaterialButtonLoading";
import MaterialButtonDisabled from "../generic/MaterialButtonDisabled";
import { useText } from "../../../../core/utils/text";
import MaterialButtonReservableFromAnotherLibrary from "./MaterialButtonReservableFromAnotherLibrary";

export interface MaterialButtonsPhysicalProps {
manifestations: Manifestation[];
Expand All @@ -26,8 +24,6 @@ const MaterialButtonsPhysical: React.FC<MaterialButtonsPhysicalProps> = ({
size,
dataCy = "material-buttons-physical"
}) => {
const isReservableFromAnotherLibrary =
getReservablePidsFromAnotherLibrary(manifestations);
const t = useText();
const faustIds = getAllFaustIds(manifestations);
const { reservableManifestations } = UseReservableManifestations({
Expand All @@ -48,16 +44,6 @@ const MaterialButtonsPhysical: React.FC<MaterialButtonsPhysicalProps> = ({
return <MaterialButtonUserBlocked size={size} dataCy={dataCy} />;
}

if (isReservableFromAnotherLibrary.length > 0) {
return (
<MaterialButtonReservableFromAnotherLibrary
size={size}
manifestationMaterialType={getManifestationType(manifestations)}
faustIds={faustIds}
/>
);
}

// We show the reservation button if the user isn't logged in or isn't blocked.
// In the former case there there's no way to see if they're blocked, so we
// redirect anonymous user to the login page.
Expand Down

0 comments on commit 821f23b

Please sign in to comment.