@saasquatch/mint-components 1.8.5-3 → 1.8.5-31

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 (38) hide show
  1. package/dist/cjs/sqm-big-stat_38.cjs.entry.js +2 -2
  2. package/dist/cjs/{sqm-portal-verify-email-view-ce552bbc.js → sqm-portal-verify-email-view-4f7063ff.js} +9 -1
  3. package/dist/cjs/sqm-portal-verify-email.cjs.entry.js +81 -37
  4. package/dist/cjs/sqm-stencilbook.cjs.entry.js +5 -3
  5. package/dist/collection/components/sqm-link-button/sqm-link-button-view.js +2 -2
  6. package/dist/collection/components/sqm-portal-verify-email/PortalVerifyEmail.stories.js +2 -0
  7. package/dist/collection/components/sqm-portal-verify-email/sqm-portal-verify-email-view.js +9 -1
  8. package/dist/collection/components/sqm-portal-verify-email/sqm-portal-verify-email.js +1 -1
  9. package/dist/collection/components/sqm-portal-verify-email/usePortalVerifyEmail.js +93 -37
  10. package/dist/esm/sqm-big-stat_38.entry.js +2 -2
  11. package/dist/esm/{sqm-portal-verify-email-view-283bf637.js → sqm-portal-verify-email-view-4c562714.js} +9 -1
  12. package/dist/esm/sqm-portal-verify-email.entry.js +82 -38
  13. package/dist/esm/sqm-stencilbook.entry.js +5 -3
  14. package/dist/esm-es5/sqm-big-stat_38.entry.js +1 -1
  15. package/dist/esm-es5/sqm-portal-verify-email-view-4c562714.js +1 -0
  16. package/dist/esm-es5/sqm-portal-verify-email.entry.js +1 -1
  17. package/dist/esm-es5/sqm-stencilbook.entry.js +1 -1
  18. package/dist/mint-components/mint-components.esm.js +1 -1
  19. package/dist/mint-components/{p-561262cd.entry.js → p-1a5005fe.entry.js} +1 -1
  20. package/dist/mint-components/p-26a300dc.entry.js +1 -0
  21. package/dist/mint-components/p-2cbc3524.js +1 -0
  22. package/dist/mint-components/p-44b12b2e.system.js +1 -1
  23. package/dist/mint-components/p-570eaaee.system.js +1 -0
  24. package/dist/mint-components/{p-907c3344.system.entry.js → p-a9482c97.system.entry.js} +1 -1
  25. package/dist/mint-components/p-bed01771.system.entry.js +1 -0
  26. package/dist/mint-components/p-c33bbf65.entry.js +9 -0
  27. package/dist/mint-components/p-ddba12bb.system.entry.js +1 -0
  28. package/dist/types/components/sqm-portal-verify-email/sqm-portal-verify-email-view.d.ts +1 -0
  29. package/dist/types/components/sqm-portal-verify-email/usePortalVerifyEmail.d.ts +1 -0
  30. package/docs/docs.docx +0 -0
  31. package/package.json +1 -1
  32. package/dist/esm-es5/sqm-portal-verify-email-view-283bf637.js +0 -1
  33. package/dist/mint-components/p-17bc729f.entry.js +0 -1
  34. package/dist/mint-components/p-463e96b9.system.entry.js +0 -1
  35. package/dist/mint-components/p-4d9744bf.js +0 -1
  36. package/dist/mint-components/p-5cd6d4ed.system.entry.js +0 -1
  37. package/dist/mint-components/p-b2b22a2a.entry.js +0 -9
  38. package/dist/mint-components/p-d4b174e1.system.js +0 -1
@@ -1508,8 +1508,8 @@ function LinkButtonView(props) {
1508
1508
  index.h("style", { type: "text/css" },
1509
1509
  styleString$1,
1510
1510
  vanillaStyle),
1511
- index.h("sl-button", { type: "primary", exportparts: "base: primarybutton-base" },
1512
- index.h("a", { onClick: onClick, class: sheet$1.classes.Link, part: "sqm-link" }, buttonText))));
1511
+ index.h("sl-button", { onClick: onClick, type: "primary", exportparts: "base: primarybutton-base" },
1512
+ index.h("a", { class: sheet$1.classes.Link, part: "sqm-link" }, buttonText))));
1513
1513
  }
1514
1514
 
1515
1515
  const LinkButton = class {
@@ -24,7 +24,15 @@ const sheet = JSS.createStyleSheet(style);
24
24
  const styleString = sheet.toString();
25
25
  function PortalVerifyEmailView(props) {
26
26
  const { states, data, callbacks, content } = props;
27
- if (states.verified) {
27
+ console.log({
28
+ loading: states.loading,
29
+ success: states.success,
30
+ error: states.error,
31
+ oobCode: data.oobCode,
32
+ });
33
+ if (states.loading)
34
+ return;
35
+ if (states.success) {
28
36
  return (index.h("div", { class: sheet.classes.Wrapper, part: "sqm-base" },
29
37
  index.h("style", { type: "text/css" },
30
38
  vanillaStyle,
@@ -10,26 +10,32 @@ require('./mixins-fe9d4112.js');
10
10
  require('./JSS-8503a151.js');
11
11
  const utils = require('./utils-6847bc06.js');
12
12
  require('./sqm-text-span-view-e1cd9bd3.js');
13
- const sqmPortalVerifyEmailView = require('./sqm-portal-verify-email-view-ce552bbc.js');
13
+ const sqmPortalVerifyEmailView = require('./sqm-portal-verify-email-view-4f7063ff.js');
14
14
 
15
15
  const SUBMITTED_CONTEXT = "sq:verify-submitted";
16
- function setSubmitted(submitted) {
16
+ function setWindowSubmitted(submitted) {
17
17
  // using window due to dom-context getting reset on re-render
18
18
  window[SUBMITTED_CONTEXT] = submitted;
19
19
  }
20
20
  function usePortalVerifyEmail({ nextPage, failedPage, verifySuccessText, verifyEmailText, verifyInvalidText, networkErrorMessage, continueText, }) {
21
- var _a, _b, _c, _d, _e, _f, _g, _h;
22
- const submitted = window[SUBMITTED_CONTEXT];
21
+ var _b, _c, _d, _e, _f, _g, _h, _j;
22
+ const [submitted, setSubmitted] = stencilHooks_module.useState(window[SUBMITTED_CONTEXT]);
23
23
  const userIdent = index_module.Q();
24
+ const [verificationError, setVerificationError] = stencilHooks_module.useState(null);
25
+ const [success, setSuccess] = stencilHooks_module.useState(false);
24
26
  const [request, { loading, data, errors }] = index_module.an();
25
27
  const urlParams = new URLSearchParams(index_module.$n.location.search);
26
28
  const oobCode = urlParams.get("oobCode");
29
+ const oobEmail = urlParams.get("email");
27
30
  const nextPageOverride = urlParams.get("nextPage");
31
+ const syncSubmitted = (submitted) => {
32
+ setSubmitted(submitted);
33
+ setWindowSubmitted(submitted);
34
+ };
28
35
  // derived from useMutation in component boilerplate initialState
29
36
  const disableContinue = data === undefined && errors === undefined && !!oobCode;
30
37
  // if logged out, userIdent?.managedIdentity?.emailVerified will be falsey, even if verification was successful
31
- const verified = !!(((_a = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _a === void 0 ? void 0 : _a.emailVerified) || (data === null || data === void 0 ? void 0 : data.verifyManagedIdentityEmail.success));
32
- console.log({ userIdent, data, verified });
38
+ const verified = !!((_b = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _b === void 0 ? void 0 : _b.emailVerified);
33
39
  const failed = () => {
34
40
  return index_module.$n.push({
35
41
  pathname: failedPage,
@@ -41,51 +47,89 @@ function usePortalVerifyEmail({ nextPage, failedPage, verifySuccessText, verifyE
41
47
  const url = utils.sanitizeUrlPath(nextPageOverride || nextPage);
42
48
  index_module.$n.push(url.href);
43
49
  };
44
- const submit = async () => {
50
+ console.log({
51
+ userIdent,
52
+ data,
53
+ submitted,
54
+ verified,
55
+ verificationError,
56
+ success,
57
+ });
58
+ const check = async () => {
45
59
  var _a;
46
- setSubmitted(true);
47
- if (oobCode) {
48
- const result = await request({ oobCode });
49
- if ((result instanceof Error ||
50
- !result.verifyManagedIdentityEmail.success) &&
51
- !((_a = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _a === void 0 ? void 0 : _a.emailVerified)) {
52
- // pause on error if logged out/unverified
53
- return;
54
- }
55
- setTimeout(() => {
56
- gotoNextPage();
57
- setSubmitted(false);
58
- }, 3000);
60
+ syncSubmitted(true);
61
+ const response = await request({ oobCode });
62
+ if (response instanceof Error ||
63
+ !((_a = response === null || response === void 0 ? void 0 : response.verifyManagedIdentityEmail) === null || _a === void 0 ? void 0 : _a.success)) {
64
+ // logout();
65
+ console.debug("set verification error");
66
+ setVerificationError({ message: true });
59
67
  }
68
+ else {
69
+ console.debug("set success: true");
70
+ setSuccess(true);
71
+ }
72
+ console.debug("SUBMITTED", response);
73
+ console.debug("window", window[SUBMITTED_CONTEXT]);
60
74
  };
75
+ stencilHooks_module.useEffect(() => {
76
+ if (!submitted)
77
+ check();
78
+ }, [submitted]);
61
79
  stencilHooks_module.useEffect(() => {
62
80
  var _a;
63
- console.log("useEffect", { userIdent, data, verified });
64
- // verification successful but users do not match
65
- if (verified && !((_a = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _a === void 0 ? void 0 : _a.emailVerified)) {
66
- setTimeout(() => {
67
- gotoNextPage();
68
- setSubmitted(false);
69
- index_module.setUserIdentity(undefined);
70
- }, 3000);
81
+ if (!submitted || !(success || verificationError))
71
82
  return;
72
- // Already verified, begin redirect
83
+ if (!verificationError &&
84
+ ((_a = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _a === void 0 ? void 0 : _a.email) === oobEmail &&
85
+ (success || verified)) {
86
+ console.log("LOGGING IN", success, verified, verificationError);
87
+ setTimeout(gotoNextPage, 3000);
73
88
  }
74
- else if (verified) {
89
+ else {
90
+ console.log("LOGGING OUT", success, verified, verificationError);
75
91
  setTimeout(() => {
92
+ index_module.setUserIdentity(undefined);
76
93
  gotoNextPage();
77
- setSubmitted(false);
78
94
  }, 3000);
79
- return;
80
95
  }
81
- if (userIdent && !data && !submitted)
82
- submit();
83
- }, [verified, submitted, data, userIdent]);
96
+ }, [verified, verificationError, success, submitted, userIdent]);
97
+ stencilHooks_module.useEffect(() => {
98
+ if (errors)
99
+ setVerificationError(errors);
100
+ }, [errors, setVerificationError]);
101
+ // useEffect(() => {
102
+ // if (!data && !submitted && oobCode) {
103
+ // submit();
104
+ // return;
105
+ // }
106
+ // // verification successful but user in context is not verified
107
+ // // or mismatch between logged in user and user associated with oobCode
108
+ // if (submitted) {
109
+ // console.debug("in submit condition");
110
+ // if (email && email !== oobEmail) {
111
+ // console.debug("email mismatch");
112
+ // logout();
113
+ // return;
114
+ // // Already verified, begin redirect
115
+ // }
116
+ // if (verified) {
117
+ // if (!verificationError) setSuccess(true);
118
+ // console.debug("verified");
119
+ // setTimeout(() => {
120
+ // gotoNextPage();
121
+ // setSubmitted(false);
122
+ // }, 3000);
123
+ // return;
124
+ // }
125
+ // }
126
+ // }, [submitted, verificationError, data, email, oobCode, oobEmail, submit]);
84
127
  return {
85
128
  states: {
86
129
  loading: loading || disableContinue,
87
- error: ((_e = (_d = (_c = (_b = errors === null || errors === void 0 ? void 0 : errors.response) === null || _b === void 0 ? void 0 : _b.errors) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.extensions) === null || _e === void 0 ? void 0 : _e.message) || ((_h = (_g = (_f = errors === null || errors === void 0 ? void 0 : errors.response) === null || _f === void 0 ? void 0 : _f.errors) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.message) ||
88
- ((errors === null || errors === void 0 ? void 0 : errors.message) && networkErrorMessage),
130
+ success,
131
+ error: ((_f = (_e = (_d = (_c = verificationError === null || verificationError === void 0 ? void 0 : verificationError.response) === null || _c === void 0 ? void 0 : _c.errors) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.extensions) === null || _f === void 0 ? void 0 : _f.message) || ((_j = (_h = (_g = verificationError === null || verificationError === void 0 ? void 0 : verificationError.response) === null || _g === void 0 ? void 0 : _g.errors) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.message) ||
132
+ ((verificationError === null || verificationError === void 0 ? void 0 : verificationError.message) && networkErrorMessage),
89
133
  verified,
90
134
  },
91
135
  data: {
@@ -27,7 +27,7 @@ const sqmPortalForgotPasswordView = require('./sqm-portal-forgot-password-view-c
27
27
  const sqmPortalProfileView = require('./sqm-portal-profile-view-d8697f23.js');
28
28
  require('./utilities-73df97e1.js');
29
29
  const sqmPortalResetPasswordView = require('./sqm-portal-reset-password-view-07a13210.js');
30
- const sqmPortalVerifyEmailView = require('./sqm-portal-verify-email-view-ce552bbc.js');
30
+ const sqmPortalVerifyEmailView = require('./sqm-portal-verify-email-view-4f7063ff.js');
31
31
  const ShadowViewAddon = require('./ShadowViewAddon-89ba2ab0.js');
32
32
  const sqmPortalContainerView = require('./sqm-portal-container-view-5fb2ad49.js');
33
33
  const sqmInvoiceTableView = require('./sqm-invoice-table-view-501f8985.js');
@@ -7605,7 +7605,7 @@ const PortalResetPassword = /*#__PURE__*/Object.freeze({
7605
7605
  CodeValidating: CodeValidating
7606
7606
  });
7607
7607
 
7608
- const scenario$9 = "@author:derek\n@owner:ian\nFeature: Verify Email\n\n Background: A user is on the email verification page\n Given a user who has been redirected to the email verification page\n\n @motivating\n Scenario: Verifying your email takes you to the portal login page\n Given a user has a valid oob code as a url query parameter\n When they click \"Verify Email\"\n Then the button enters a loading state\n When their email is validated\n Then a button that says \"Continue\" appears\n When they click \"Continue\"\n Then they are redirected to login\n\n @motivating\n Scenario: Users are automatically redirected if they dont click \"Continue\"\n Given a user has a valid oob code as a url query parameter\n When they click \"Verify Email\"\n Then the button enters a loading state\n When their email is validated\n Then a button that says \"Continue\" appears\n When they wait 5 seconds\n Then they are redirected to login\n\n @motivating\n Scenario: Users are notified if verifying their email has failed\n Given a user has a valid oob code as a url query parameter\n When they click \"Verify Email\"\n Then the button enters a loading state\n When their email fails to be validated\n Then an banner is shown stating that an error occured\n\n @motivating\n Scenario Outline: Users cannot verify their email with an invalid or missing oob code\n Given a user has a <oobCode> as a url query parameter\n And the component <mayHave> \"failed-page\" with <value>\n Then they see an error message saying that their verification code is invalid/expired\n When they click \"Continue\"\n Then they are redirected to <redirectPath>\n Examples:\n | oobCode | mayHave | value | redirectPath |\n | invalid oob code | doesn't have | N/A | / |\n | non existant oob code | doesn't have | N/A | / |\n | invalid oob code | has | /login | /login |\n | non existant oob code | has | /login | /login |\n\n @motivating\n Scenario: Users are redirected to \"/\" by default\n Given the component does not have prop \"nextPage\"\n And the users url does not contain a \"nextPage\" query parameter\n And a user has verified their email\n When they click \"Continue\"\n Then they are redirected to \"/\"\n\n @motivating\n Scenario: Custom redirection can be configured\n Given the component has prop \"nextPage\" with value \"/activity\"\n And the users url does not contain a \"nextPage\" query parameter\n And a user has verified their email\n When they click \"Continue\"\n Then they are redirected to \"/activity\"\n\n @motivating\n Scenario Outline: Users are redirected to the value of the nextPage url parameter if it exists\n Given the component <mayHave> prop \"nextPage\" with <nextPageValue>\n And the users url contains a \"nextPage\" query paramater with <nextPageParamValue>\n And the user has verified their email\n When they click \"Continue\"\n Then they are redirected to <nextPageParamValue>\n Examples:\n | mayHave | nextPageValue | nextPageParamValue |\n | has | /dashboard | /activity |\n | does not have | N/A | /activity |\n\n @motivating\n Scenario Outline: Users are redirected to the value of the nextPage url parameter as if it were a relative path\n Given the component is loaded at <currentUrl>\n And the user has verified their email\n When they click \"Continue\"\n And they are redirected to <url>\n Examples:\n | currentUrl | url |\n | https://www.example.com?nextPage=./activity | https://www.example.com/activity |\n | https://www.example.com?nextPage=activity | https://www.example.com/activity |\n | https://www.example.com?nextPage=/activity | https://www.example.com/activity |\n | https://www.example.com?nextPage=www.google.com | https://www.example.com/www.google.com |\n | https://www.example.com?nextPage=//foo.com | https://www.example.com/ |\n | https://www.example.com?nextPage=https://malicious.example.com | https://www.example.com/ |\n | http://www.example.com/nest/page?oob=123&other&nextPage=activity#heading-1 | http://www.example.com/activity |\n | https://www.example.com?nextPage=activity?foo=bar | https://www.example.com/activity?foo=bar |\n | https://www.example.com?nextPage=%2Factivity%3Ffoo%3Dbar | https://www.example.com/activity?foo=bar |\n | https://www.example.com?nextPage=%2Factivity%3Ffoo%3Dbar#hash | https://www.example.com/activity?foo=bar |\n | https://www.example.com?nextPage=%2Factivity%3Ffoo%3Dbar%23hash | https://www.example.com/activity?foo=bar#hash |\n | https://www.example.com:1337?nextPage=activity | https://www.example.com:1337/activity |\n | http://1.1.1.1:1111?nextPage=activity | http://1.1.1.1:1111/activity |\n\n @landmine\n Scenario Outline: Username and password are not persisted on redirects\n Given the component is loaded at <currentUrl>\n And the user has verified their email\n When they click \"Continue\"\n And they are redirected to <url>\n Examples:\n | currentUrl | url |\n | https://user:pass@www.example.com:444?nextPage=activity | https://www.example.com:444/activity |";
7608
+ const scenario$9 = "@author:derek\n@owner:ian\nFeature: Verify Email\n\n Background: A user is on the email verification page\n Given a user who has been redirected to the email verification page\n\n @motivating\n Scenario: Verifying your email takes you to the portal login page\n Given a user has a valid oob code as a url query parameter\n When they click \"Verify Email\"\n Then the button enters a loading state\n When their email is validated\n Then a button that says \"Continue\" appears\n When they click \"Continue\"\n Then they are redirected to login\n\n @motivating\n Scenario: Users are automatically redirected if they dont click \"Continue\"\n Given a user has a valid oob code as a url query parameter\n When they click \"Verify Email\"\n Then the button enters a loading state\n When their email is validated\n Then a button that says \"Continue\" appears\n When they wait 5 seconds\n Then they are redirected to login\n\n @motivating\n Scenario: Users are notified if verifying their email has failed\n Given a user has a valid oob code as a url query parameter\n When they click \"Verify Email\"\n Then the button enters a loading state\n When their email fails to be validated\n Then an banner is shown stating that an error occured\n\n @motivating\n Scenario Outline: Users cannot verify their email with an invalid or missing oob code\n Given a user has a <oobCode> as a url query parameter\n And the component <mayHave> \"failed-page\" with <value>\n Then they see an error message saying that their verification code is invalid/expired\n When they click \"Continue\"\n Then they are redirected to <redirectPath>\n Examples:\n | oobCode | mayHave | value | redirectPath |\n | invalid oob code | doesn't have | N/A | / |\n | non existant oob code | doesn't have | N/A | / |\n | invalid oob code | has | /login | /login |\n | non existant oob code | has | /login | /login |\n\n @motivating\n Scenario: Users are redirected to \"/\" by default\n Given the component does not have prop \"nextPage\"\n And the users url does not contain a \"nextPage\" query parameter\n And a user has verified their email\n When they click \"Continue\"\n Then they are redirected to \"/\"\n\n @motivating\n Scenario: Custom redirection can be configured\n Given the component has prop \"nextPage\" with value \"/activity\"\n And the users url does not contain a \"nextPage\" query parameter\n And a user has verified their email\n When they click \"Continue\"\n Then they are redirected to \"/activity\"\n\n @motivating\n Scenario Outline: Users are redirected to the value of the nextPage url parameter if it exists\n Given the component <mayHave> prop \"nextPage\" with <nextPageValue>\n And the users url contains a \"nextPage\" query paramater with <nextPageParamValue>\n And the user has verified their email\n When they click \"Continue\"\n Then they are redirected to <nextPageParamValue>\n Examples:\n | mayHave | nextPageValue | nextPageParamValue |\n | has | /dashboard | /activity |\n | does not have | N/A | /activity |\n\n @motivating\n Scenario Outline: Users are redirected to the value of the nextPage url parameter as if it were a relative path\n Given the component is loaded at <currentUrl>\n And the user has verified their email\n When they click \"Continue\"\n And they are redirected to <url>\n Examples:\n | currentUrl | url |\n | https://www.example.com?nextPage=./activity | https://www.example.com/activity |\n | https://www.example.com?nextPage=activity | https://www.example.com/activity |\n | https://www.example.com?nextPage=/activity | https://www.example.com/activity |\n | https://www.example.com?nextPage=www.google.com | https://www.example.com/www.google.com |\n | https://www.example.com?nextPage=//foo.com | https://www.example.com/ |\n | https://www.example.com?nextPage=https://malicious.example.com | https://www.example.com/ |\n | http://www.example.com/nest/page?oob=123&other&nextPage=activity#heading-1 | http://www.example.com/activity |\n | https://www.example.com?nextPage=activity?foo=bar | https://www.example.com/activity?foo=bar |\n | https://www.example.com?nextPage=%2Factivity%3Ffoo%3Dbar | https://www.example.com/activity?foo=bar |\n | https://www.example.com?nextPage=%2Factivity%3Ffoo%3Dbar#hash | https://www.example.com/activity?foo=bar |\n | https://www.example.com?nextPage=%2Factivity%3Ffoo%3Dbar%23hash | https://www.example.com/activity?foo=bar#hash |\n | https://www.example.com:1337?nextPage=activity | https://www.example.com:1337/activity |\n | http://1.1.1.1:1111?nextPage=activity | http://1.1.1.1:1111/activity |\n\n @landmine\n Scenario Outline: Username and password are not persisted on redirects\n Given the component is loaded at <currentUrl>\n And the user has verified their email\n When they click \"Continue\"\n And they are redirected to <url>\n Examples:\n | currentUrl | url |\n | https://user:pass@www.example.com:444?nextPage=activity | https://www.example.com:444/activity |\n\n\n @minutia\n Scenario Outline: Users may be logged in or logged out depending on the verified status and logged in email\n Given an oobCode with email <oobCodeEmail> as a url query parameter\n And the user is logged in as <loggedInEmail>\n And the logged in user <isVerified>\n When the oobCode is submitted\n And the oobCode <isValid>\n Then the <submitState> screen is shown\n And after 3 seconds pass\n Then the user is redirected to <redirect>\n Examples:\n | oobCodeEmail | loggedInEmail | isVerified | isValid | submitState | redirect |\n | user1@example.com | N/A | false | is valid | success | /login |\n | user1@example.com | N/A | false | is not valid | error | /login |\n | user1@example.com | user1@example.com | false | is valid | success | /activity |\n | user1@example.com | user1@example.com | false | is not valid | error | N/A |\n | user1@example.com | user2@example.com | false | is valid | success | /login |\n | user1@example.com | user2@example.com | false | is not valid | error | /login |\n | user1@example.com | user1@example.com | true | is valid | success | /activity |\n | user1@example.com | user1@example.com | true | is not valid | success | /activity |\n | user1@example.com | user2@example.com | true | is not valid | error | /login |\n | N/A | N/A | false | is not valid | error | N/A |\n";
7609
7609
 
7610
7610
  const PortalVerifyEmail_stories = {
7611
7611
  title: "Components/Microsite Verify Email",
@@ -7618,6 +7618,7 @@ const errorProps$5 = {
7618
7618
  error: "Something went wrong. Please try again.",
7619
7619
  loading: false,
7620
7620
  verified: false,
7621
+ success: false,
7621
7622
  },
7622
7623
  data: {
7623
7624
  oobCode: "abc123",
@@ -7637,6 +7638,7 @@ const verifiedProps = {
7637
7638
  error: "",
7638
7639
  loading: false,
7639
7640
  verified: true,
7641
+ success: true,
7640
7642
  },
7641
7643
  data: {
7642
7644
  oobCode: "abc123",
@@ -9955,7 +9957,7 @@ const ResetPasswordReadme = "# sqm-portal-reset-password\n\n\n\n<!-- Auto Genera
9955
9957
 
9956
9958
  const EmailVerificationReadme = "# sqm-portal-email-verification\n\n\n\n<!-- Auto Generated Below -->\n\n\n## Properties\n\n| Property | Attribute | Description | Type | Default |\n| ---------------------------- | ------------------------------ | ----------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `demoData` | -- | | `{ states?: { error: string; loading: boolean; success: boolean; isVerified?: boolean; loadingVerification?: boolean; countdown?: number; }; content?: { email: string; verifyMessage: string; emailVerificationHeader: string; resendEmailButtonText: string; verificationStatusMessage?: string; verificationLoadingMessage?: string; verificationResentMessage?: string; }; }` | `undefined` |\n| `emailVerificationHeader` | `email-verification-header` | | `string` | `\"Verify your email\"` |\n| `networkErrorMessage` | `network-error-message` | | `string` | `\"An error occurred while verifying your password. Please refresh the page.\"` |\n| `redirectPath` | `redirect-path` | Redirect participants to this page from their verification email. | `string` | `\"/verifyEmail\"` |\n| `resendEmailButtonText` | `resend-email-button-text` | | `string` | `\"Re-send Email\"` |\n| `verificationLoadingMessage` | `verification-loading-message` | | `string` | `\"Checking verification status\"` |\n| `verificationResentMessage` | `verification-resent-message` | | `string` | `\"Your verification email has been resent successfully\"` |\n| `verificationStatusMessage` | `verification-status-message` | | `string` | `\"Checking verification status in {countdown}\"` |\n| `verifyMessage` | `verify-message` | | `string` | `\"A verification email was sent to {email}. Please verify your email to continue to the portal. Resending an email will invalidate the previous email.\"` |\n\n\n## Dependencies\n\n### Depends on\n\n- [sqm-form-message](../sqm-form-message)\n\n### Graph\n```mermaid\ngraph TD;\n sqm-portal-email-verification --> sqm-form-message\n style sqm-portal-email-verification fill:#f9f,stroke:#333,stroke-width:4px\n```\n\n----------------------------------------------\n\n*Built with [StencilJS](https://stenciljs.com/)*\n";
9957
9959
 
9958
- const EmailVerifiedReadme = "# sqm-portal-verify-email\n\n\n\n<!-- Auto Generated Below -->\n\n\n## Properties\n\n| Property | Attribute | Description | Type | Default |\n| --------------------- | ----------------------- | ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |\n| `continueText` | `continue-text` | | `string` | `\"Continue\"` |\n| `demoData` | -- | | `{ states?: { error: string; loading: boolean; verified: boolean; }; data?: { oobCode: string; }; content?: { verifySuccessText?: string; verifyEmailText?: string; verifyInvalidText?: string; continueText?: string; }; }` | `undefined` |\n| `failedPage` | `failed-page` | Redirect participants to this page if verification fails due to an outdated verification attempt. | `string` | `\"/\"` |\n| `networkErrorMessage` | `network-error-message` | | `string` | `\"An error occurred while verifying your email. Please refresh the page and try again.\"` |\n| `nextPage` | `next-page` | Redirect participants to this page when they successfully verify their email. | `string` | `\"/\"` |\n| `verifyEmailText` | `verify-email-text` | | `string` | `\"Verify your email\"` |\n| `verifyInvalidText` | `verify-invalid-text` | | `string` | `\"The email verification code is invalid or has expired, please try again.\"` |\n| `verifySuccessText` | `verify-success-text` | | `string` | `\"Your email has been verified and you are being redirected. If you are not redirected, please click Continue.\"` |\n\n\n## Dependencies\n\n### Depends on\n\n- [sqm-form-message](../sqm-form-message)\n\n### Graph\n```mermaid\ngraph TD;\n sqm-portal-verify-email --> sqm-form-message\n style sqm-portal-verify-email fill:#f9f,stroke:#333,stroke-width:4px\n```\n\n----------------------------------------------\n\n*Built with [StencilJS](https://stenciljs.com/)*\n";
9960
+ const EmailVerifiedReadme = "# sqm-portal-verify-email\n\n\n\n<!-- Auto Generated Below -->\n\n\n## Properties\n\n| Property | Attribute | Description | Type | Default |\n| --------------------- | ----------------------- | ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |\n| `continueText` | `continue-text` | | `string` | `\"Continue\"` |\n| `demoData` | -- | | `{ states?: { error: string; loading: boolean; success: boolean; verified: boolean; }; data?: { oobCode: string; }; content?: { verifySuccessText?: string; verifyEmailText?: string; verifyInvalidText?: string; continueText?: string; }; }` | `undefined` |\n| `failedPage` | `failed-page` | Redirect participants to this page if verification fails due to an outdated verification attempt. | `string` | `\"/\"` |\n| `networkErrorMessage` | `network-error-message` | | `string` | `\"An error occurred while verifying your email. Please refresh the page and try again.\"` |\n| `nextPage` | `next-page` | Redirect participants to this page when they successfully verify their email. | `string` | `\"/\"` |\n| `verifyEmailText` | `verify-email-text` | | `string` | `\"Verify your email\"` |\n| `verifyInvalidText` | `verify-invalid-text` | | `string` | `\"The email verification code is invalid or has expired, please try again.\"` |\n| `verifySuccessText` | `verify-success-text` | | `string` | `\"Your email has been verified and you are being redirected. If you are not redirected, please click Continue.\"` |\n\n\n## Dependencies\n\n### Depends on\n\n- [sqm-form-message](../sqm-form-message)\n\n### Graph\n```mermaid\ngraph TD;\n sqm-portal-verify-email --> sqm-form-message\n style sqm-portal-verify-email fill:#f9f,stroke:#333,stroke-width:4px\n```\n\n----------------------------------------------\n\n*Built with [StencilJS](https://stenciljs.com/)*\n";
9959
9961
 
9960
9962
  const PortalTemplates_stories = {
9961
9963
  title: "Templates / Microsite",
@@ -20,6 +20,6 @@ export function LinkButtonView(props) {
20
20
  h("style", { type: "text/css" },
21
21
  styleString,
22
22
  vanillaStyle),
23
- h("sl-button", { type: "primary", exportparts: "base: primarybutton-base" },
24
- h("a", { onClick: onClick, class: sheet.classes.Link, part: "sqm-link" }, buttonText))));
23
+ h("sl-button", { onClick: onClick, type: "primary", exportparts: "base: primarybutton-base" },
24
+ h("a", { class: sheet.classes.Link, part: "sqm-link" }, buttonText))));
25
25
  }
@@ -12,6 +12,7 @@ const errorProps = {
12
12
  error: "Something went wrong. Please try again.",
13
13
  loading: false,
14
14
  verified: false,
15
+ success: false,
15
16
  },
16
17
  data: {
17
18
  oobCode: "abc123",
@@ -31,6 +32,7 @@ const verifiedProps = {
31
32
  error: "",
32
33
  loading: false,
33
34
  verified: true,
35
+ success: true,
34
36
  },
35
37
  data: {
36
38
  oobCode: "abc123",
@@ -21,7 +21,15 @@ const sheet = createStyleSheet(style);
21
21
  const styleString = sheet.toString();
22
22
  export function PortalVerifyEmailView(props) {
23
23
  const { states, data, callbacks, content } = props;
24
- if (states.verified) {
24
+ console.log({
25
+ loading: states.loading,
26
+ success: states.success,
27
+ error: states.error,
28
+ oobCode: data.oobCode,
29
+ });
30
+ if (states.loading)
31
+ return;
32
+ if (states.success) {
25
33
  return (h("div", { class: sheet.classes.Wrapper, part: "sqm-base" },
26
34
  h("style", { type: "text/css" },
27
35
  vanillaStyle,
@@ -228,7 +228,7 @@ export class PortalVerifyEmail {
228
228
  "mutable": false,
229
229
  "complexType": {
230
230
  "original": "DemoData<PortalVerifyEmailViewProps>",
231
- "resolved": "{ states?: { error: string; loading: boolean; verified: boolean; }; data?: { oobCode: string; }; content?: { verifySuccessText?: string; verifyEmailText?: string; verifyInvalidText?: string; continueText?: string; }; }",
231
+ "resolved": "{ states?: { error: string; loading: boolean; success: boolean; verified: boolean; }; data?: { oobCode: string; }; content?: { verifySuccessText?: string; verifyEmailText?: string; verifyInvalidText?: string; continueText?: string; }; }",
232
232
  "references": {
233
233
  "DemoData": {
234
234
  "location": "import",
@@ -1,24 +1,31 @@
1
1
  import { navigation, setUserIdentity, useUserIdentity, useVerifyEmailMutation, } from "@saasquatch/component-boilerplate";
2
- import { useEffect } from "@saasquatch/universal-hooks";
2
+ import { useEffect, useState } from "@saasquatch/universal-hooks";
3
3
  import { sanitizeUrlPath } from "../../utils/utils";
4
4
  const SUBMITTED_CONTEXT = "sq:verify-submitted";
5
- function setSubmitted(submitted) {
5
+ function setWindowSubmitted(submitted) {
6
6
  // using window due to dom-context getting reset on re-render
7
7
  window[SUBMITTED_CONTEXT] = submitted;
8
8
  }
9
9
  export function usePortalVerifyEmail({ nextPage, failedPage, verifySuccessText, verifyEmailText, verifyInvalidText, networkErrorMessage, continueText, }) {
10
- var _a, _b, _c, _d, _e, _f, _g, _h;
11
- const submitted = window[SUBMITTED_CONTEXT];
10
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
11
+ const [submitted, setSubmitted] = useState(window[SUBMITTED_CONTEXT]);
12
12
  const userIdent = useUserIdentity();
13
+ const [verificationError, setVerificationError] = useState(null);
14
+ const [success, setSuccess] = useState(false);
15
+ const email = (_a = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _a === void 0 ? void 0 : _a.email;
13
16
  const [request, { loading, data, errors }] = useVerifyEmailMutation();
14
17
  const urlParams = new URLSearchParams(navigation.location.search);
15
18
  const oobCode = urlParams.get("oobCode");
19
+ const oobEmail = urlParams.get("email");
16
20
  const nextPageOverride = urlParams.get("nextPage");
21
+ const syncSubmitted = (submitted) => {
22
+ setSubmitted(submitted);
23
+ setWindowSubmitted(submitted);
24
+ };
17
25
  // derived from useMutation in component boilerplate initialState
18
26
  const disableContinue = data === undefined && errors === undefined && !!oobCode;
19
27
  // if logged out, userIdent?.managedIdentity?.emailVerified will be falsey, even if verification was successful
20
- const verified = !!(((_a = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _a === void 0 ? void 0 : _a.emailVerified) || (data === null || data === void 0 ? void 0 : data.verifyManagedIdentityEmail.success));
21
- console.log({ userIdent, data, verified });
28
+ const verified = !!((_b = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _b === void 0 ? void 0 : _b.emailVerified);
22
29
  const failed = () => {
23
30
  return navigation.push({
24
31
  pathname: failedPage,
@@ -30,51 +37,100 @@ export function usePortalVerifyEmail({ nextPage, failedPage, verifySuccessText,
30
37
  const url = sanitizeUrlPath(nextPageOverride || nextPage);
31
38
  navigation.push(url.href);
32
39
  };
33
- const submit = async () => {
40
+ console.log({
41
+ userIdent,
42
+ data,
43
+ submitted,
44
+ verified,
45
+ verificationError,
46
+ success,
47
+ });
48
+ const logout = () => {
49
+ console.log("LOGGING OUT", success, verified, verificationError);
50
+ setTimeout(() => {
51
+ setUserIdentity(undefined);
52
+ gotoNextPage();
53
+ }, 3000);
54
+ };
55
+ const login = () => {
56
+ console.log("LOGGING IN", success, verified, verificationError);
57
+ setTimeout(gotoNextPage, 3000);
58
+ };
59
+ const check = async () => {
34
60
  var _a;
35
- setSubmitted(true);
36
- if (oobCode) {
37
- const result = await request({ oobCode });
38
- if ((result instanceof Error ||
39
- !result.verifyManagedIdentityEmail.success) &&
40
- !((_a = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _a === void 0 ? void 0 : _a.emailVerified)) {
41
- // pause on error if logged out/unverified
42
- return;
43
- }
44
- setTimeout(() => {
45
- gotoNextPage();
46
- setSubmitted(false);
47
- }, 3000);
61
+ syncSubmitted(true);
62
+ const response = await request({ oobCode });
63
+ if (response instanceof Error ||
64
+ !((_a = response === null || response === void 0 ? void 0 : response.verifyManagedIdentityEmail) === null || _a === void 0 ? void 0 : _a.success)) {
65
+ // logout();
66
+ console.debug("set verification error");
67
+ setVerificationError({ message: true });
48
68
  }
69
+ else {
70
+ console.debug("set success: true");
71
+ setSuccess(true);
72
+ }
73
+ console.debug("SUBMITTED", response);
74
+ console.debug("window", window[SUBMITTED_CONTEXT]);
49
75
  };
76
+ useEffect(() => {
77
+ if (!submitted)
78
+ check();
79
+ }, [submitted]);
50
80
  useEffect(() => {
51
81
  var _a;
52
- console.log("useEffect", { userIdent, data, verified });
53
- // verification successful but users do not match
54
- if (verified && !((_a = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _a === void 0 ? void 0 : _a.emailVerified)) {
55
- setTimeout(() => {
56
- gotoNextPage();
57
- setSubmitted(false);
58
- setUserIdentity(undefined);
59
- }, 3000);
82
+ if (!submitted || !(success || verificationError))
60
83
  return;
61
- // Already verified, begin redirect
84
+ if (!verificationError &&
85
+ ((_a = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _a === void 0 ? void 0 : _a.email) === oobEmail &&
86
+ (success || verified)) {
87
+ console.log("LOGGING IN", success, verified, verificationError);
88
+ setTimeout(gotoNextPage, 3000);
62
89
  }
63
- else if (verified) {
90
+ else {
91
+ console.log("LOGGING OUT", success, verified, verificationError);
64
92
  setTimeout(() => {
93
+ setUserIdentity(undefined);
65
94
  gotoNextPage();
66
- setSubmitted(false);
67
95
  }, 3000);
68
- return;
69
96
  }
70
- if (userIdent && !data && !submitted)
71
- submit();
72
- }, [verified, submitted, data, userIdent]);
97
+ }, [verified, verificationError, success, submitted, userIdent]);
98
+ useEffect(() => {
99
+ if (errors)
100
+ setVerificationError(errors);
101
+ }, [errors, setVerificationError]);
102
+ // useEffect(() => {
103
+ // if (!data && !submitted && oobCode) {
104
+ // submit();
105
+ // return;
106
+ // }
107
+ // // verification successful but user in context is not verified
108
+ // // or mismatch between logged in user and user associated with oobCode
109
+ // if (submitted) {
110
+ // console.debug("in submit condition");
111
+ // if (email && email !== oobEmail) {
112
+ // console.debug("email mismatch");
113
+ // logout();
114
+ // return;
115
+ // // Already verified, begin redirect
116
+ // }
117
+ // if (verified) {
118
+ // if (!verificationError) setSuccess(true);
119
+ // console.debug("verified");
120
+ // setTimeout(() => {
121
+ // gotoNextPage();
122
+ // setSubmitted(false);
123
+ // }, 3000);
124
+ // return;
125
+ // }
126
+ // }
127
+ // }, [submitted, verificationError, data, email, oobCode, oobEmail, submit]);
73
128
  return {
74
129
  states: {
75
130
  loading: loading || disableContinue,
76
- error: ((_e = (_d = (_c = (_b = errors === null || errors === void 0 ? void 0 : errors.response) === null || _b === void 0 ? void 0 : _b.errors) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.extensions) === null || _e === void 0 ? void 0 : _e.message) || ((_h = (_g = (_f = errors === null || errors === void 0 ? void 0 : errors.response) === null || _f === void 0 ? void 0 : _f.errors) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.message) ||
77
- ((errors === null || errors === void 0 ? void 0 : errors.message) && networkErrorMessage),
131
+ success,
132
+ error: ((_f = (_e = (_d = (_c = verificationError === null || verificationError === void 0 ? void 0 : verificationError.response) === null || _c === void 0 ? void 0 : _c.errors) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.extensions) === null || _f === void 0 ? void 0 : _f.message) || ((_j = (_h = (_g = verificationError === null || verificationError === void 0 ? void 0 : verificationError.response) === null || _g === void 0 ? void 0 : _g.errors) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.message) ||
133
+ ((verificationError === null || verificationError === void 0 ? void 0 : verificationError.message) && networkErrorMessage),
78
134
  verified,
79
135
  },
80
136
  data: {
@@ -1504,8 +1504,8 @@ function LinkButtonView(props) {
1504
1504
  h$1("style", { type: "text/css" },
1505
1505
  styleString$1,
1506
1506
  vanillaStyle),
1507
- h$1("sl-button", { type: "primary", exportparts: "base: primarybutton-base" },
1508
- h$1("a", { onClick: onClick, class: sheet$1.classes.Link, part: "sqm-link" }, buttonText))));
1507
+ h$1("sl-button", { onClick: onClick, type: "primary", exportparts: "base: primarybutton-base" },
1508
+ h$1("a", { class: sheet$1.classes.Link, part: "sqm-link" }, buttonText))));
1509
1509
  }
1510
1510
 
1511
1511
  const LinkButton = class {
@@ -22,7 +22,15 @@ const sheet = createStyleSheet(style);
22
22
  const styleString = sheet.toString();
23
23
  function PortalVerifyEmailView(props) {
24
24
  const { states, data, callbacks, content } = props;
25
- if (states.verified) {
25
+ console.log({
26
+ loading: states.loading,
27
+ success: states.success,
28
+ error: states.error,
29
+ oobCode: data.oobCode,
30
+ });
31
+ if (states.loading)
32
+ return;
33
+ if (states.success) {
26
34
  return (h("div", { class: sheet.classes.Wrapper, part: "sqm-base" },
27
35
  h("style", { type: "text/css" },
28
36
  vanillaStyle,