Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bibdk2021 2418 change init email according to pickupbranch #1331

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -54,9 +57,11 @@ export function OrdererInformation({
label: "email-placeholder",
})}
invalidClass={invalidClass}
value={email?.value || ""}
disabled={isLoading || hasAuthMail}
value={email || ""}
id="order-user-email"
onChange={onMailChange}
readOnly={isLoading || hasAuthMail}
skeleton={isLoadingBranches && !email}
/>

Expand Down Expand Up @@ -165,35 +170,38 @@ 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 = {};
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?.({ value: initialmail, valid: { status, message } });
}

if (initialmail) {
updateEmail();
}
}, [pickupAuthMail, initialmail]);

const showMailMessage =
isLoadingBranches || (authUser?.mail && lockedMessage && hasBorchk);
isLoadingBranches || (pickupAuthMail && lockedMessage && hasBorchk);

return (
<OrdererInformation
isLoadingBranches={isLoadingBranches}
name={actualUserName}
hasAuthMail={!!authUser?.mail}
email={email || initialmail}
hasAuthMail={!!pickupAuthMail}
email={email?.value || initialmail}
lockedMessage={lockedMessage}
pickupBranch={pickupBranch}
invalidClass={invalidClass}
Expand Down
6 changes: 6 additions & 0 deletions src/lib/api/user.fragments.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ export function basic() {
demandDrivenAcquisition
}
agencies {
id
name
type
hitcount
user {
mail
}
result {
branchId
agencyId
Expand Down