Skip to content

Commit

Permalink
Merge pull request #854 from danskernesdigitalebibliotek/fix-overbygn…
Browse files Browse the repository at this point in the history
…ingsmateriale-2024

Change the 'Reserve' button text to the standard and move the notice about material ordered from other libraries to the `MaterialAvailabilityTextParagraph`.
  • Loading branch information
kasperbirch1 authored Apr 16, 2024
2 parents 636826a + f854c63 commit bdfe2b9
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 33 deletions.
6 changes: 3 additions & 3 deletions cypress/fixtures/material/open-order/open-order-accepted.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"data": {
"submitOrder": {
"status": "OWNED_ACCEPTED",
"message": "Item available at pickupAgency, order accepted",
"orderId": "1234"
"status": "NOT_OWNED_ILL_LOC",
"message": "Item not available at pickupAgency, item localised for ILL",
"orderId": "1048265231"
}
}
}
9 changes: 7 additions & 2 deletions src/apps/material/material.dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,14 @@ export default {
defaultValue: "Reserve",
control: { type: "text" }
},
reserveWithMaterialTypeText: {
name: "Reserve",
defaultValue: "Reserve @materialType",
control: { type: "text" }
},
reservableFromAnotherLibraryText: {
name: "Reservable on another library",
defaultValue: "Reservable on another library",
defaultValue: "Ordered from another library.",
control: { type: "text" }
},
findOnBookshelfText: {
Expand Down Expand Up @@ -769,7 +774,7 @@ export default {
},
openOrderNotOwnedIllLocText: {
name: "Open order item localized for ILL text",
defaultValue: "Item not available at pickup agency but localized for ILL",
defaultValue: "Your material has been ordered from another library",
control: { type: "text" }
},
openOrderNotOwnedNoIllLocText: {
Expand Down
1 change: 1 addition & 0 deletions src/apps/material/material.entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ interface MaterialEntryTextProps {
reservationSuccesTitleText: string;
reserveBookText: string;
reserveText: string;
reserveWithMaterialTypeText: string;
reviewsText: string;
saveButtonText: string;
seeOnlineText: string;
Expand Down
4 changes: 2 additions & 2 deletions src/apps/material/open-order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const navigateToMaterial = () => {
cy.getBySel("material-button-reservable-on-another-library")
.first()
.should("be.visible")
.and("contain", "Reservable on another library")
.and("contain", "Reserve bog")
.click();
cy.getBySel("material-description").scrollIntoView();
cy.getBySel("reservation-modal-submit-button", true)
Expand Down Expand Up @@ -45,7 +45,7 @@ describe("Open Order Functionality", () => {

cy.getBySel("open-oprder-response-status-text")
.should("be.visible")
.and("contain", "Your order is accepted");
.and("contain", "Your material has been ordered from another library");

closeModal();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,30 @@ import { Manifestation } from "../../../core/utils/types/entities";
import { hasCorrectAccessType } from "../material-buttons/helper";
import MaterialAvailabilityTextOnline from "./online/MaterialAvailabilityTextOnline";
import MaterialAvailabilityTextPhysical from "./physical/MaterialAvailabilityTextPhysical";
import useReservableFromAnotherLibrary from "../../../core/utils/useReservableFromAnotherLibrary";
import MaterialAvailabilityTextParagraph from "./generic/MaterialAvailabilityTextParagraph";
import { useText } from "../../../core/utils/text";

interface Props {
manifestations: Manifestation[];
}

const MaterialAvailabilityText: React.FC<Props> = ({ manifestations }) => {
const t = useText();
const materialType = head(getMaterialTypes(manifestations));
const isbns = getAllIdentifiers(manifestations);
const { materialIsReservableFromAnotherLibrary } =
useReservableFromAnotherLibrary(manifestations);

if (hasCorrectAccessType(AccessTypeCode.Physical, manifestations)) {
const pids = getAllPids(manifestations);
if (materialIsReservableFromAnotherLibrary) {
return (
<MaterialAvailabilityTextParagraph>
{t("reservableFromAnotherLibraryText")}
</MaterialAvailabilityTextParagraph>
);
}
return <MaterialAvailabilityTextPhysical pids={pids} />;
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/material/material-buttons/MaterialButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ const MaterialButtons: FC<MaterialButtonsProps> = ({
// articles appear as a part of journal/periodical publications and can't be
// physically loaned for themseleves.

const reservablePidsFromAnotherLibrary =
const { materialIsReservableFromAnotherLibrary } =
useReservableFromAnotherLibrary(manifestations);

if (reservablePidsFromAnotherLibrary.length > 0) {
if (materialIsReservableFromAnotherLibrary) {
return (
<MaterialButtonReservableFromAnotherLibrary
size={size}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ const MaterialButtonPhysical: FC<MaterialButtonPhysicalProps> = ({
label={
size === "small"
? t("reserveText")
: `${t("reserveText")} ${manifestationMaterialType}`
: `${t("reserveWithMaterialTypeText", {
placeholders: { "@materialType": manifestationMaterialType }
})}`
}
buttonType="none"
variant="filled"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ const MaterialButtonReservableFromAnotherLibrary: FC<
dataCy={dataCy}
label={
size === "small"
? t("reservableFromAnotherLibraryText")
: `${t(
"reservableFromAnotherLibraryText"
)} ${manifestationMaterialType}`
? t("reserveText")
: `${t("reserveWithMaterialTypeText", {
placeholders: { "@materialType": manifestationMaterialType }
})}`
}
buttonType="none"
variant="filled"
Expand Down
40 changes: 26 additions & 14 deletions src/components/reservation/ReservationModalBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ import {
getInstantLoanBranchHoldings,
getInstantLoanBranchHoldingsAboveThreshold,
removePrefixFromBranchId,
translateOpenOrderStatus
translateOpenOrderStatus,
getFutureDateStringISO
} from "./helper";
import UseReservableManifestations from "../../core/utils/UseReservableManifestations";
import { PeriodicalEdition } from "../material/periodical/helper";
Expand Down Expand Up @@ -134,9 +135,10 @@ export const ReservationModalBody = ({
!!selectedPeriodical
);

const reservablePidsFromAnotherLibrary = useReservableFromAnotherLibrary(
selectedManifestations
);
const {
reservablePidsFromAnotherLibrary,
materialIsReservableFromAnotherLibrary
} = useReservableFromAnotherLibrary(selectedManifestations);

// If we don't have all data for displaying the view render nothing.
if (!userResponse.data || !holdingsResponse.data) {
Expand Down Expand Up @@ -185,19 +187,20 @@ export const ReservationModalBody = ({
);
}

if (reservablePidsFromAnotherLibrary?.length && patron) {
if (materialIsReservableFromAnotherLibrary && patron) {
const { patronId, name, emailAddress, preferredPickupBranch } = patron;

// Save reservation to open order.
mutateOpenOrder(
{
input: {
pids: [...reservablePidsFromAnotherLibrary],
pids: reservablePidsFromAnotherLibrary,
pickUpBranch: selectedBranch
? removePrefixFromBranchId(selectedBranch)
: removePrefixFromBranchId(preferredPickupBranch),
expires:
selectedInterest?.toString() ||
defaultInterestDaysForOpenOrder.toString(),
expires: getFutureDateStringISO(
Number(selectedInterest ?? defaultInterestDaysForOpenOrder)
),
userParameters: {
userId: patronId.toString(),
userName: name,
Expand Down Expand Up @@ -259,10 +262,14 @@ export const ReservationModalBody = ({
<div>
<div className="reservation-modal-submit">
<MaterialAvailabilityTextParagraph>
<StockAndReservationInfo
stockCount={holdings}
reservationCount={reservations}
/>
{materialIsReservableFromAnotherLibrary ? (
t("reservableFromAnotherLibraryText")
) : (
<StockAndReservationInfo
stockCount={holdings}
reservationCount={reservations}
/>
)}
</MaterialAvailabilityTextParagraph>
<Button
dataCy="reservation-modal-submit-button"
Expand Down Expand Up @@ -303,7 +310,12 @@ export const ReservationModalBody = ({
branches={branches}
selectedBranch={selectedBranch}
selectBranchHandler={setSelectedBranch}
selectedInterest={selectedInterest}
selectedInterest={
materialIsReservableFromAnotherLibrary &&
selectedInterest === null
? Number(defaultInterestDaysForOpenOrder)
: selectedInterest
}
setSelectedInterest={setSelectedInterest}
/>
)}
Expand Down
6 changes: 6 additions & 0 deletions src/components/reservation/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export const getFutureDateString = (num: number) => {
const futureDate = dayjs().add(num, "day").format("YYYY-MM-DD");
return futureDate;
};

export const getFutureDateStringISO = (num: number) => {
const futureDate = dayjs().add(num, "day").format("YYYY-MM-DDTHH:mm:ssZ");
return futureDate;
};

type Periodical = Pick<PeriodicalEdition, "volumeNumber" | "volumeYear">;

const constructReservation = ({
Expand Down
21 changes: 18 additions & 3 deletions src/core/utils/useReservableFromAnotherLibrary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { Pid } from "./types/ids";

const useReservableFromAnotherLibrary = (
manifestations: Manifestation[]
): Pid[] => {
): {
reservablePidsFromAnotherLibrary: Pid[];
materialIsReservableFromAnotherLibrary: boolean;
} => {
const config = useConfig();
const { data: holdingsData } = useGetHoldings({
faustIds: getAllFaustIds(manifestations),
Expand All @@ -16,14 +19,26 @@ const useReservableFromAnotherLibrary = (
// If there is no holdings data or if there are holdings that are reservable, we return an empty array.
// Because we use the array length to determine if we should show the button or not.
if (holdingsData?.some(({ reservable }) => reservable === true)) {
return [];
return {
reservablePidsFromAnotherLibrary: [],
materialIsReservableFromAnotherLibrary: false
};
}

return manifestations
const reservablePidsFromAnotherLibrary = manifestations
.filter(({ catalogueCodes }) =>
catalogueCodes?.otherCatalogues.some((code) => code.startsWith("OVE"))
)
.map(({ pid }) => pid);

const materialIsReservableFromAnotherLibrary = Boolean(
reservablePidsFromAnotherLibrary.length
);

return {
reservablePidsFromAnotherLibrary,
materialIsReservableFromAnotherLibrary
};
};

export default useReservableFromAnotherLibrary;
8 changes: 6 additions & 2 deletions src/tests/unit/useReservableFromAnotherLibrary.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ describe("useReservableFromAnotherLibrary", () => {
);

act(() => {
expect(result.current).toEqual(["870970-basis:27721257"]);
expect(result.current.reservablePidsFromAnotherLibrary).toEqual([
"870970-basis:27721257"
]);
expect(result.current.materialIsReservableFromAnotherLibrary).toBe(true);
});
});

Expand Down Expand Up @@ -103,7 +106,8 @@ describe("useReservableFromAnotherLibrary", () => {
);

act(() => {
expect(result.current).toEqual([]);
expect(result.current.reservablePidsFromAnotherLibrary).toEqual([]);
expect(result.current.materialIsReservableFromAnotherLibrary).toBe(false);
});
});
});

0 comments on commit bdfe2b9

Please sign in to comment.