Skip to content

Commit

Permalink
WIP: expires not work for open order
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperbirch1 committed Apr 3, 2024
1 parent 2a1354a commit acff10d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
21 changes: 14 additions & 7 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 @@ -177,8 +178,9 @@ export const ReservationModalBody = ({
);
}

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

// Save reservation to open order.
mutateOpenOrder(
{
Expand All @@ -187,9 +189,9 @@ export const ReservationModalBody = ({
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,7 +253,7 @@ export const ReservationModalBody = ({
<div>
<div className="reservation-modal-submit">
<MaterialAvailabilityTextParagraph>
{reservablePidsFromAnotherLibrary?.length ? (
{reservablePidsFromAnotherLibrary?.length > 0 ? (
t("reservableFromAnotherLibraryText")
) : (
<StockAndReservationInfo
Expand Down Expand Up @@ -299,7 +301,12 @@ export const ReservationModalBody = ({
branches={branches}
selectedBranch={selectedBranch}
selectBranchHandler={setSelectedBranch}
selectedInterest={selectedInterest}
selectedInterest={
reservablePidsFromAnotherLibrary?.length > 0 &&
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

0 comments on commit acff10d

Please sign in to comment.