Skip to content

Commit

Permalink
Disable "Approve reservation" button if user already clicked it
Browse files Browse the repository at this point in the history
This prevents multiple calls being fired before they're resolved.
  • Loading branch information
Adamik10 committed Oct 9, 2024
1 parent 1d712cd commit 6853a6f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/components/reservation/ReservationModalBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ export const ReservationModalBody = ({
reservableManifestations ?? [],
!!selectedPeriodical
);

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

const saveReservation = () => {
if (manifestationsToReserve?.length) {
setReservationStatus("pending");
// Save reservation to FBS.
mutateAddReservations(
{
Expand All @@ -174,6 +176,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 +189,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 +220,11 @@ export const ReservationModalBody = ({
},
{
onSuccess: (res) => {
setReservationStatus("success");
setOpenOrderResponse(res);
},
onError: () => {
setReservationStatus("error");
}
}
);
Expand Down Expand Up @@ -280,7 +290,7 @@ export const ReservationModalBody = ({
label={t("approveReservationText")}
buttonType="none"
variant="filled"
disabled={false}
disabled={reservationStatus === "pending"}
collapsible={false}
size="small"
onClick={saveReservation}
Expand Down

0 comments on commit 6853a6f

Please sign in to comment.