@stokr/components-library 3.0.77 → 3.1.0

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.
Files changed (75) hide show
  1. package/dist/components/Input/InputPassword.js +3 -5
  2. package/dist/components/Input/OtpInput.js +1 -3
  3. package/dist/components/MenuNav/MenuNav.styles.js +1 -2
  4. package/dist/components/Modal/Modal.styles.js +2 -3
  5. package/dist/components/Newsletter/Newsletter.js +1 -3
  6. package/dist/components/NotificationCounter/NotificationCounter.styles.js +1 -2
  7. package/dist/components/SmartLink/SmartLink.js +0 -2
  8. package/dist/components/StepController/StepController.js +3 -5
  9. package/dist/components/StepController/StepController.styles.js +102 -1
  10. package/dist/components/StepController/StepControllerProgress.js +1 -1
  11. package/dist/components/Switch/Switch.js +1 -3
  12. package/dist/components/ToDoList/ToDoListTask.js +15 -3
  13. package/dist/components/taxId/register-taxid.js +7 -5
  14. package/dist/index.js +67 -141
  15. package/dist/runtime-config.js +4 -70
  16. package/dist/styles/global.js +1 -2
  17. package/dist/styles/ioniconsStyles.js +13 -10
  18. package/dist/utils/check-todo-status.js +1 -2
  19. package/package.json +8 -14
  20. package/dist/api/authenticationApi.js +0 -13
  21. package/dist/auth/index.js +0 -34
  22. package/dist/components/2FA/Connect2FA.js +0 -58
  23. package/dist/components/2FA/EnterCode.js +0 -74
  24. package/dist/components/2FA/InstallAuthApp.js +0 -68
  25. package/dist/components/2FA/ResetCode.js +0 -34
  26. package/dist/components/2FA/Sucess2FA.js +0 -63
  27. package/dist/components/2FA/disable-2fa-flow.js +0 -104
  28. package/dist/components/2FA/enable-2fa-flow.js +0 -167
  29. package/dist/components/2FA/login-with-otp-flow.js +0 -262
  30. package/dist/components/2FA/main-flow.js +0 -273
  31. package/dist/components/Footer/Footer.js +0 -69
  32. package/dist/components/Footer/Footer.styles.js +0 -277
  33. package/dist/components/Footer/FooterLayout.js +0 -150
  34. package/dist/components/Footer/FooterMenu.js +0 -107
  35. package/dist/components/Footer/FooterMenu.styles.js +0 -334
  36. package/dist/components/ForgotPasswordModal/ForgotPasswordModal.js +0 -121
  37. package/dist/components/Header/Header.js +0 -441
  38. package/dist/components/Header/Header.styles.js +0 -568
  39. package/dist/components/Layout/Layout.js +0 -76
  40. package/dist/components/LoginModal/LoginModal.js +0 -165
  41. package/dist/components/MainMenu/DynamicMainMenu.js +0 -38
  42. package/dist/components/MainMenu/MainMenu.js +0 -220
  43. package/dist/components/MainMenu/MainMenu.styles.js +0 -362
  44. package/dist/components/Modal/NewVentureModal/NewVentureModal.js +0 -273
  45. package/dist/components/RegisterConfirmModal/RegisterConfirmModal.js +0 -74
  46. package/dist/components/RegisterConfirmModal/RegisterConfirmModal.styles.js +0 -20
  47. package/dist/components/RegisterModal/RegisterModal.js +0 -278
  48. package/dist/components/ResetConfirmModal/ResetConfirmModal.js +0 -40
  49. package/dist/components/ResetConfirmModal/ResetConfirmModal.styles.js +0 -41
  50. package/dist/components/ResetPasswordModal/ResetPasswordModal.js +0 -145
  51. package/dist/components/StepsProgress/StepIndicator.js +0 -40
  52. package/dist/components/StepsProgress/StepIndicator.styles.js +0 -69
  53. package/dist/components/StepsProgress/StepsProgress.js +0 -67
  54. package/dist/components/StepsProgress/StepsProgress.styles.js +0 -105
  55. package/dist/components/TermsModal/TermsModal.js +0 -145
  56. package/dist/components/TermsModal/_styles.js +0 -313
  57. package/dist/components/VerifyEmailModal/VerifyEmailModal.js +0 -122
  58. package/dist/components/headerHo/HeaderHo.js +0 -707
  59. package/dist/config.js +0 -33
  60. package/dist/context/Auth.js +0 -423
  61. package/dist/context/AuthContext.js +0 -1016
  62. package/dist/firebase-config.js +0 -56
  63. package/dist/hooks/useNewVentureForm.js +0 -235
  64. package/dist/static/images/background3.png.js +0 -4
  65. package/dist/static/images/google_auth.png.js +0 -4
  66. package/dist/static/images/iso27001-black.svg.js +0 -4
  67. package/dist/static/images/mangopay.svg.js +0 -4
  68. package/dist/static/images/social/Facebook_Logo.png.js +0 -4
  69. package/dist/static/images/social/LI-In-Bug.png.js +0 -4
  70. package/dist/static/images/social/Telegram-Logo.png.js +0 -4
  71. package/dist/static/images/social/X-logo-black.png.js +0 -4
  72. package/dist/static/images/social/youtube_social_circle_red.png.js +0 -4
  73. package/dist/utils/show-account-locked-modal.js +0 -23
  74. package/dist/utils/user-identity.js +0 -10
  75. package/dist/utils/withRouter.js +0 -26
@@ -1,167 +0,0 @@
1
- import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
- import { useContext, useState, useRef, useLayoutEffect, useEffect } from "react";
3
- import { Modal } from "../Modal/Modal.js";
4
- import stdin_default$2 from "../StepController/StepController.js";
5
- import { StepControllerProvider, StepControllerConsumer } from "../StepController/StepControllerContext.js";
6
- import stdin_default$3 from "./InstallAuthApp.js";
7
- import stdin_default$4 from "./Connect2FA.js";
8
- import stdin_default$5 from "./EnterCode.js";
9
- import { AuthContext } from "../../context/AuthContext.js";
10
- import stdin_default$1 from "./Sucess2FA.js";
11
- import fetchData from "../../api/fetchData.js";
12
- import { getFirebaseAuth } from "../../firebase-config.js";
13
- import { ModalInner, ModalBack } from "../Modal/Modal.styles.js";
14
- const stepsNames = ["app", "connect", "enter-code"];
15
- const Enable2FAFlow = ({ showFlow, setShowFlow, onSuccess, totpData, onRequiresRecentLoginError }) => {
16
- const { user, firebaseUser, enrollUserToTotp, refreshIdToken } = useContext(AuthContext);
17
- const [showSuccess, setshowSuccess] = useState(false);
18
- const [flowKey, setFlowKey] = useState(0);
19
- const prevShowFlowRef = useRef(showFlow);
20
- const isFirstMountRef = useRef(true);
21
- const [popupError, setpopupError] = useState({
22
- popup: void 0,
23
- message: void 0
24
- });
25
- useLayoutEffect(() => {
26
- if (isFirstMountRef.current) {
27
- isFirstMountRef.current = false;
28
- prevShowFlowRef.current = showFlow;
29
- return;
30
- }
31
- if (showFlow && !prevShowFlowRef.current) {
32
- setFlowKey((key) => key + 1);
33
- setshowSuccess(false);
34
- setpopupError({ popup: void 0, message: void 0 });
35
- }
36
- prevShowFlowRef.current = showFlow;
37
- }, [showFlow]);
38
- const refreshToken = async () => {
39
- try {
40
- refreshIdToken();
41
- } catch (error) {
42
- console.log("🚀 ~ error in refreshToken:", error);
43
- }
44
- };
45
- useEffect(() => {
46
- if (user) {
47
- refreshToken();
48
- }
49
- }, [user]);
50
- const onSubmit = async (data) => {
51
- if (!data) return console.log("not enough data");
52
- const mfaUser = firebaseUser || getFirebaseAuth()?.currentUser || user;
53
- if (!mfaUser) {
54
- setpopupError({
55
- popup: "enter2fa",
56
- message: "Unable to complete 2FA setup. Please log in again and retry."
57
- });
58
- return;
59
- }
60
- try {
61
- await enrollUserToTotp(mfaUser, totpData.totpSecret, data.otpInput, user?.displayName || mfaUser?.displayName);
62
- setshowSuccess(true);
63
- try {
64
- await fetchData("auth/enable-2fa-email");
65
- } catch (error) {
66
- console.log("🚀 ~ error while sending email:", error);
67
- }
68
- } catch (error) {
69
- console.log("🚀 ~ file: enable-2fa-flow.js:60 ~ error:", error);
70
- if (error.code === "auth/invalid-verification-code") {
71
- setpopupError({
72
- popup: "enter2fa",
73
- message: "That’s not the right 2FA code. Try again"
74
- });
75
- return { otpInput: "Invalid code" };
76
- } else if (error.code === "auth/requires-recent-login") {
77
- onRequiresRecentLoginError?.();
78
- } else {
79
- setpopupError({
80
- popup: "enter2fa",
81
- message: `${error?.message ? error?.message : "Something went wrong. Try again?"}`
82
- });
83
- }
84
- }
85
- };
86
- const onBackButtonClick = (stepController, prevStepIndex) => {
87
- stepController.changeStep(stepsNames[prevStepIndex], prevStepIndex);
88
- };
89
- return /* @__PURE__ */ jsx(Modal, { isOpen: showFlow, onClose: () => setShowFlow(false), children: /* @__PURE__ */ jsx(ModalInner, { noPadding: true, children: showSuccess ? /* @__PURE__ */ jsx(
90
- stdin_default$1,
91
- {
92
- continueButtonId: "enable-2fa-success-continue-btn",
93
- continueButtonDataCy: "enable-2fa-success-continue",
94
- onClick: () => {
95
- if (onSuccess) onSuccess();
96
- setshowSuccess(false);
97
- setShowFlow(false);
98
- },
99
- subTitleLeft: "Your log in 2FA authentication is now set",
100
- textRight: "You will now be asked for your 2FA code next time you log in."
101
- }
102
- ) : /* @__PURE__ */ jsx(StepControllerProvider, { initialStep: stepsNames[0], children: /* @__PURE__ */ jsx(StepControllerConsumer, { children: (stepController) => {
103
- const prevStepIndex = stepController.activeStepIndex - 1;
104
- return /* @__PURE__ */ jsxs(Fragment, { children: [
105
- /* @__PURE__ */ jsx(
106
- ModalBack,
107
- {
108
- onClick: () => onBackButtonClick(stepController, prevStepIndex),
109
- hide: stepController.activeStepIndex === 0
110
- }
111
- ),
112
- /* @__PURE__ */ jsxs(
113
- stdin_default$2,
114
- {
115
- stepsProgressList: [
116
- {
117
- id: "app",
118
- dataCy: "enable-2fa-progress-app",
119
- handleClick: () => {
120
- stepController.changeStep("app", 0);
121
- }
122
- },
123
- {
124
- id: "connect",
125
- dataCy: "enable-2fa-progress-connect",
126
- handleClick: () => {
127
- stepController.changeStep("connect", 1);
128
- }
129
- },
130
- {
131
- id: "enter-code",
132
- dataCy: "enable-2fa-progress-enter-code",
133
- handleClick: () => stepController.changeStep("enter-code", 2)
134
- }
135
- ],
136
- ...stepController,
137
- children: [
138
- /* @__PURE__ */ jsx(stdin_default$3, { id: "app", changeStep: () => stepController.changeStep("connect", 1, 0) }),
139
- /* @__PURE__ */ jsx(
140
- stdin_default$4,
141
- {
142
- id: "connect",
143
- changeStep: () => stepController.changeStep("enter-code", 2, 1),
144
- totpData,
145
- user
146
- }
147
- ),
148
- /* @__PURE__ */ jsx(
149
- stdin_default$5,
150
- {
151
- id: "enter-code",
152
- changeStep: () => {
153
- },
154
- popupError,
155
- onFormSend: onSubmit
156
- }
157
- )
158
- ]
159
- }
160
- )
161
- ] });
162
- } }) }, flowKey) }) });
163
- };
164
- var stdin_default = Enable2FAFlow;
165
- export {
166
- stdin_default as default
167
- };
@@ -1,262 +0,0 @@
1
- import { jsxs, jsx } from "react/jsx-runtime";
2
- import PropTypes from "prop-types";
3
- import stdin_default$2 from "./EnterCode.js";
4
- import stdin_default$3 from "./ResetCode.js";
5
- import { Layout } from "../Layout/Layout.js";
6
- import { useNavigate } from "react-router-dom";
7
- import stdin_default$1 from "../LoginModal/LoginModal.js";
8
- import { AuthContext } from "../../context/AuthContext.js";
9
- import background from "../../static/images/background3.png.js";
10
- import { hasLoggedInSession } from "../../utils/user-identity.js";
11
- import { authenticationApi } from "../../api/authenticationApi.js";
12
- import { getConfig, getPlatformURL } from "../../runtime-config.js";
13
- import { useContext, useRef, useState, useEffect } from "react";
14
- import stdin_default$4 from "../ForgotPasswordModal/ForgotPasswordModal.js";
15
- import { isAccountLockedError, showAccountLockedModal } from "../../utils/show-account-locked-modal.js";
16
- import { navigateToHref } from "../../routing/navigate-app.js";
17
- const closedModalsState = {
18
- login: false,
19
- enter2fa: false,
20
- forgot: false,
21
- resetCode: false
22
- };
23
- const LoginWithOTP = ({ withBackground, useRelativePathForMenu = false, onLoginSuccess }) => {
24
- const navigate = useNavigate();
25
- const { user, loginUser, getUser, waitingFor2fa, firebaseError, loginUserWithTotp, reset2faFlow, logoutUser } = useContext(AuthContext);
26
- const loginSuccessHandledRef = useRef(false);
27
- const [isModalOpen, setIsModalOpen] = useState({
28
- login: true,
29
- enter2fa: false,
30
- forgot: false,
31
- resetCode: false
32
- });
33
- const [isActionLoading, setIsActionLoading] = useState();
34
- const [popupError, setPopupError] = useState({
35
- popup: void 0,
36
- message: void 0
37
- });
38
- const [popupSuccess, setPopupSuccess] = useState({
39
- popup: void 0,
40
- message: void 0
41
- });
42
- const switchOpenModal = (prevModalId, nextModalId) => {
43
- setIsModalOpen((prev) => ({
44
- ...prev,
45
- [prevModalId]: false,
46
- [nextModalId]: true
47
- }));
48
- };
49
- useEffect(() => {
50
- if (waitingFor2fa) {
51
- setIsModalOpen((prev) => ({
52
- ...prev,
53
- login: false,
54
- enter2fa: true
55
- }));
56
- }
57
- }, [waitingFor2fa]);
58
- useEffect(() => {
59
- if (!hasLoggedInSession(user) || waitingFor2fa) {
60
- loginSuccessHandledRef.current = false;
61
- return;
62
- }
63
- setIsModalOpen(closedModalsState);
64
- if (onLoginSuccess && !loginSuccessHandledRef.current) {
65
- loginSuccessHandledRef.current = true;
66
- onLoginSuccess(user);
67
- }
68
- }, [user, waitingFor2fa, onLoginSuccess]);
69
- const handleSetPopupSuccess = (popup, message) => {
70
- setPopupSuccess({ popup, message });
71
- };
72
- const clearPopupSuccess = () => {
73
- setPopupSuccess({
74
- popup: void 0,
75
- message: void 0
76
- });
77
- };
78
- const handleSetPopupError = (popup, message) => {
79
- setPopupError({ popup, message });
80
- };
81
- const clearPopupError = () => {
82
- setPopupError({
83
- popup: void 0,
84
- message: void 0
85
- });
86
- };
87
- const backgroundProp = `url(${background}) left top no-repeat`;
88
- return /* @__PURE__ */ jsxs(Layout, { noHeader: true, noFooter: true, useRelativePathForMenu, children: [
89
- /* @__PURE__ */ jsx(
90
- stdin_default$1,
91
- {
92
- isActionLoading,
93
- popupError,
94
- background: withBackground && backgroundProp,
95
- isModalOpen: isModalOpen.login,
96
- onModalClose: () => {
97
- navigateToHref(navigate, getPlatformURL());
98
- },
99
- onModalSwitch: () => {
100
- navigateToHref(navigate, getConfig("registerUrl"));
101
- },
102
- onForgotPassword: () => {
103
- switchOpenModal("login", "forgot");
104
- clearPopupError();
105
- setIsActionLoading(void 0);
106
- },
107
- logoutUser,
108
- onFormSend: async ({ email, password }) => {
109
- clearPopupError();
110
- setIsActionLoading("login");
111
- try {
112
- if (password.length > 128) {
113
- handleSetPopupError("login", "Your password cannot exceed 128 characters");
114
- return;
115
- }
116
- await loginUser(email, password);
117
- await getUser();
118
- clearPopupError();
119
- } catch (error) {
120
- const errorMessage = error?.message;
121
- if (error?.code === "auth/multi-factor-auth-required") {
122
- clearPopupError();
123
- return;
124
- }
125
- if (isAccountLockedError(error)) {
126
- clearPopupError();
127
- setIsModalOpen((prev) => ({
128
- ...prev,
129
- login: false
130
- }));
131
- await showAccountLockedModal({
132
- background: withBackground ? backgroundProp : void 0
133
- });
134
- setIsModalOpen((prev) => ({
135
- ...prev,
136
- login: true
137
- }));
138
- return;
139
- }
140
- if (errorMessage) {
141
- handleSetPopupError("login", errorMessage);
142
- } else {
143
- handleSetPopupError("login", "Oops. Something's not right there. Try again?");
144
- }
145
- } finally {
146
- setIsActionLoading(void 0);
147
- }
148
- }
149
- }
150
- ),
151
- /* @__PURE__ */ jsx(
152
- stdin_default$2,
153
- {
154
- isModal: true,
155
- isActionLoading,
156
- popupError,
157
- isModalOpen: isModalOpen.enter2fa,
158
- background: withBackground && backgroundProp,
159
- onModalClose: () => {
160
- reset2faFlow();
161
- switchOpenModal("enter2fa", "login");
162
- clearPopupError();
163
- setIsActionLoading(void 0);
164
- },
165
- onModalSwitch: () => {
166
- switchOpenModal("enter2fa", "resetCode");
167
- clearPopupError();
168
- setIsActionLoading(void 0);
169
- },
170
- onFormSend: async ({ otpInput }) => {
171
- setIsActionLoading("enter2fa");
172
- try {
173
- await loginUserWithTotp(otpInput, firebaseError);
174
- await getUser();
175
- clearPopupError();
176
- setIsModalOpen(closedModalsState);
177
- } catch (error) {
178
- if (error?.code === "auth/invalid-verification-code") {
179
- handleSetPopupError("enter2fa", "The verification code is not correct. Try again?");
180
- } else if (error?.code === "auth/code-expired") {
181
- handleSetPopupError("enter2fa", "Time out. Please restart the flow and log in again");
182
- } else {
183
- handleSetPopupError("enter2fa", error?.message);
184
- }
185
- } finally {
186
- setIsActionLoading(void 0);
187
- }
188
- }
189
- }
190
- ),
191
- /* @__PURE__ */ jsx(
192
- stdin_default$3,
193
- {
194
- isModalOpen: isModalOpen.resetCode,
195
- background: withBackground && backgroundProp,
196
- onModalClose: () => {
197
- switchOpenModal("resetCode", "login");
198
- clearPopupError();
199
- setIsActionLoading(void 0);
200
- },
201
- onModalSwitch: () => {
202
- switchOpenModal("resetCode", "enter2fa");
203
- }
204
- }
205
- ),
206
- /* @__PURE__ */ jsx(
207
- stdin_default$4,
208
- {
209
- isActionLoading,
210
- popupError,
211
- background: withBackground && backgroundProp,
212
- popupSuccess,
213
- isModalOpen: isModalOpen.forgot,
214
- onModalClose: () => {
215
- switchOpenModal("forgot", "login");
216
- clearPopupError();
217
- clearPopupSuccess();
218
- setIsActionLoading(void 0);
219
- },
220
- onModalSwitch: () => {
221
- switchOpenModal("forgot", "login");
222
- clearPopupError();
223
- clearPopupSuccess();
224
- setIsActionLoading(void 0);
225
- },
226
- onFormSend: async ({ email }) => {
227
- clearPopupError();
228
- setIsActionLoading("forgot");
229
- try {
230
- await authenticationApi.post("forgotPass", {
231
- email
232
- });
233
- handleSetPopupSuccess(
234
- "forgot",
235
- `We sent a message to ${email} (you might need to check your junk or spam folder) — tap the link inside to create a new password.`
236
- );
237
- setIsActionLoading(void 0);
238
- } catch (error) {
239
- let errorMessage = `Too many requests. Please try again later.`;
240
- console.log(error?.response);
241
- if (error?.response?.status === 429) {
242
- errorMessage = error.response.data?.message;
243
- }
244
- handleSetPopupError("forgot", errorMessage);
245
- setIsActionLoading(void 0);
246
- }
247
- }
248
- }
249
- )
250
- ] });
251
- };
252
- LoginWithOTP.propTypes = {
253
- withBackground: PropTypes.bool,
254
- useRelativePathForMenu: PropTypes.bool,
255
- /** Called once when login (and optional 2FA) completes and the user session is ready. */
256
- onLoginSuccess: PropTypes.func
257
- };
258
- var stdin_default = LoginWithOTP;
259
- export {
260
- LoginWithOTP,
261
- stdin_default as default
262
- };
@@ -1,273 +0,0 @@
1
- import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
- import React__default, { useContext, useState, useRef, useEffect } from "react";
3
- import PropTypes from "prop-types";
4
- import { AuthContext } from "../../context/AuthContext.js";
5
- import { ComponentWrapper } from "../ComponentWrapper/ComponentWrapper.styles.js";
6
- import stdin_default$1 from "../Switch/Switch.js";
7
- import { Text } from "../Text/Text.styles.js";
8
- import stdin_default$5 from "./login-with-otp-flow.js";
9
- import stdin_default$2 from "./enable-2fa-flow.js";
10
- import stdin_default$3 from "./disable-2fa-flow.js";
11
- import { colors } from "../../styles/colors.js";
12
- import { InfoIcon } from "../InfoIcon/InfoIcon.js";
13
- import { Modal } from "../Modal/Modal.js";
14
- import stdin_default$4 from "./Sucess2FA.js";
15
- import { ModalInner } from "../Modal/Modal.styles.js";
16
- import { showProgress } from "../Modal/SuccessModal/SuccessModal.js";
17
- const SUPPORT_URL = "https://support.stokr.io/";
18
- const Main2FAFlow = ({
19
- onRequiresRecentLoginError,
20
- open2faflow,
21
- onLoginAgainClick,
22
- openDisable2faflow,
23
- allowDisable2FA = false,
24
- title = "SET UP YOUR LOG IN TWO FACTOR AUTHENTICATION",
25
- subtitle = "Protect your account with an additional layer of security to log in",
26
- showSwitch = true,
27
- customComponent,
28
- onFlowClose,
29
- recentLoginTitle = "LOG IN AGAIN",
30
- recentLoginSubtitle = "To continue please log in again and set up your two factor authentication",
31
- recentLoginCTA = "Log in again",
32
- showInlineLoginOnLogout = true
33
- }) => {
34
- const { user, checkMfaEnrollment, userMfaEnrollment, generateTotpSecret, logoutUser } = useContext(AuthContext);
35
- const [isFlowopen, setIsFlowOpen] = useState({
36
- enable2fa: open2faflow || false,
37
- disable2fa: allowDisable2FA && (openDisable2faflow || false),
38
- requiresRecentLogin: false
39
- });
40
- const [is2FAEnabled, setis2FAEnabled] = useState(false);
41
- const [successMessage, setsuccessMessage] = useState();
42
- const [isLoginRequired, setisLoginRequired] = useState(false);
43
- const [totpData, settotpData] = useState();
44
- const [awaitingReauthFor2fa, setAwaitingReauthFor2fa] = useState(false);
45
- const enable2faCompletedRef = useRef(false);
46
- const disable2faCompletedRef = useRef(false);
47
- const onRequiresRecentLoginErrorHandler = () => {
48
- setIsFlowOpen({
49
- requiresRecentLogin: true,
50
- enable2fa: false,
51
- disable2fa: false
52
- });
53
- onRequiresRecentLoginError?.();
54
- };
55
- const generateTotp = async () => {
56
- try {
57
- const response = await generateTotpSecret();
58
- settotpData(response);
59
- } catch (error) {
60
- if (error.code === "auth/requires-recent-login" || error.code === "auth/unsupported-first-factor") {
61
- setisLoginRequired(true);
62
- if (isFlowopen.enable2fa && !isFlowopen.requiresRecentLogin) {
63
- onRequiresRecentLoginErrorHandler();
64
- }
65
- }
66
- }
67
- };
68
- useEffect(() => {
69
- if (userMfaEnrollment?.length > 0) {
70
- setis2FAEnabled(true);
71
- } else if (user && !awaitingReauthFor2fa) {
72
- checkMfaEnrollment();
73
- generateTotp();
74
- }
75
- }, [user, userMfaEnrollment, awaitingReauthFor2fa]);
76
- useEffect(() => {
77
- if (!user || !awaitingReauthFor2fa) return;
78
- setAwaitingReauthFor2fa(false);
79
- setisLoginRequired(false);
80
- setIsFlowOpen((prev) => ({
81
- ...prev,
82
- requiresRecentLogin: false,
83
- enable2fa: true
84
- }));
85
- checkMfaEnrollment();
86
- generateTotp();
87
- }, [user, awaitingReauthFor2fa]);
88
- useEffect(() => {
89
- let timeoutId;
90
- if (successMessage) {
91
- timeoutId = setTimeout(setsuccessMessage, 400);
92
- }
93
- return () => {
94
- if (timeoutId != null) clearTimeout(timeoutId);
95
- };
96
- }, [successMessage]);
97
- const switchOpenFlow = (prevFlowId, nextFlowId) => {
98
- setIsFlowOpen((prev) => ({
99
- ...prev,
100
- [prevFlowId]: false,
101
- [nextFlowId]: true
102
- }));
103
- };
104
- const showDisable2faBlockedModal = () => showProgress({
105
- title: "TWO-FACTOR AUTHENTICATION REQUIRED",
106
- subtitle: /* @__PURE__ */ jsxs(Fragment, { children: [
107
- "Under our security policy, two-factor authentication is required on all accounts and cannot be turned off. To reset your method, contact our",
108
- " ",
109
- /* @__PURE__ */ jsx("a", { href: SUPPORT_URL, target: "_blank", rel: "noreferrer", style: { textDecoration: "underline" }, children: /* @__PURE__ */ jsx("u", { children: "support team" }) }),
110
- "."
111
- ] }),
112
- maxWidth: "820px"
113
- });
114
- const handleFlowClose = (flowId, completed = false) => {
115
- setIsFlowOpen((prev) => ({ ...prev, [flowId]: false }));
116
- if (onFlowClose) onFlowClose({ flow: flowId, completed });
117
- };
118
- const onEnable2FASuccess = async () => {
119
- enable2faCompletedRef.current = true;
120
- setis2FAEnabled(true);
121
- checkMfaEnrollment();
122
- setsuccessMessage("Your log in 2FA authentication is now set");
123
- };
124
- const onDisable2FASuccess = async () => {
125
- disable2faCompletedRef.current = true;
126
- setis2FAEnabled(false);
127
- checkMfaEnrollment();
128
- setsuccessMessage("Your log in 2FA authentication is removed");
129
- };
130
- const handleLoginAgain = async () => {
131
- setIsFlowOpen((prev) => ({
132
- ...prev,
133
- requiresRecentLogin: false,
134
- enable2fa: false,
135
- disable2fa: false
136
- }));
137
- await logoutUser();
138
- setAwaitingReauthFor2fa(true);
139
- onLoginAgainClick?.();
140
- };
141
- const flowActions = {
142
- openEnable2FA: () => switchOpenFlow("disable2fa", "enable2fa"),
143
- openDisable2FA: () => {
144
- if (!is2FAEnabled) return;
145
- if (!allowDisable2FA) {
146
- void showDisable2faBlockedModal();
147
- return;
148
- }
149
- switchOpenFlow("enable2fa", "disable2fa");
150
- },
151
- closeFlows: () => {
152
- const wasOpen = Object.keys(isFlowopen).find((key) => isFlowopen[key]);
153
- setIsFlowOpen({
154
- enable2fa: false,
155
- disable2fa: false,
156
- requiresRecentLogin: false
157
- });
158
- if (wasOpen) {
159
- onFlowClose?.(wasOpen);
160
- }
161
- },
162
- is2FAEnabled,
163
- isFlowOpen: isFlowopen
164
- };
165
- return /* @__PURE__ */ jsxs(Fragment, { children: [
166
- /* @__PURE__ */ jsx(ComponentWrapper, { alignVertically: true, noPaddingHorizontal: true, children: /* @__PURE__ */ jsx(Text, { children: /* @__PURE__ */ jsx("h5", { children: title }) }) }),
167
- /* @__PURE__ */ jsx(Text, { children: /* @__PURE__ */ jsx("p", { children: subtitle }) }),
168
- showSwitch && /* @__PURE__ */ jsxs(ComponentWrapper, { noPaddingHorizontal: true, children: [
169
- /* @__PURE__ */ jsx(
170
- InfoIcon,
171
- {
172
- position: "top",
173
- html: is2FAEnabled ? "Enabled" : "Disabled",
174
- noIcon: true,
175
- noMarginLeft: true,
176
- disabled: isFlowopen.enable2fa || isFlowopen.disable2fa,
177
- children: /* @__PURE__ */ jsx(
178
- stdin_default$1,
179
- {
180
- dataCy: "2fa-settings-toggle",
181
- value1: "disabled",
182
- value2: "enabled",
183
- value1Color: colors.orangishRed,
184
- value2Color: colors.freshGreen,
185
- value: is2FAEnabled ? "enabled" : "disabled",
186
- revertToPrevious: true,
187
- hideValues: true,
188
- indicatorStyle: { margin: 0 },
189
- handleChange: (value) => {
190
- if (isLoginRequired && value === "enabled") {
191
- setIsFlowOpen({
192
- requiresRecentLogin: true,
193
- enable2fa: false,
194
- disable2fa: false
195
- });
196
- } else if (value === "enabled") {
197
- switchOpenFlow("disable2fa", "enable2fa");
198
- } else if (value === "disabled") {
199
- if (!allowDisable2FA) {
200
- void showDisable2faBlockedModal();
201
- return;
202
- }
203
- switchOpenFlow("enable2fa", "disable2fa");
204
- }
205
- }
206
- }
207
- )
208
- }
209
- ),
210
- successMessage && /* @__PURE__ */ jsx(Text, { small: true, success: true, style: { position: "absolute", bottom: 0, left: 0 }, children: /* @__PURE__ */ jsx("p", { children: successMessage }) })
211
- ] }),
212
- customComponent && (typeof customComponent === "function" ? customComponent(flowActions) : React__default.isValidElement(customComponent) ? React__default.createElement(customComponent.type, {
213
- ...customComponent.props,
214
- flowActions
215
- }) : customComponent),
216
- isFlowopen.enable2fa && /* @__PURE__ */ jsx(
217
- stdin_default$2,
218
- {
219
- showFlow: isFlowopen.enable2fa,
220
- setShowFlow: (value) => {
221
- if (!value) {
222
- handleFlowClose("enable2fa", enable2faCompletedRef.current);
223
- } else {
224
- setIsFlowOpen({ ...isFlowopen, enable2fa: value });
225
- }
226
- },
227
- totpData,
228
- onRequiresRecentLoginError: onRequiresRecentLoginErrorHandler,
229
- onSuccess: onEnable2FASuccess
230
- }
231
- ),
232
- allowDisable2FA && isFlowopen.disable2fa && /* @__PURE__ */ jsx(
233
- stdin_default$3,
234
- {
235
- showFlow: isFlowopen.disable2fa,
236
- setShowFlow: (value) => {
237
- if (!value) {
238
- handleFlowClose("disable2fa", disable2faCompletedRef.current);
239
- } else {
240
- setIsFlowOpen({ ...isFlowopen, disable2fa: value });
241
- }
242
- },
243
- onRequiresRecentLoginError: onRequiresRecentLoginErrorHandler,
244
- onSuccess: onDisable2FASuccess
245
- }
246
- ),
247
- isFlowopen.requiresRecentLogin && /* @__PURE__ */ jsx(Modal, { isOpen: isFlowopen.requiresRecentLogin, onClose: () => handleFlowClose("requiresRecentLogin"), children: /* @__PURE__ */ jsx(ModalInner, { noPadding: true, children: /* @__PURE__ */ jsx(
248
- stdin_default$4,
249
- {
250
- continueButtonId: "2fa-requires-recent-login-btn",
251
- continueButtonDataCy: "2fa-requires-recent-login-submit",
252
- onClick: () => {
253
- void handleLoginAgain();
254
- },
255
- titleText: recentLoginTitle,
256
- subTitleLeft: recentLoginSubtitle,
257
- buttonText: recentLoginCTA
258
- }
259
- ) }) }),
260
- !showInlineLoginOnLogout ? null : !user && /* @__PURE__ */ jsx(stdin_default$5, {})
261
- ] });
262
- };
263
- Main2FAFlow.propTypes = {
264
- onRequiresRecentLoginError: PropTypes.func,
265
- allowDisable2FA: PropTypes.bool,
266
- /** Called when any flow/modal is closed. Receives the flowId: 'enable2fa' | 'disable2fa' | 'requiresRecentLogin' */
267
- onFlowClose: PropTypes.func
268
- };
269
- var stdin_default = Main2FAFlow;
270
- export {
271
- Main2FAFlow,
272
- stdin_default as default
273
- };