@saasquatch/mint-components 1.12.0-4 → 1.12.0-6

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 (123) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/mint-components.cjs.js +1 -1
  3. package/dist/cjs/sqm-banking-info-form_16.cjs.entry.js +47 -18
  4. package/dist/cjs/sqm-big-stat_39.cjs.entry.js +22 -4
  5. package/dist/cjs/sqm-code-verification.cjs.entry.js +34 -48
  6. package/dist/cjs/sqm-email-verification.cjs.entry.js +143 -21
  7. package/dist/cjs/{sqm-invoice-table-view-dbba9bb4.js → sqm-invoice-table-view-e530775f.js} +39 -0
  8. package/dist/cjs/sqm-stencilbook.cjs.entry.js +19 -1
  9. package/dist/cjs/sqm-widget-verification-internal.cjs.entry.js +53 -7
  10. package/dist/cjs/sqm-widget-verification.cjs.entry.js +15 -18
  11. package/dist/cjs/useVerificationEmail-35aea294.js +170 -0
  12. package/dist/collection/collection-manifest.json +1 -1
  13. package/dist/collection/components/sqm-widget-verification/sqm-code-verification/WidgetCodeVerification.stories.js +7 -0
  14. package/dist/collection/components/sqm-widget-verification/sqm-code-verification/sqm-code-verification-view.js +1 -1
  15. package/dist/collection/components/sqm-widget-verification/sqm-code-verification/sqm-code-verification.js +20 -2
  16. package/dist/collection/components/sqm-widget-verification/sqm-code-verification/useCodeVerification.js +33 -24
  17. package/dist/collection/components/sqm-widget-verification/sqm-email-verification/useEmailVerification.js +19 -42
  18. package/dist/collection/components/sqm-widget-verification/sqm-widget-verification-internal.js +55 -7
  19. package/dist/collection/components/sqm-widget-verification/sqm-widget-verification.js +17 -20
  20. package/dist/collection/components/sqm-widget-verification/useVerificationEmail.js +165 -0
  21. package/dist/collection/components/tax-and-cash/BankingForm.stories.js +1 -0
  22. package/dist/collection/components/tax-and-cash/TaxForm.stories.js +38 -0
  23. package/dist/collection/components/tax-and-cash/sqm-banking-info-form/sqm-banking-info-form.js +2 -1
  24. package/dist/collection/components/tax-and-cash/sqm-banking-info-form/useBankingInfoForm.js +7 -0
  25. package/dist/collection/components/tax-and-cash/sqm-payout-status-alert/PayoutStatusAlert.stories.js +8 -0
  26. package/dist/collection/components/tax-and-cash/sqm-payout-status-alert/sqm-payout-status-alert-view.js +8 -3
  27. package/dist/collection/components/tax-and-cash/sqm-payout-status-alert/sqm-payout-status-alert.js +11 -1
  28. package/dist/collection/components/tax-and-cash/sqm-payout-status-alert/usePayoutStatus.js +9 -1
  29. package/dist/collection/components/tax-and-cash/sqm-tax-and-cash/data.js +5 -0
  30. package/dist/collection/components/tax-and-cash/sqm-tax-and-cash/sqm-tax-and-cash.js +8 -8
  31. package/dist/collection/components/tax-and-cash/sqm-tax-and-cash-dashboard/sqm-tax-and-cash-dashboard-view.js +11 -0
  32. package/dist/collection/components/tax-and-cash/sqm-tax-and-cash-dashboard/sqm-tax-and-cash-dashboard.js +10 -9
  33. package/dist/collection/components/tax-and-cash/sqm-tax-and-cash-dashboard/useTaxAndCashDashboard.js +2 -1
  34. package/dist/collection/components/tax-and-cash/sqm-user-info-form/useUserInfoForm.js +14 -11
  35. package/dist/esm/{keys-a1496e39.js → keys-db1897ae.js} +1 -1
  36. package/dist/esm/loader.js +1 -1
  37. package/dist/esm/mint-components.js +1 -1
  38. package/dist/esm/sqm-banking-info-form_16.entry.js +48 -19
  39. package/dist/esm/sqm-big-stat_39.entry.js +22 -4
  40. package/dist/esm/sqm-code-verification.entry.js +36 -50
  41. package/dist/esm/sqm-email-verification.entry.js +127 -5
  42. package/dist/esm/{sqm-invoice-table-view-663674f2.js → sqm-invoice-table-view-22bb7240.js} +39 -0
  43. package/dist/esm/sqm-stencilbook.entry.js +19 -1
  44. package/dist/esm/sqm-widget-verification-internal.entry.js +53 -7
  45. package/dist/esm/sqm-widget-verification.entry.js +17 -20
  46. package/dist/esm/useVerificationEmail-02b78bd7.js +168 -0
  47. package/dist/esm-es5/{keys-a1496e39.js → keys-db1897ae.js} +1 -1
  48. package/dist/esm-es5/loader.js +1 -1
  49. package/dist/esm-es5/mint-components.js +1 -1
  50. package/dist/esm-es5/sqm-banking-info-form_16.entry.js +1 -1
  51. package/dist/esm-es5/sqm-big-stat_39.entry.js +1 -1
  52. package/dist/esm-es5/sqm-code-verification.entry.js +1 -1
  53. package/dist/esm-es5/sqm-email-verification.entry.js +1 -1
  54. package/dist/esm-es5/sqm-invoice-table-view-22bb7240.js +1 -0
  55. package/dist/esm-es5/sqm-stencilbook.entry.js +1 -1
  56. package/dist/esm-es5/sqm-widget-verification-internal.entry.js +1 -1
  57. package/dist/esm-es5/sqm-widget-verification.entry.js +1 -1
  58. package/dist/esm-es5/useVerificationEmail-02b78bd7.js +1 -0
  59. package/dist/mint-components/mint-components.esm.js +1 -1
  60. package/dist/mint-components/{p-53d9df5e.entry.js → p-0aebee07.entry.js} +8 -3
  61. package/dist/mint-components/p-116c1809.entry.js +11 -0
  62. package/dist/mint-components/{p-99a09fab.entry.js → p-126a4f24.entry.js} +2 -2
  63. package/dist/mint-components/{p-d4138847.system.entry.js → p-28450e40.system.entry.js} +1 -1
  64. package/dist/mint-components/p-2b5b2586.system.js +1 -0
  65. package/dist/mint-components/p-39840341.js +1 -0
  66. package/dist/mint-components/p-4606b096.entry.js +12 -0
  67. package/dist/mint-components/p-46a5718f.system.entry.js +1 -0
  68. package/dist/mint-components/{p-ff77d11f.entry.js → p-4986a616.entry.js} +10 -10
  69. package/dist/mint-components/p-4a43ffbd.js +1 -0
  70. package/dist/mint-components/p-696e634f.system.entry.js +1 -0
  71. package/dist/mint-components/p-71b8adf7.system.js +1 -0
  72. package/dist/mint-components/p-7666cd3d.js +48 -0
  73. package/dist/mint-components/p-87bf9880.entry.js +25 -0
  74. package/dist/mint-components/p-8a7d2170.system.entry.js +1 -0
  75. package/dist/mint-components/p-a5eedbe2.system.entry.js +1 -0
  76. package/dist/mint-components/p-a60ec391.system.entry.js +1 -0
  77. package/dist/mint-components/p-b2a99637.system.js +1 -0
  78. package/dist/mint-components/p-ca423ca2.system.entry.js +1 -0
  79. package/dist/mint-components/p-e05ff098.system.js +1 -1
  80. package/dist/mint-components/p-e373b78a.entry.js +1 -0
  81. package/dist/types/components/sqm-widget-verification/sqm-code-verification/WidgetCodeVerification.stories.d.ts +1 -0
  82. package/dist/types/components/sqm-widget-verification/sqm-code-verification/sqm-code-verification-view.d.ts +1 -0
  83. package/dist/types/components/sqm-widget-verification/sqm-code-verification/sqm-code-verification.d.ts +4 -0
  84. package/dist/types/components/sqm-widget-verification/sqm-code-verification/useCodeVerification.d.ts +2 -1
  85. package/dist/types/components/sqm-widget-verification/sqm-email-verification/useEmailVerification.d.ts +0 -6
  86. package/dist/types/components/sqm-widget-verification/useVerificationEmail.d.ts +14 -0
  87. package/dist/types/components/tax-and-cash/TaxForm.stories.d.ts +1 -0
  88. package/dist/types/components/tax-and-cash/sqm-banking-info-form/sqm-banking-info-form-view.d.ts +1 -0
  89. package/dist/types/components/tax-and-cash/sqm-payout-status-alert/PayoutStatusAlert.stories.d.ts +1 -0
  90. package/dist/types/components/tax-and-cash/sqm-payout-status-alert/sqm-payout-status-alert-view.d.ts +5 -0
  91. package/dist/types/components/tax-and-cash/sqm-payout-status-alert/sqm-payout-status-alert.d.ts +5 -0
  92. package/dist/types/components/tax-and-cash/sqm-payout-status-alert/usePayoutStatus.d.ts +5 -0
  93. package/dist/types/components/tax-and-cash/sqm-tax-and-cash/data.d.ts +5 -0
  94. package/dist/types/components/tax-and-cash/sqm-tax-and-cash/sqm-tax-and-cash.d.ts +2 -2
  95. package/dist/types/components/tax-and-cash/sqm-tax-and-cash-dashboard/sqm-tax-and-cash-dashboard-view.d.ts +3 -0
  96. package/dist/types/components/tax-and-cash/sqm-tax-and-cash-dashboard/sqm-tax-and-cash-dashboard.d.ts +2 -2
  97. package/dist/types/components.d.ts +60 -52
  98. package/docs/docs.docx +0 -0
  99. package/docs/raisins.json +1 -1
  100. package/grapesjs/grapesjs.js +1 -1
  101. package/package.json +1 -1
  102. package/dist/cjs/useEmailVerification-33465f36.js +0 -155
  103. package/dist/collection/components/sqm-widget-verification/useWidgetVerification.js +0 -3
  104. package/dist/esm/useEmailVerification-8f2dc2bd.js +0 -152
  105. package/dist/esm-es5/sqm-invoice-table-view-663674f2.js +0 -1
  106. package/dist/esm-es5/useEmailVerification-8f2dc2bd.js +0 -1
  107. package/dist/mint-components/p-158e9d3a.entry.js +0 -1
  108. package/dist/mint-components/p-20c5ce3d.system.entry.js +0 -1
  109. package/dist/mint-components/p-219be817.system.entry.js +0 -1
  110. package/dist/mint-components/p-2c03096f.system.entry.js +0 -1
  111. package/dist/mint-components/p-4c9b6fbe.system.js +0 -1
  112. package/dist/mint-components/p-4d060f15.js +0 -1
  113. package/dist/mint-components/p-5810e318.entry.js +0 -1
  114. package/dist/mint-components/p-6029c42d.entry.js +0 -8
  115. package/dist/mint-components/p-6cae44d7.js +0 -1
  116. package/dist/mint-components/p-78c1bd77.system.js +0 -1
  117. package/dist/mint-components/p-80a32fe9.system.entry.js +0 -1
  118. package/dist/mint-components/p-a2baff3e.entry.js +0 -1
  119. package/dist/mint-components/p-b52b7e60.system.entry.js +0 -1
  120. package/dist/mint-components/p-f4dff47a.system.entry.js +0 -1
  121. package/dist/mint-components/p-faf019cf.system.js +0 -1
  122. package/dist/mint-components/p-fcb224ab.js +0 -25
  123. package/dist/types/components/sqm-widget-verification/useWidgetVerification.d.ts +0 -1
@@ -2,13 +2,26 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const index = require('./index-b0129cd6.js');
5
+ const index$1 = require('./index-b0129cd6.js');
6
6
  const stencilHooks_module = require('./stencil-hooks.module-a5a04d8a.js');
7
7
  const index_module = require('./index.module-236d0403.js');
8
+ const index = require('./index-56d1fa5b.js');
8
9
  const utils = require('./utils-6847bc06.js');
9
10
  const keys = require('./keys-cff24974.js');
10
11
  const extractProps = require('./extractProps-fd93ba62.js');
11
12
 
13
+ const USER_LOOKUP = index.dist.gql `
14
+ query viewer {
15
+ viewer {
16
+ ... on User {
17
+ id
18
+ accountId
19
+ email
20
+ emailVerified
21
+ }
22
+ }
23
+ }
24
+ `;
12
25
  function useWidgetVerificationInternal() {
13
26
  const userIdentity = index_module.K();
14
27
  const [showCode, setShowCode] = index_module.Fn({
@@ -19,11 +32,36 @@ function useWidgetVerificationInternal() {
19
32
  namespace: keys.VERIFICATION_EMAIL_NAMESPACE,
20
33
  initialValue: userIdentity === null || userIdentity === void 0 ? void 0 : userIdentity.email,
21
34
  });
22
- return { showCode };
35
+ const setContext = index_module.Sn(keys.VERIFICATION_PARENT_NAMESPACE);
36
+ const [loading, setLoading] = stencilHooks_module.useState(true);
37
+ const [fetch] = index_module.an(USER_LOOKUP);
38
+ stencilHooks_module.useEffect(() => {
39
+ const checkUser = async () => {
40
+ var _a;
41
+ try {
42
+ const res = await fetch({});
43
+ if (!res || res instanceof Error)
44
+ throw new Error();
45
+ if ((_a = res === null || res === void 0 ? void 0 : res.viewer) === null || _a === void 0 ? void 0 : _a.emailVerified)
46
+ setContext(true);
47
+ }
48
+ catch (e) {
49
+ console.error("Could not fetch user information", e);
50
+ }
51
+ finally {
52
+ setLoading(false);
53
+ }
54
+ };
55
+ checkUser();
56
+ }, []);
57
+ const onVerification = () => {
58
+ setContext(true);
59
+ };
60
+ return { showCode, onVerification, loading };
23
61
  }
24
62
  const WidgetVerificationInternal = class {
25
63
  constructor(hostRef) {
26
- index.registerInstance(this, hostRef);
64
+ index$1.registerInstance(this, hostRef);
27
65
  stencilHooks_module.h(this);
28
66
  }
29
67
  disconnectedCallback() { }
@@ -32,13 +70,17 @@ const WidgetVerificationInternal = class {
32
70
  return extractProps.extractProps(props, prefix);
33
71
  }
34
72
  render() {
35
- const { showCode } = index_module.isDemo()
73
+ const { showCode, onVerification, loading } = index_module.isDemo()
36
74
  ? useDemoWidgetVerificationInternal()
37
75
  : useWidgetVerificationInternal();
76
+ if (loading) {
77
+ // TODO: Proper loading state
78
+ return index$1.h("div", null, "Loading");
79
+ }
38
80
  if (showCode) {
39
- return (index.h("sqm-code-verification", Object.assign({}, this.getStepTextProps("codeStep_"))));
81
+ return (index$1.h("sqm-code-verification", Object.assign({ onVerification: onVerification }, this.getStepTextProps("codeStep_"))));
40
82
  }
41
- return (index.h("sqm-email-verification", Object.assign({}, this.getStepTextProps("emailStep_"))));
83
+ return (index$1.h("sqm-email-verification", Object.assign({}, this.getStepTextProps("emailStep_"))));
42
84
  }
43
85
  };
44
86
  function useDemoWidgetVerificationInternal() {
@@ -50,7 +92,11 @@ function useDemoWidgetVerificationInternal() {
50
92
  namespace: keys.VERIFICATION_EMAIL_NAMESPACE,
51
93
  initialValue: undefined,
52
94
  });
53
- return { showCode };
95
+ const setContext = index_module.Sn(keys.VERIFICATION_PARENT_NAMESPACE);
96
+ const onVerification = () => {
97
+ setContext(true);
98
+ };
99
+ return { showCode, onVerification, loading: false };
54
100
  }
55
101
 
56
102
  exports.sqm_widget_verification_internal = WidgetVerificationInternal;
@@ -129,15 +129,12 @@ const WidgetVerification = class {
129
129
  render() {
130
130
  const [context, setContext] = index_module.Fn({
131
131
  namespace: keys.VERIFICATION_PARENT_NAMESPACE,
132
- initialValue: undefined,
132
+ initialValue: false,
133
133
  });
134
- const authToken = context === null || context === void 0 ? void 0 : context.token;
135
134
  const [container, setContainer] = stencilHooks_module.useState(undefined);
136
135
  const [slot, setSlot] = stencilHooks_module.useState(undefined);
137
- if (!authToken)
138
- debug("No user identity available");
139
136
  const updateTemplates = index_module.useCallback(() => {
140
- const isAuth = !!authToken;
137
+ const isAuth = context;
141
138
  const templates = slot.querySelectorAll(`template`);
142
139
  const template = Array.from(templates).find((t) => t.slot === (isAuth ? "verified" : "not-verified"));
143
140
  if (template) {
@@ -185,7 +182,7 @@ const WidgetVerification = class {
185
182
  target.style.height = "25px";
186
183
  });
187
184
  }
188
- }, [container, slot, authToken]);
185
+ }, [container, slot, context]);
189
186
  stencilHooks_module.useEffect(() => {
190
187
  if (!container || !slot) {
191
188
  debug("DOM not ready:");
@@ -194,18 +191,18 @@ const WidgetVerification = class {
194
191
  // Run on first render
195
192
  updateTemplates();
196
193
  return useTemplateChildren({ parent: slot, callback: updateTemplates });
197
- }, [slot, container, authToken]);
198
- stencilHooks_module.useEffect(() => {
199
- const host = stencilHooks_module.l();
200
- const callback = (e) => {
201
- e.stopPropagation();
202
- setContext({ token: e.detail.token });
203
- };
204
- host.addEventListener(keys.VERIFICATION_EVENT_KEY, callback);
205
- return () => {
206
- host.removeEventListener(keys.VERIFICATION_EVENT_KEY, callback);
207
- };
208
- }, []);
194
+ }, [slot, container, context]);
195
+ // useEffect(() => {
196
+ // const host = useHost();
197
+ // const callback = (e: CustomEvent) => {
198
+ // e.stopPropagation();
199
+ // setContext({ token: e.detail.token });
200
+ // };
201
+ // host.addEventListener(VERIFICATION_EVENT_KEY, callback);
202
+ // return () => {
203
+ // host.removeEventListener(VERIFICATION_EVENT_KEY, callback);
204
+ // };
205
+ // }, []);
209
206
  return (index.h(index.Host, null, index.h("div", { ref: setSlot, style: { display: "contents" } }, index.h("template", { slot: "not-verified" }, index.h("sqm-widget-verification-internal", Object.assign({}, utils.getProps(this)))), index.h("slot", { name: "not-verified" }), index.h("slot", { name: "verified" })), index.h("div", { ref: setContainer }, index.h("slot", { name: "shown" }))));
210
207
  }
211
208
  };
@@ -0,0 +1,170 @@
1
+ 'use strict';
2
+
3
+ const stencilHooks_module = require('./stencil-hooks.module-a5a04d8a.js');
4
+ const index_module = require('./index.module-236d0403.js');
5
+ const index = require('./index-56d1fa5b.js');
6
+
7
+ const UserLookupQuery = index.dist.gql `
8
+ query userLookup {
9
+ viewer {
10
+ ... on User {
11
+ id
12
+ accountId
13
+ email
14
+ impactConnection {
15
+ user {
16
+ id
17
+ email
18
+ }
19
+ }
20
+ }
21
+ }
22
+ }
23
+ `;
24
+ const ParticipantVerificationEmailMutation = index.dist.gql `
25
+ mutation requestUserEmailVerification($user: UserIdInput!) {
26
+ requestUserEmailVerification(user: $user) {
27
+ success
28
+ }
29
+ }
30
+ `;
31
+ const ImpactVerificationEmailMutation = index.dist.gql `
32
+ mutation requestImpactPublisherEmail2FA($user: UserIdInput!) {
33
+ requestImpactPublisherEmail2FA(user: $user) {
34
+ success
35
+ }
36
+ }
37
+ `;
38
+ const VerifyUserEmailMutation = index.dist.gql `
39
+ mutation verifyUserEmail($user: UserIdInput!, $code: String!) {
40
+ verifyUserEmail(user: $user, code: $code) {
41
+ id
42
+ accountId
43
+ email
44
+ emailVerified
45
+ }
46
+ }
47
+ `;
48
+ const SubmitImpactCodeMutation = index.dist.gql `
49
+ mutation submitImpactPublisherEmail2FACode(
50
+ $user: UserIdInput!
51
+ $code: String!
52
+ ) {
53
+ submitImpactPublisherEmail2FACode(user: $user, code: $code) {
54
+ verifiedEmail
55
+ accessKey
56
+ }
57
+ }
58
+ `;
59
+ // ! It's important when using this hook to ensure initialisation
60
+ // ! is done before calling any mutations
61
+ function useVerificationEmail() {
62
+ const userIdentity = index_module.K();
63
+ const [hasEmails, setHasEmails] = stencilHooks_module.useState({
64
+ participant: false,
65
+ impact: false,
66
+ });
67
+ const [fetch] = index_module.an(UserLookupQuery);
68
+ // Send mutations
69
+ const [sendParticipantEmail, { loading: participantEmailLoading, errors: participantEmailErrors },] = index_module.xe(ParticipantVerificationEmailMutation);
70
+ const [sendImpactEmail, { loading: impactEmailLoading, errors: impactEmailErrors },] = index_module.xe(ImpactVerificationEmailMutation);
71
+ const sendLoading = participantEmailLoading || impactEmailLoading;
72
+ const sendErrors = participantEmailErrors || impactEmailErrors;
73
+ // Verification mutations
74
+ const [verifyUserEmail, { loading: verifyMutationLoading, errors: verifyMutationErrors },] = index_module.xe(VerifyUserEmailMutation);
75
+ const [submitImpactCode, { loading: submitImpactCodeLoading, errors: submitImpactCodeErrors },] = index_module.xe(SubmitImpactCodeMutation);
76
+ const verifyLoading = verifyMutationLoading || submitImpactCodeLoading;
77
+ const verifyErrors = verifyMutationErrors || submitImpactCodeErrors;
78
+ const [initialized, setInitialized] = stencilHooks_module.useState(false);
79
+ const initialise = async () => {
80
+ var _a, _b, _c, _d;
81
+ try {
82
+ const lookup = await fetch({});
83
+ if (!lookup || lookup instanceof Error)
84
+ throw new Error();
85
+ setHasEmails({
86
+ participant: !!((_a = lookup === null || lookup === void 0 ? void 0 : lookup.viewer) === null || _a === void 0 ? void 0 : _a.email),
87
+ impact: !!((_d = (_c = (_b = lookup === null || lookup === void 0 ? void 0 : lookup.viewer) === null || _b === void 0 ? void 0 : _b.impactConnection) === null || _c === void 0 ? void 0 : _c.user) === null || _d === void 0 ? void 0 : _d.email),
88
+ });
89
+ setInitialized(true);
90
+ }
91
+ catch (e) {
92
+ console.error("Could not initialise verification", e);
93
+ }
94
+ };
95
+ const sendVerificationEmail = async () => {
96
+ let result = null;
97
+ if (!initialized)
98
+ return result;
99
+ if (!hasEmails.participant && !hasEmails.impact)
100
+ return result;
101
+ try {
102
+ const request = hasEmails.impact ? sendImpactEmail : sendParticipantEmail;
103
+ const res = await request({
104
+ user: {
105
+ id: userIdentity.id,
106
+ accountId: userIdentity.accountId,
107
+ },
108
+ });
109
+ if (res instanceof Error || !res)
110
+ throw new Error();
111
+ result = hasEmails.impact
112
+ ? res.requestImpactPublisherEmail2FA
113
+ : res.requestUserEmailVerification;
114
+ }
115
+ catch (e) {
116
+ console.error("Could not send verification email", e);
117
+ }
118
+ finally {
119
+ return result;
120
+ }
121
+ };
122
+ const verifyVerificationEmail = async (code) => {
123
+ var _a;
124
+ let result = null;
125
+ if (!initialized)
126
+ return result;
127
+ if (!hasEmails.participant && !hasEmails.impact)
128
+ return result;
129
+ try {
130
+ const request = hasEmails.impact ? submitImpactCode : verifyUserEmail;
131
+ const res = await request({
132
+ user: {
133
+ id: userIdentity.id,
134
+ accountId: userIdentity.accountId,
135
+ },
136
+ code,
137
+ });
138
+ if (res instanceof Error || !res)
139
+ throw new Error();
140
+ result = {
141
+ success: true,
142
+ accessKey: hasEmails.impact
143
+ ? (_a = res.submitImpactPublisherEmail2FACode) === null || _a === void 0 ? void 0 : _a.accessKey : undefined,
144
+ };
145
+ }
146
+ catch (e) {
147
+ console.error("Could not verify email", e);
148
+ }
149
+ finally {
150
+ return result;
151
+ }
152
+ };
153
+ stencilHooks_module.useEffect(() => {
154
+ if (!initialized)
155
+ initialise();
156
+ }, []);
157
+ return {
158
+ initialized,
159
+ send: [
160
+ sendVerificationEmail,
161
+ { loading: sendLoading, errors: sendErrors },
162
+ ],
163
+ verify: [
164
+ verifyVerificationEmail,
165
+ { loading: verifyLoading, errors: verifyErrors },
166
+ ],
167
+ };
168
+ }
169
+
170
+ exports.useVerificationEmail = useVerificationEmail;
@@ -110,8 +110,8 @@
110
110
  "./components/sqm-user-name/sqm-user-name.js",
111
111
  "./components/sqm-widget-verification/sqm-widget-verification-internal.js",
112
112
  "./components/sqm-widget-verification/sqm-widget-verification.js",
113
- "./components/sqm-widget-verification/sqm-email-verification/sqm-email-verification.js",
114
113
  "./components/sqm-widget-verification/sqm-code-verification/sqm-code-verification.js",
114
+ "./components/sqm-widget-verification/sqm-email-verification/sqm-email-verification.js",
115
115
  "./components/tax-and-cash/sqm-payout-details-card/sqm-payout-details-card.js",
116
116
  "./components/tax-and-cash/sqm-tax-and-cash/sqm-tax-and-cash.js"
117
117
  ],
@@ -3,12 +3,19 @@ export default {
3
3
  title: "Components/Widget Code Verification",
4
4
  };
5
5
  const defaultProps = {
6
+ initialiseLoading: false,
6
7
  email: "testemail@example.com",
7
8
  loading: false,
8
9
  verifyFailed: false,
9
10
  emailResent: false,
10
11
  };
11
12
  export const Default = () => (h("sqm-code-verification", { demoData: { states: defaultProps } }));
13
+ export const InitialLoading = () => (h("sqm-code-verification", { demoData: {
14
+ states: {
15
+ ...defaultProps,
16
+ initialiseLoading: true,
17
+ },
18
+ } }));
12
19
  export const Loading = () => (h("sqm-code-verification", { demoData: {
13
20
  states: {
14
21
  ...defaultProps,
@@ -122,7 +122,7 @@ export function WidgetCodeVerificationView(props) {
122
122
  h("sl-input", { class: inputClass, name: "code" }),
123
123
  h("sl-input", { class: inputClass, name: "code" })),
124
124
  states.verifyFailed && (h("p", { class: sheet.classes.ErrorText }, text.invalidCodeText)),
125
- h("sl-button", { class: sheet.classes.ContinueButton, onClick: callbacks.submitCode, loading: states.loading, exportparts: "base: primarybutton-base", type: "primary" }, text.verifyText)),
125
+ h("sl-button", { class: sheet.classes.ContinueButton, onClick: callbacks.submitCode, disabled: states.loading || states.initialiseLoading, loading: states.loading || states.initialiseLoading, exportparts: "base: primarybutton-base", type: "primary" }, text.verifyText)),
126
126
  h("div", { class: sheet.classes.FooterContainer },
127
127
  h(TextSpanView, { type: "p" }, resendCodeText)))));
128
128
  }
@@ -233,7 +233,7 @@ export class WidgetCodeVerification {
233
233
  "mutable": false,
234
234
  "complexType": {
235
235
  "original": "DemoData<WidgetCodeVerificationViewProps>",
236
- "resolved": "{ states?: { loading: boolean; email: string; verifyFailed?: boolean; emailResent: boolean; }; refs?: { codeWrapperRef: any; }; }",
236
+ "resolved": "{ states?: { initialiseLoading: boolean; loading: boolean; email: string; verifyFailed?: boolean; emailResent: boolean; }; refs?: { codeWrapperRef: any; }; }",
237
237
  "references": {
238
238
  "DemoData": {
239
239
  "location": "import",
@@ -257,6 +257,24 @@ export class WidgetCodeVerification {
257
257
  }],
258
258
  "text": ""
259
259
  }
260
+ },
261
+ "onVerification": {
262
+ "type": "unknown",
263
+ "mutable": false,
264
+ "complexType": {
265
+ "original": "(token: string) => any",
266
+ "resolved": "(token: string) => any",
267
+ "references": {}
268
+ },
269
+ "required": false,
270
+ "optional": true,
271
+ "docs": {
272
+ "tags": [{
273
+ "text": undefined,
274
+ "name": "undocumented"
275
+ }],
276
+ "text": ""
277
+ }
260
278
  }
261
279
  }; }
262
280
  }
@@ -276,7 +294,7 @@ function useDemoWidgetCodeVerification(props) {
276
294
  },
277
295
  callbacks: {
278
296
  resendEmail: async () => setEmailResent(true),
279
- submitCode: async () => setVerifiedContext({ token: "TOKEN" }),
297
+ submitCode: async () => setVerifiedContext(true),
280
298
  },
281
299
  text: props.getTextProps(),
282
300
  }, props.demoData || {}, { arrayMerge: (_, a) => a });
@@ -1,12 +1,14 @@
1
1
  import { useMutation, useParent, useParentValue, useUserIdentity, } from "@saasquatch/component-boilerplate";
2
2
  import { useEffect, useHost, useState } from "@saasquatch/stencil-hooks";
3
3
  import { gql } from "graphql-request";
4
- import { SHOW_CODE_NAMESPACE, VERIFICATION_EMAIL_NAMESPACE, VERIFICATION_EVENT_KEY, } from "../keys";
5
- import { useVerificationEmailMutation } from "../sqm-email-verification/useEmailVerification";
6
- // TODO: Move to component-boilerplate
4
+ import { SHOW_CODE_NAMESPACE, VERIFICATION_EMAIL_NAMESPACE, } from "../keys";
5
+ import { useVerificationEmail } from "../useVerificationEmail";
7
6
  export const VerifyEmailWithCodeMutation = gql `
8
- mutation verifyUserEmail($user: UserIdInput!, $code: String!) {
9
- verifyUserEmail(user: $user, code: $code) {
7
+ mutation submitImpactPublisherEmail2FACode(
8
+ $user: UserIdInput!
9
+ $code: String!
10
+ ) {
11
+ submitImpactPublisherEmail2FACode(user: $user, code: $code) {
10
12
  verifiedEmail
11
13
  accessKey
12
14
  }
@@ -44,9 +46,10 @@ export function useWidgetCodeVerification(props) {
44
46
  const [codeRef, setCodeRef] = useState(null);
45
47
  const [validationError, setValidationError] = useState(false);
46
48
  const [emailError, setEmailError] = useState(false);
47
- // TODO: Need to handle error states for these errors
48
- const [verifyUser, { loading: verifyLoading, errors: verifyErrors }] = useCodeVerificationMutation();
49
- const [request, { loading: resendLoading, data, errors: resendErrors }] = useVerificationEmailMutation();
49
+ // // TODO: Need to handle error states for these errors
50
+ // const [verifyUser, { loading: verifyLoading, errors: verifyErrors }] =
51
+ // useCodeVerificationMutation();
52
+ const { initialized, send: [sendEmail, { loading: sendLoading, errors: sendErrors }], verify: [verifyEmail, { loading: verifyLoading, errors: verifyErrors }], } = useVerificationEmail();
50
53
  useEffect(() => {
51
54
  if (!codeRef)
52
55
  return;
@@ -62,7 +65,7 @@ export function useWidgetCodeVerification(props) {
62
65
  }
63
66
  });
64
67
  element.addEventListener("input", (e) => {
65
- const input = e.target.value;
68
+ const input = e.data;
66
69
  if (!input)
67
70
  return;
68
71
  if (idx === codeElements.length - 1) {
@@ -72,8 +75,10 @@ export function useWidgetCodeVerification(props) {
72
75
  if (input.length > 1) {
73
76
  const rest = input.slice(1);
74
77
  e.target.value = input.slice(0, 1);
75
- codeElements[idx + 1].value = rest;
76
- codeElements[idx + 1].dispatchEvent(new Event("input"));
78
+ codeElements[idx + 1].dispatchEvent(new InputEvent("input", {
79
+ inputType: "insertFromPaste",
80
+ data: rest,
81
+ }));
77
82
  }
78
83
  codeElements[idx + 1].focus();
79
84
  });
@@ -84,7 +89,10 @@ export function useWidgetCodeVerification(props) {
84
89
  setValidationError(false);
85
90
  };
86
91
  const resendEmail = async () => {
87
- const result = await request();
92
+ // UI should only allow this to be called if initialized, but checking just in case
93
+ if (!initialized)
94
+ return;
95
+ const result = await sendEmail();
88
96
  if (!result) {
89
97
  setEmailError(true);
90
98
  return;
@@ -104,16 +112,13 @@ export function useWidgetCodeVerification(props) {
104
112
  codeElements.forEach((element) => {
105
113
  code = `${code}${element.value}`;
106
114
  });
115
+ // UI should only allow this to be called if initialized, but checking just in case
116
+ if (!initialized)
117
+ return;
107
118
  setValidationError(false);
108
- // Only 123456 passes for a valid code rn
109
- const res = await verifyUser(code);
110
- if (res) {
111
- const event = new CustomEvent(VERIFICATION_EVENT_KEY, {
112
- detail: { token: res.verifyUserEmail.accessKey },
113
- composed: true,
114
- bubbles: true,
115
- });
116
- host.dispatchEvent(event);
119
+ const res = await verifyEmail(code);
120
+ if (res === null || res === void 0 ? void 0 : res.success) {
121
+ props.onVerification(res.accessKey);
117
122
  reset();
118
123
  }
119
124
  else {
@@ -121,12 +126,15 @@ export function useWidgetCodeVerification(props) {
121
126
  }
122
127
  };
123
128
  useEffect(() => {
129
+ // Wait for mutations to be determined from user lookup
130
+ if (!initialized)
131
+ return;
124
132
  // email should already exist if user has completed email-verification
125
133
  if (!email)
126
134
  resendEmail();
127
135
  else
128
136
  setEmailSent(true);
129
- }, []);
137
+ }, [initialized]);
130
138
  return {
131
139
  refs: {
132
140
  codeWrapperRef: setCodeRef,
@@ -134,8 +142,9 @@ export function useWidgetCodeVerification(props) {
134
142
  states: {
135
143
  email,
136
144
  emailResent,
137
- resendError: !!(resendErrors === null || resendErrors === void 0 ? void 0 : resendErrors.message) || emailError,
138
- loading: verifyLoading || resendLoading,
145
+ resendError: sendErrors || verifyErrors,
146
+ initialiseLoading: !initialized,
147
+ loading: sendLoading || verifyLoading,
139
148
  verifyFailed: !!validationError,
140
149
  },
141
150
  callbacks: {
@@ -2,13 +2,7 @@ import { useMutation, useParent, useQuery, useUserIdentity, } from "@saasquatch/
2
2
  import { useEffect, useState } from "@saasquatch/universal-hooks";
3
3
  import { gql } from "graphql-request";
4
4
  import { SHOW_CODE_NAMESPACE, VERIFICATION_EMAIL_NAMESPACE } from "../keys";
5
- export const VerificationEmailMutation = gql `
6
- mutation requestUserEmailVerification($user: UserIdInput!) {
7
- requestUserEmailVerification(user: $user) {
8
- success
9
- }
10
- }
11
- `;
5
+ import { useVerificationEmail } from "../useVerificationEmail";
12
6
  export const UpsertUserEmailMutation = gql `
13
7
  mutation upsertUser($userInput: UserInput!) {
14
8
  user(userInput: $userInput) {
@@ -25,40 +19,16 @@ export const UserLookupQuery = gql `
25
19
  id
26
20
  accountId
27
21
  email
22
+ impactConnection {
23
+ user {
24
+ id
25
+ email
26
+ }
27
+ }
28
28
  }
29
29
  }
30
30
  }
31
31
  `;
32
- // TODO: Move to component-boilerplate
33
- export function useVerificationEmailMutation() {
34
- const user = useUserIdentity();
35
- const [request, { loading: loading, data, errors }] = useMutation(VerificationEmailMutation);
36
- const sendVerificationEmailMutation = async () => {
37
- try {
38
- const result = await request({
39
- user: {
40
- id: user.id,
41
- accountId: user.accountId,
42
- },
43
- });
44
- if (result instanceof Error || !result)
45
- throw new Error();
46
- return result;
47
- }
48
- catch (e) {
49
- console.error("Could not send verification email", e);
50
- return undefined;
51
- }
52
- };
53
- return [
54
- sendVerificationEmailMutation,
55
- {
56
- loading,
57
- data,
58
- errors,
59
- },
60
- ];
61
- }
62
32
  export function useUpsertUserEmail() {
63
33
  const user = useUserIdentity();
64
34
  const [request, { loading: loading, data, errors }] = useMutation(UpsertUserEmailMutation);
@@ -95,9 +65,9 @@ export function useWidgetEmailVerification(props) {
95
65
  const [emailExists, setEmailExists] = useState(false);
96
66
  const [error, setError] = useState(false);
97
67
  const [mutationError, setMutationError] = useState(false);
98
- const [sendVerificationEmailMutation] = useVerificationEmailMutation();
68
+ const { initialized, send: [sendEmail, { loading: sendLoading, errors }], } = useVerificationEmail();
99
69
  const [upsertUserEmail] = useUpsertUserEmail();
100
- const [loading, setLoading] = useState(false);
70
+ const [loading, setLoading] = useState(true);
101
71
  const { data, loading: initialLoading } = useQuery(UserLookupQuery, {});
102
72
  const emailRegex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
103
73
  useEffect(() => {
@@ -105,6 +75,10 @@ export function useWidgetEmailVerification(props) {
105
75
  return;
106
76
  setEmailExists(!!data.viewer.email);
107
77
  }, [data]);
78
+ useEffect(() => {
79
+ if (initialized)
80
+ setLoading(false);
81
+ }, [initialized]);
108
82
  const submitEmail = async (e) => {
109
83
  e.preventDefault();
110
84
  if (!(data === null || data === void 0 ? void 0 : data.viewer))
@@ -123,8 +97,11 @@ export function useWidgetEmailVerification(props) {
123
97
  if (!result || !result.user.email)
124
98
  setError(true);
125
99
  }
126
- const result = await sendVerificationEmailMutation();
127
- if (!result || !result.requestUserEmailVerification.success)
100
+ // UI should not allow this call til initialisation is done
101
+ if (!initialized)
102
+ return;
103
+ const result = await sendEmail();
104
+ if (!result || !result.success)
128
105
  setMutationError(true);
129
106
  else {
130
107
  // This is used to let the code verification widget know an email was already sent
@@ -139,7 +116,7 @@ export function useWidgetEmailVerification(props) {
139
116
  },
140
117
  states: {
141
118
  loading,
142
- initialLoading,
119
+ initialLoading: initialLoading && !initialized,
143
120
  error,
144
121
  email: data === null || data === void 0 ? void 0 : data.viewer.email,
145
122
  sendCodeError: mutationError,