Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the 'Reserve' button text to the standard and move the notice about material ordered from other libraries to the MaterialAvailabilityTextParagraph. #854

Merged
merged 5 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}
}
4 changes: 2 additions & 2 deletions src/apps/material/material.dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default {
},
reservableFromAnotherLibraryText: {
name: "Reservable on another library",
defaultValue: "Reservable on another library",
defaultValue: "Ordered from another library.",
control: { type: "text" }
},
findOnBookshelfText: {
Expand Down Expand Up @@ -767,7 +767,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
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 @@ -40,10 +40,8 @@ const MaterialButtonReservableFromAnotherLibrary: FC<
dataCy={dataCy}
label={
size === "small"
? t("reservableFromAnotherLibraryText")
: `${t(
"reservableFromAnotherLibraryText"
)} ${manifestationMaterialType}`
? t("reserveText")
: `${t("reserveText")} ${manifestationMaterialType}`
kasperbirch1 marked this conversation as resolved.
Show resolved Hide resolved
}
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 @@ -128,9 +129,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 @@ -177,19 +179,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 @@ -251,10 +254,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 @@ -295,7 +302,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);
});
});
});
Loading