Skip to content

Commit

Permalink
Introduce OpenOrder logic and related components
Browse files Browse the repository at this point in the history
- Implemented a new function `getReservableOnAnotherLibrary` to verify if a material is categorized as "overbygningsmateriale". This function returns both a boolean and a list of PIDs.
- Utilized `getReservableOnAnotherLibrary` function to determine the visibility of the `MaterialButtonReservableOnAnotherLibrary` button.
- Introduced a new component, `OpenOrderResponse`, as the `ReservationSuccess` does not have the same response structure.
- Added `translateOpenOrderStatus` to interpret and display the response status.
  • Loading branch information
kasperbirch1 committed Sep 26, 2023
1 parent 966cefd commit 7c23601
Show file tree
Hide file tree
Showing 7 changed files with 376 additions and 13 deletions.
100 changes: 100 additions & 0 deletions src/apps/material/material.dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,101 @@ export default {
defaultValue:
'[\n {\n "value":"30",\n "label":"1 month"\n },\n {\n "value":"60",\n "label":"2 months"\n },\n {\n "value":"90",\n "label":"3 months"\n },\n {\n "value":"180",\n "label":"6 months"\n },\n {\n "value":"360",\n "label":"1 year"\n }\n]',
control: { type: "text" }
},
openOrderResponseTitleText: {
name: "Reservation Success title",
defaultValue: "Order from another library:",
control: { type: "text" }
},
openOrderResponseIsReservedForYouText: {
name: "Reservation Success Title",
defaultValue: "is ordered to your library",
control: { type: "text" }
},
openOrderAuthenticationErrorText: {
name: "Open order authentication error text",
defaultValue: "Authentication error occurred",
control: { type: "text" }
},
openOrderUserBlockedByAgencyText: {
name: "Open order user blocked by agency text",
defaultValue: "You are blocked by the agency",
control: { type: "text" }
},
openOrderUserNotVerifiedText: {
name: "Open order user not verified text",
defaultValue: "User could not be verified",
control: { type: "text" }
},
openOrderUserNoLongerExistOnAgencyText: {
name: "Open order user no longer exists on agency text",
defaultValue: "User no longer exists at the specified agency",
control: { type: "text" }
},
openOrderInvalidOrderText: {
name: "Open order invalid order text",
defaultValue: "Your order is invalid",
control: { type: "text" }
},
openOrderNotOwnedIllLocText: {
name: "Open order item localized for ILL text",
defaultValue: "Item not available at pickup agency but localized for ILL",
control: { type: "text" }
},
openOrderNotOwnedNoIllLocText: {
name: "Open order item not localized for ILL text",
defaultValue: "Item not available and not localized for ILL",
control: { type: "text" }
},
openOrderNotOwnedWrongIllMediumtypeText: {
name: "Open order wrong ILL medium type text",
defaultValue: "Item not available, ILL of this medium type not accepted",
control: { type: "text" }
},
openOrderNoServicerequesterText: {
name: "Open order no service requester text",
defaultValue: "Service requester is obligatory",
control: { type: "text" }
},
openOrderOrsErrorText: {
name: "Open order ORS error text",
defaultValue: "Error occurred while sending order to ORS",
control: { type: "text" }
},
openOrderStatusOwnedAcceptedText: {
name: "Open order status owned accepted text",
defaultValue: "Your order is accepted",
control: { type: "text" }
},
openOrderOwnedOwnCatalogueText: {
name: "Open order available in own catalogue text",
defaultValue: "Item available, order through the library's catalogue",
control: { type: "text" }
},
openOrderOwnedWrongMediumtypeText: {
name: "Open order wrong medium type for available item text",
defaultValue: "Item available but medium type not accepted",
control: { type: "text" }
},
openOrderServiceUnavailableText: {
name: "Open order service unavailable text",
defaultValue: "Service is currently unavailable",
control: { type: "text" }
},
openOrderUnknownErrorText: {
name: "Open order unknown error text",
defaultValue: "An unknown error occurred",
control: { type: "text" }
},
openOrderUnknownPickupagencyText: {
name: "Open order unknown pickup agency text",
defaultValue: "Specified pickup agency not found",
control: { type: "text" }
},
openOrderUnknownUserText: {
name: "Open order unknown user text",
defaultValue: "User not found",
control: { type: "text" }
}
}
} as ComponentMeta<typeof MaterialEntry>;
Expand Down Expand Up @@ -877,3 +972,8 @@ export const Underverden = Template.bind({});
Underverden.args = {
wid: "work-of:870970-basis:52886619"
};

export const overbygningsMatriale = Template.bind({});
overbygningsMatriale.args = {
wid: "work-of:870970-basis:135721719"
};
19 changes: 19 additions & 0 deletions src/apps/material/material.entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,25 @@ interface MaterialEntryTextProps {
okButtonText: string;
onlineLimitMonthAudiobookInfoText: string;
onlineLimitMonthEbookInfoText: string;
openOrderAuthenticationErrorText: string;
openOrderInvalidOrderText: string;
openOrderNoServicerequesterText: string;
openOrderNotOwnedIllLocText: string;
openOrderNotOwnedNoIllLocText: string;
openOrderNotOwnedWrongIllMediumtypeText: string;
openOrderOrsErrorText: string;
openOrderOwnedOwnCatalogueText: string;
openOrderOwnedWrongMediumtypeText: string;
openOrderResponseIsReservedForYouText: string;
openOrderResponseTitleText: string;
openOrderServiceUnavailableText: string;
openOrderStatusOwnedAcceptedText: string;
openOrderUnknownErrorText: string;
openOrderUnknownPickupagencyText: string;
openOrderUnknownUserText: string;
openOrderUserBlockedByAgencyText: string;
openOrderUserNoLongerExistOnAgencyText: string;
openOrderUserNotVerifiedText: string;
orderDigitalCopyButtonLoadingText: string;
orderDigitalCopyButtonText: string;
orderDigitalCopyDescriptionText: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import {
getAllFaustIds,
getManifestationType,
isReservableOnAnotherLibrary
getReservableOnAnotherLibrary
} from "../../../../core/utils/helpers/general";
import { isBlocked } from "../../../../core/utils/helpers/user";
import { ButtonSize } from "../../../../core/utils/types/button";
Expand All @@ -27,8 +27,8 @@ const MaterialButtonsPhysical: React.FC<MaterialButtonsPhysicalProps> = ({
size,
dataCy = "material-buttons-physical"
}) => {
const reservableOnAnotherLibrary =
isReservableOnAnotherLibrary(manifestations);
const { isReservable: isReservableOnAnotherLibrar } =
getReservableOnAnotherLibrary(manifestations);
const t = useText();
const faustIds = getAllFaustIds(manifestations);
const { reservableManifestations } = UseReservableManifestations({
Expand All @@ -49,12 +49,12 @@ const MaterialButtonsPhysical: React.FC<MaterialButtonsPhysicalProps> = ({
return <MaterialButtonUserBlocked size={size} dataCy={dataCy} />;
}

if (reservableOnAnotherLibrary) {
if (isReservableOnAnotherLibrar) {
return (
<MaterialButtonReservableOnAnotherLibrary
size={size}
manifestationMaterialType=""
faustIds={[]}
manifestationMaterialType={getManifestationType(manifestations)}
faustIds={faustIds}
/>
);
}
Expand Down
66 changes: 66 additions & 0 deletions src/components/reservation/OpenOrderResponse.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import FocusTrap from "focus-trap-react";
import React from "react";
import { useDispatch } from "react-redux";
import { closeModal } from "../../core/modal.slice";
import { useText } from "../../core/utils/text";
import { Button } from "../Buttons/Button";
import { OpenOrderMutation } from "../../core/dbc-gateway/generated/graphql";
import { translateOpenOrderStatus } from "./helper";

type OpenOrderResponseProps = {
title: string;
modalId: string;
openOrderResponse: OpenOrderMutation;
};

const OpenOrderResponse: React.FC<OpenOrderResponseProps> = ({
modalId,
title,
openOrderResponse
}) => {
const dispatch = useDispatch();
const t = useText();

return (
<FocusTrap
focusTrapOptions={{
allowOutsideClick: true
}}
>
<section className="reservation-modal reservation-modal--confirm">
<h2
data-cy="reservation-success-title-text"
className="text-header-h3 pb-48"
>
{t("openOrderResponseTitleText")}
</h2>

<p className="text-body-medium-regular pb-24">
{title} {t("openOrderResponseIsReservedForYouText")}
</p>

{openOrderResponse.submitOrder?.status && (
<p className="text-body-medium-regular pb-24">
{translateOpenOrderStatus(openOrderResponse.submitOrder?.status, t)}
</p>
)}

<Button
dataCy="reservation-success-close-button"
classNames="reservation-modal__confirm-button"
label={t("okButtonText")}
buttonType="none"
disabled={false}
collapsible={false}
size="small"
variant="filled"
onClick={() => {
dispatch(closeModal({ modalId }));
}}
/>
</section>
</FocusTrap>
);
};

export default OpenOrderResponse;
61 changes: 56 additions & 5 deletions src/components/reservation/ReservationModalBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
getAllPids,
getMaterialTypes,
getManifestationType,
materialIsFiction
materialIsFiction,
getReservableOnAnotherLibrary
} from "../../core/utils/helpers/general";
import { useText } from "../../core/utils/text";
import { Button } from "../Buttons/Button";
Expand Down Expand Up @@ -39,7 +40,9 @@ import {
getAuthorLine,
getManifestationsToReserve,
getInstantLoanBranchHoldings,
getInstantLoanBranchHoldingsAboveThreshold
getInstantLoanBranchHoldingsAboveThreshold,
removeDKFromBranchId,
getPatronAddress
} from "./helper";
import UseReservableManifestations from "../../core/utils/UseReservableManifestations";
import { PeriodicalEdition } from "../material/periodical/helper";
Expand All @@ -54,6 +57,11 @@ import InstantLoan from "../instant-loan/InstantLoan";
import { excludeBlacklistedBranches } from "../../core/utils/branches";
import { InstantLoanConfigType } from "../../core/utils/types/instant-loan";
import { usePatronData } from "../material/helper";
import {
OpenOrderMutation,
useOpenOrderMutation
} from "../../core/dbc-gateway/generated/graphql";
import OpenOrderResponse from "./OpenOrderResponse";

type ReservationModalProps = {
selectedManifestations: Manifestation[];
Expand Down Expand Up @@ -95,11 +103,14 @@ export const ReservationModalBody = ({
const queryClient = useQueryClient();
const [reservationResponse, setReservationResponse] =
useState<ReservationResponseV2 | null>(null);
const [openOrderResponse, setOpenOrderResponse] =
useState<OpenOrderMutation | null>(null);
const [selectedBranch, setSelectedBranch] = useState<string | null>(null);
const [selectedInterest, setSelectedInterest] = useState<number | null>(null);
const allPids = getAllPids(selectedManifestations);
const faustIds = convertPostIdsToFaustIds(allPids);
const { mutate } = useAddReservationsV2();
const { mutate: mutateAddReservations } = useAddReservationsV2();
const { mutate: mutateOpenOrder } = useOpenOrderMutation();
const userResponse = usePatronData();
const holdingsResponse = useGetHoldings({ faustIds, config });
const { track } = useStatistics();
Expand Down Expand Up @@ -128,12 +139,45 @@ export const ReservationModalBody = ({
? getFutureDateString(selectedInterest)
: null;

const {
isReservable: isReservableOnAnotherLibrar,
pids: pidsOnAnotherLibrar
} = getReservableOnAnotherLibrary(manifestationsToReserve);

const saveReservation = () => {
if (!manifestationsToReserve || manifestationsToReserve.length < 1) {
return;
}

if (isReservableOnAnotherLibrar && patron) {
const { preferredPickupBranch, patronId, address, name, emailAddress } =
patron;

mutateOpenOrder(
{
input: {
pids: [...pidsOnAnotherLibrar],
pickUpBranch: removeDKFromBranchId(preferredPickupBranch),
userParameters: {
userId: patronId.toString(),
userAddress: address ? getPatronAddress(address) : "",
userName: name,
userMail: emailAddress
}
}
},
{
onSuccess: (res) => {
setOpenOrderResponse(res);
}
}
);

return;
}

// Save reservation to FBS.
mutate(
mutateAddReservations(
{
data: constructReservationData({
manifestations: manifestationsToReserve,
Expand Down Expand Up @@ -184,7 +228,7 @@ export const ReservationModalBody = ({

return (
<>
{!reservationResults && (
{!reservationResults && !openOrderResponse && (
<section className="reservation-modal">
<header className="reservation-modal-header">
<Cover id={manifestation.pid} size="medium" animate />
Expand Down Expand Up @@ -266,6 +310,13 @@ export const ReservationModalBody = ({
</div>
</section>
)}
{openOrderResponse && (
<OpenOrderResponse
title={manifestation.titles.main[0]}
modalId={reservationModalId(faustIds)}
openOrderResponse={openOrderResponse}
/>
)}
{reservationSuccess && reservationDetails && (
<ReservationSucces
modalId={reservationModalId(faustIds)}
Expand Down
Loading

0 comments on commit 7c23601

Please sign in to comment.