From a5fb5764d5637880d450470ae5b9f21dc3c11b0f Mon Sep 17 00:00:00 2001 From: mtni Date: Fri, 26 Jan 2024 11:39:57 +0100 Subject: [PATCH 1/4] ... --- .../ordererinformation/OrdererInformation.js | 54 +++++++++++-------- src/lib/api/user.fragments.js | 6 +++ 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/components/_modal/pages/order/ordererinformation/OrdererInformation.js b/src/components/_modal/pages/order/ordererinformation/OrdererInformation.js index bd2c6ca03..21eaf9bd5 100644 --- a/src/components/_modal/pages/order/ordererinformation/OrdererInformation.js +++ b/src/components/_modal/pages/order/ordererinformation/OrdererInformation.js @@ -9,13 +9,16 @@ import * as PropTypes from "prop-types"; import useOrderPageInformation from "@/components/hooks/useOrderPageInformations"; import { getStylingAndErrorMessage } from "@/components/_modal/pages/order/utils/order.utils"; import { validateEmail } from "@/utils/validateEmail"; +import { useEffect } from "react"; export function OrdererInformation({ isLoadingBranches, name, + hasAuthMail, email, lockedMessage, invalidClass, + isLoading, onMailChange, message, validClass, @@ -54,9 +57,11 @@ export function OrdererInformation({ label: "email-placeholder", })} invalidClass={invalidClass} + disabled={isLoading || hasAuthMail} value={email?.value || ""} id="order-user-email" onChange={onMailChange} + readOnly={isLoading || hasAuthMail} skeleton={isLoadingBranches && !email} /> @@ -165,34 +170,41 @@ export default function Wrap({ const isLoading = isWorkLoading || isPickupBranchLoading || userIsLoading; - // Email according to agency borrowerCheck (authUser.mail is from cicero and can not be changed) - let initialmail = hasBorchk ? authUser?.mail || userMail : userMail; - - if (!email && initialmail) { - const status = validateEmail(initialmail); - setMail && - setMail({ - value: initialmail, - valid: { - status: status, - message: status - ? null - : { - context: "form", - label: "wrong-email-field", - }, - }, - }); - } + const map = { + 732900: "moni.privat@hotmail.dk", + 737000: "hest@mail.dk", + 800010: null, + }; + // authUser?.agencies.forEach((a) => (map[a.id] = a.user?.mail)); + + const pickupAuthMail = map?.[pickupBranch?.agencyId]; + + // Email according to agency borrowerCheck (map[pickupBranch?.agencyId] is from cicero and can not be changed) + let initialmail = hasBorchk ? pickupAuthMail || userMail : userMail; + + useEffect(() => { + function updateEmail() { + const status = validateEmail(initialmail); + const message = !status && { + context: "form", + label: "wrong-email-field", + }; + setMail && setMail({ value: initialmail, valid: { status, message } }); + } + + if (initialmail) { + updateEmail(); + } + }, [pickupAuthMail]); const showMailMessage = - isLoadingBranches || (authUser?.mail && lockedMessage && hasBorchk); + isLoadingBranches || (pickupAuthMail && lockedMessage && hasBorchk); return ( Date: Fri, 26 Jan 2024 13:01:58 +0100 Subject: [PATCH 2/4] ... --- .../pages/order/ordererinformation/OrdererInformation.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/components/_modal/pages/order/ordererinformation/OrdererInformation.js b/src/components/_modal/pages/order/ordererinformation/OrdererInformation.js index 21eaf9bd5..8220b7f09 100644 --- a/src/components/_modal/pages/order/ordererinformation/OrdererInformation.js +++ b/src/components/_modal/pages/order/ordererinformation/OrdererInformation.js @@ -170,12 +170,8 @@ export default function Wrap({ const isLoading = isWorkLoading || isPickupBranchLoading || userIsLoading; - const map = { - 732900: "moni.privat@hotmail.dk", - 737000: "hest@mail.dk", - 800010: null, - }; - // authUser?.agencies.forEach((a) => (map[a.id] = a.user?.mail)); + const map = {}; + authUser?.agencies.forEach((a) => (map[a.id] = a.user?.mail)); const pickupAuthMail = map?.[pickupBranch?.agencyId]; From 2c62478837f97bbcd1633812c23a266ea99eb92b Mon Sep 17 00:00:00 2001 From: mtni Date: Fri, 26 Jan 2024 13:54:36 +0100 Subject: [PATCH 3/4] fix test --- e2e/cypress/e2e/bookmarkorder.cy.js | 2 +- .../pages/order/ordererinformation/OrdererInformation.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/e2e/cypress/e2e/bookmarkorder.cy.js b/e2e/cypress/e2e/bookmarkorder.cy.js index 8a8511474..f0cc28fdd 100644 --- a/e2e/cypress/e2e/bookmarkorder.cy.js +++ b/e2e/cypress/e2e/bookmarkorder.cy.js @@ -4,7 +4,7 @@ describe("BookmarkOrderSingle", () => { win.sessionStorage.clear(); }); }); - it(`Order a single material from bookmarklist`, () => { + it.only(`Order a single material from bookmarklist`, () => { cy.visit( "/iframe.html?id=modal-materials--materials-to-order-single-material" ); diff --git a/src/components/_modal/pages/order/ordererinformation/OrdererInformation.js b/src/components/_modal/pages/order/ordererinformation/OrdererInformation.js index 8220b7f09..58d69f07c 100644 --- a/src/components/_modal/pages/order/ordererinformation/OrdererInformation.js +++ b/src/components/_modal/pages/order/ordererinformation/OrdererInformation.js @@ -58,7 +58,7 @@ export function OrdererInformation({ })} invalidClass={invalidClass} disabled={isLoading || hasAuthMail} - value={email?.value || ""} + value={email || ""} id="order-user-email" onChange={onMailChange} readOnly={isLoading || hasAuthMail} @@ -185,13 +185,13 @@ export default function Wrap({ context: "form", label: "wrong-email-field", }; - setMail && setMail({ value: initialmail, valid: { status, message } }); + setMail?.({ value: initialmail, valid: { status, message } }); } if (initialmail) { updateEmail(); } - }, [pickupAuthMail]); + }, [pickupAuthMail, initialmail]); const showMailMessage = isLoadingBranches || (pickupAuthMail && lockedMessage && hasBorchk); @@ -201,7 +201,7 @@ export default function Wrap({ isLoadingBranches={isLoadingBranches} name={actualUserName} hasAuthMail={!!pickupAuthMail} - email={email || initialmail} + email={email?.value || initialmail} lockedMessage={lockedMessage} pickupBranch={pickupBranch} invalidClass={invalidClass} From 79ba4eae5fa08d9a7660e41369881b446f7340d0 Mon Sep 17 00:00:00 2001 From: mtni Date: Fri, 26 Jan 2024 14:53:00 +0100 Subject: [PATCH 4/4] ... --- e2e/cypress/e2e/bookmarkorder.cy.js | 2 +- .../_modal/pages/order/ordererinformation/OrdererInformation.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/cypress/e2e/bookmarkorder.cy.js b/e2e/cypress/e2e/bookmarkorder.cy.js index f0cc28fdd..8a8511474 100644 --- a/e2e/cypress/e2e/bookmarkorder.cy.js +++ b/e2e/cypress/e2e/bookmarkorder.cy.js @@ -4,7 +4,7 @@ describe("BookmarkOrderSingle", () => { win.sessionStorage.clear(); }); }); - it.only(`Order a single material from bookmarklist`, () => { + it(`Order a single material from bookmarklist`, () => { cy.visit( "/iframe.html?id=modal-materials--materials-to-order-single-material" ); diff --git a/src/components/_modal/pages/order/ordererinformation/OrdererInformation.js b/src/components/_modal/pages/order/ordererinformation/OrdererInformation.js index 58d69f07c..c848514de 100644 --- a/src/components/_modal/pages/order/ordererinformation/OrdererInformation.js +++ b/src/components/_modal/pages/order/ordererinformation/OrdererInformation.js @@ -171,7 +171,7 @@ export default function Wrap({ const isLoading = isWorkLoading || isPickupBranchLoading || userIsLoading; const map = {}; - authUser?.agencies.forEach((a) => (map[a.id] = a.user?.mail)); + authUser?.agencies?.forEach((a) => (map[a.id] = a.user?.mail)); const pickupAuthMail = map?.[pickupBranch?.agencyId];