Skip to content

Commit

Permalink
Merge pull request #1481 from danskernesdigitalebibliotek/DDFBRA-47-f…
Browse files Browse the repository at this point in the history
…lere-samtidige-reserveringer

Ddfbra 47 flere samtidige reserveringer
  • Loading branch information
Adamik10 authored Oct 11, 2024
2 parents 3689d60 + e7859b2 commit c5e92bf
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
18 changes: 15 additions & 3 deletions src/components/reservation/ReservationModalBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import configuration, { getConf } from "../../core/configuration";
import useReservableFromAnotherLibrary from "../../core/utils/useReservableFromAnotherLibrary";
import { usePatronData } from "../../core/utils/helpers/usePatronData";
import { Periods } from "./types";
import { RequestStatus } from "../../core/utils/types/request";

type ReservationModalProps = {
selectedManifestations: Manifestation[];
Expand Down Expand Up @@ -135,7 +136,8 @@ export const ReservationModalBody = ({
reservableManifestations ?? [],
!!selectedPeriodical
);

const [reservationStatus, setReservationStatus] =
useState<RequestStatus>("idle");
const {
reservablePidsFromAnotherLibrary,
materialIsReservableFromAnotherLibrary
Expand All @@ -162,6 +164,7 @@ export const ReservationModalBody = ({

const saveReservation = () => {
if (manifestationsToReserve?.length) {
setReservationStatus("pending");
// Save reservation to FBS.
mutateAddReservations(
{
Expand All @@ -174,6 +177,7 @@ export const ReservationModalBody = ({
},
{
onSuccess: (res) => {
setReservationStatus("success");
// Track only if the reservation has been successfully saved.
track("click", {
id: statistics.reservation.id,
Expand All @@ -186,14 +190,17 @@ export const ReservationModalBody = ({
queryClient.invalidateQueries(
getGetHoldingsV3QueryKey({ recordid: faustIds })
);
},
onError: () => {
setReservationStatus("error");
}
}
);
}

if (materialIsReservableFromAnotherLibrary && patron) {
setReservationStatus("pending");
const { patronId, name, emailAddress, preferredPickupBranch } = patron;

// Save reservation to open order.
mutateOpenOrder(
{
Expand All @@ -214,7 +221,11 @@ export const ReservationModalBody = ({
},
{
onSuccess: (res) => {
setReservationStatus("success");
setOpenOrderResponse(res);
},
onError: () => {
setReservationStatus("error");
}
}
);
Expand Down Expand Up @@ -280,7 +291,7 @@ export const ReservationModalBody = ({
label={t("approveReservationText")}
buttonType="none"
variant="filled"
disabled={false}
disabled={reservationStatus === "pending"}
collapsible={false}
size="small"
onClick={saveReservation}
Expand Down Expand Up @@ -321,6 +332,7 @@ export const ReservationModalBody = ({
: selectedInterest
}
setSelectedInterest={setSelectedInterest}
reservationStatus={reservationStatus}
/>
)}

Expand Down
7 changes: 6 additions & 1 deletion src/components/reservation/UserListItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import PickupModal from "./forms/PickupModal";
import NoInterestAfterModal from "./forms/NoInterestAfterModal";
import { Periods } from "./types";
import { RequestStatus } from "../../core/utils/types/request";

export interface UserListItemsProps {
patron: PatronV5;
Expand All @@ -32,6 +33,7 @@ export interface UserListItemsProps {
selectedInterest: number | null;
setSelectedInterest: (value: number) => void;
whitelistBranches: AgencyBranch[];
reservationStatus: RequestStatus;
}

const UserListItems: FC<UserListItemsProps> = ({
Expand All @@ -42,7 +44,8 @@ const UserListItems: FC<UserListItemsProps> = ({
selectBranchHandler,
selectedInterest,
setSelectedInterest,
whitelistBranches
whitelistBranches,
reservationStatus
}) => {
const t = useText();
const config = useConfig();
Expand Down Expand Up @@ -83,6 +86,7 @@ const UserListItems: FC<UserListItemsProps> = ({
selectedInterest ?? interestPeriods.defaultInterestPeriod.value
}
setSelectedInterest={setSelectedInterest}
reservationStatus={reservationStatus}
/>
</>
)}
Expand All @@ -99,6 +103,7 @@ const UserListItems: FC<UserListItemsProps> = ({
branches={whitelistBranches}
defaultBranch={selectedBranch ?? preferredPickupBranch}
selectBranchHandler={selectBranchHandler}
reservationStatus={reservationStatus}
/>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface ModalReservationFormSelectProps<
saveCallback?: <TSaveValue extends FormSelectValue>(
value: TSaveValue
) => void;
reservationStatus?: RequestStatus;
reservationStatus: RequestStatus;
setReservationStatus?: (status: RequestStatus) => void;
}

Expand Down Expand Up @@ -129,6 +129,7 @@ const ModalReservationFormSelect = <TValue extends FormSelectValue>({
title={header.title}
description={header.description}
onSubmit={onSubmit}
disabledButton={reservationStatus === "pending"}
buttonLabel={
reservationStatus === "pending" ? t("loadingText") : undefined
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/reservation/forms/NoInterestAfterModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface NoInterestAfterModalProps {
selectedInterest: number;
setSelectedInterest: (value: number) => void;
saveCallback?: <TValue extends FormSelectValue>(value: TValue) => void;
reservationStatus?: RequestStatus;
reservationStatus: RequestStatus;
setReservationStatus?: (status: RequestStatus) => void;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/reservation/forms/PickupModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface PickupModalProps {
defaultBranch: string;
selectBranchHandler: (value: string) => void;
saveCallback?: <TValue extends FormSelectValue>(value: TValue) => void;
reservationStatus?: RequestStatus;
reservationStatus: RequestStatus;
setReservationStatus?: (status: RequestStatus) => void;
}

Expand Down

0 comments on commit c5e92bf

Please sign in to comment.