@vtex/faststore-plugin-buyer-portal 2.0.45 → 2.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/features/shared/utils/constants.ts +1 -1
- package/src/features/users/components/CreateUserDrawerWithUsername/CreateUserDrawerWithUsername.tsx +8 -9
- package/src/features/users/utils/__tests__/resolveAccessCodeRecipient.test.ts +38 -0
- package/src/features/users/utils/resolveAccessCodeRecipient.ts +26 -0
package/package.json
CHANGED
package/src/features/users/components/CreateUserDrawerWithUsername/CreateUserDrawerWithUsername.tsx
CHANGED
|
@@ -18,6 +18,7 @@ import { buyerPortalRoutes } from "../../../shared/utils/buyerPortalRoutes";
|
|
|
18
18
|
import { normalizePhoneNumber } from "../../../shared/utils/phoneNumber";
|
|
19
19
|
import { useAddUserToOrgUnit, useResetPassword } from "../../hooks";
|
|
20
20
|
import { detectLoginType } from "../../utils/detectLoginType";
|
|
21
|
+
import { resolveAccessCodeRecipient } from "../../utils/resolveAccessCodeRecipient";
|
|
21
22
|
import {
|
|
22
23
|
EMPTY_FORM,
|
|
23
24
|
UserFormFields,
|
|
@@ -134,13 +135,6 @@ export const CreateUserDrawerWithUsername = ({
|
|
|
134
135
|
};
|
|
135
136
|
};
|
|
136
137
|
|
|
137
|
-
const getEffectiveEmail = () => {
|
|
138
|
-
if (loginType === "email") {
|
|
139
|
-
return useLoginAsTransactional ? login : transactionalEmail;
|
|
140
|
-
}
|
|
141
|
-
return email;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
138
|
const handleResetPasswordSuccess = useCallback(
|
|
145
139
|
(data: { accessCode: string }) => {
|
|
146
140
|
setAccessToken(data.accessCode);
|
|
@@ -174,7 +168,12 @@ export const CreateUserDrawerWithUsername = ({
|
|
|
174
168
|
org_unit_id: orgUnitId,
|
|
175
169
|
});
|
|
176
170
|
|
|
177
|
-
const effectiveEmail =
|
|
171
|
+
const effectiveEmail = resolveAccessCodeRecipient({
|
|
172
|
+
login,
|
|
173
|
+
email,
|
|
174
|
+
transactionalEmail,
|
|
175
|
+
useLoginAsTransactional,
|
|
176
|
+
});
|
|
178
177
|
const shouldResetPassword =
|
|
179
178
|
!effectiveEmail?.trim() || drawerState === "CONFIRM_SHARED_EMAIL";
|
|
180
179
|
|
|
@@ -186,7 +185,7 @@ export const CreateUserDrawerWithUsername = ({
|
|
|
186
185
|
pushToast({
|
|
187
186
|
title: t("users.create.toasts.userAddedSuccessfully"),
|
|
188
187
|
message: `${t("users.create.toasts.accessCodeSent", [
|
|
189
|
-
`[${
|
|
188
|
+
`[${effectiveEmail}](mailto:${effectiveEmail})`,
|
|
190
189
|
])}\n${t("shared.messages.changesTimeout")}`,
|
|
191
190
|
status: "INFO",
|
|
192
191
|
icon: (
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { resolveAccessCodeRecipient } from "../resolveAccessCodeRecipient";
|
|
4
|
+
|
|
5
|
+
describe("resolveAccessCodeRecipient", () => {
|
|
6
|
+
it("uses the login when it is an email and the email field stays empty", () => {
|
|
7
|
+
expect(
|
|
8
|
+
resolveAccessCodeRecipient({
|
|
9
|
+
login: "novo.usuario@empresa.com",
|
|
10
|
+
email: "",
|
|
11
|
+
transactionalEmail: "",
|
|
12
|
+
useLoginAsTransactional: true,
|
|
13
|
+
})
|
|
14
|
+
).toBe("novo.usuario@empresa.com");
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("uses the transactional email when login is an email and the checkbox is off", () => {
|
|
18
|
+
expect(
|
|
19
|
+
resolveAccessCodeRecipient({
|
|
20
|
+
login: "novo.usuario@empresa.com",
|
|
21
|
+
email: "",
|
|
22
|
+
transactionalEmail: "avisos@empresa.com",
|
|
23
|
+
useLoginAsTransactional: false,
|
|
24
|
+
})
|
|
25
|
+
).toBe("avisos@empresa.com");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("uses the email field when login is a phone or username", () => {
|
|
29
|
+
expect(
|
|
30
|
+
resolveAccessCodeRecipient({
|
|
31
|
+
login: "15551234567",
|
|
32
|
+
email: "pessoa@empresa.com",
|
|
33
|
+
transactionalEmail: "",
|
|
34
|
+
useLoginAsTransactional: true,
|
|
35
|
+
})
|
|
36
|
+
).toBe("pessoa@empresa.com");
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { detectLoginType } from "./detectLoginType";
|
|
2
|
+
|
|
3
|
+
export interface AccessCodeRecipientInput {
|
|
4
|
+
login: string;
|
|
5
|
+
email: string;
|
|
6
|
+
transactionalEmail: string;
|
|
7
|
+
useLoginAsTransactional: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Address that receives the first-access code.
|
|
12
|
+
* When login is an email, the separate email field is hidden, so the
|
|
13
|
+
* recipient is the login or the transactional override.
|
|
14
|
+
*/
|
|
15
|
+
export function resolveAccessCodeRecipient({
|
|
16
|
+
login,
|
|
17
|
+
email,
|
|
18
|
+
transactionalEmail,
|
|
19
|
+
useLoginAsTransactional,
|
|
20
|
+
}: AccessCodeRecipientInput): string {
|
|
21
|
+
if (detectLoginType(login.trim()) === "email") {
|
|
22
|
+
return useLoginAsTransactional ? login : transactionalEmail;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return email;
|
|
26
|
+
}
|