From 2a061b7114936b51377674fc1802eb6af0de4e20 Mon Sep 17 00:00:00 2001 From: Kasper Birch Date: Tue, 31 Oct 2023 12:03:57 +0100 Subject: [PATCH] Set the patron `preferredPickupBranch` instead of the empty string in `openOrder` The previous implementation set an empty string for the `pickUpBranch` field in `openOrder` if `selectedBranch` was not provided. However, an empty string is still considered a valid value when sent to the API, which triggered an `UNKNOWN_USER` error due to the user not being found. Additionally, the `getPatronAddress` function has been removed as it's no longer necessary to send the address. There was a concern regarding potential mismatches in address formatting, which could result in errors since `openOrder` requires exact matches for input values. --- src/components/reservation/ReservationModalBody.tsx | 8 +++----- src/core/utils/helpers/general.ts | 4 ---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/components/reservation/ReservationModalBody.tsx b/src/components/reservation/ReservationModalBody.tsx index 07ed3384a9..a8dfe601c2 100644 --- a/src/components/reservation/ReservationModalBody.tsx +++ b/src/components/reservation/ReservationModalBody.tsx @@ -7,8 +7,7 @@ import { getMaterialTypes, getManifestationType, materialIsFiction, - getReservablePidsFromAnotherLibrary, - getPatronAddress + getReservablePidsFromAnotherLibrary } from "../../core/utils/helpers/general"; import { useText } from "../../core/utils/text"; import { Button } from "../Buttons/Button"; @@ -155,7 +154,7 @@ export const ReservationModalBody = ({ } if (pidsFromAnotherLibrary.length > 0 && patron) { - const { patronId, address, name, emailAddress } = patron; + const { patronId, name, emailAddress, preferredPickupBranch } = patron; mutateOpenOrder( { @@ -163,13 +162,12 @@ export const ReservationModalBody = ({ pids: [...pidsFromAnotherLibrary], pickUpBranch: selectedBranch ? removePrefixFromBranchId(selectedBranch) - : "", + : removePrefixFromBranchId(preferredPickupBranch), expires: selectedInterest?.toString() || defaultInterestDaysForOpenOrder.toString(), userParameters: { userId: patronId.toString(), - userAddress: address ? getPatronAddress(address) : "", userName: name, userMail: emailAddress } diff --git a/src/core/utils/helpers/general.ts b/src/core/utils/helpers/general.ts index b52b3329fb..5959b22c77 100644 --- a/src/core/utils/helpers/general.ts +++ b/src/core/utils/helpers/general.ts @@ -20,7 +20,6 @@ import { dashboardReservedApiValueText } from "../../configuration/api-strings.j import { ReservationType } from "../types/reservation-type"; import { ManifestationMaterialType } from "../types/material-type"; import { store } from "../../store"; -import { AddressV2 } from "../../fbs/model"; export const getManifestationPublicationYear = ( manifestation: Manifestation @@ -573,9 +572,6 @@ export const getReservablePidsFromAnotherLibrary = ( return matchingManifestations.map(({ pid }) => pid); }; -export const getPatronAddress = (address: AddressV2) => - `${address.street}, ${address.postalCode} ${address.city}`; - export default {}; /* ********************************* Vitest Section ********************************* */