@saasquatch/mint-components 1.12.0-1 → 1.12.0-10

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 (158) hide show
  1. package/dist/cjs/{ShadowViewAddon-88821c64.js → ShadowViewAddon-040cffad.js} +6 -3
  2. package/dist/cjs/extractProps-fd93ba62.js +21 -0
  3. package/dist/cjs/loader.cjs.js +1 -1
  4. package/dist/cjs/mint-components.cjs.js +1 -1
  5. package/dist/cjs/sqm-banking-info-form_16.cjs.entry.js +91 -72
  6. package/dist/cjs/sqm-big-stat_39.cjs.entry.js +128 -63
  7. package/dist/cjs/sqm-code-verification.cjs.entry.js +67 -77
  8. package/dist/cjs/sqm-email-verification.cjs.entry.js +158 -12
  9. package/dist/cjs/{sqm-invoice-table-view-ce9a34ac.js → sqm-invoice-table-view-c58966f8.js} +79 -0
  10. package/dist/cjs/sqm-stencilbook.cjs.entry.js +56 -14
  11. package/dist/cjs/sqm-widget-verification-internal.cjs.entry.js +81 -11
  12. package/dist/cjs/sqm-widget-verification.cjs.entry.js +102 -19
  13. package/dist/cjs/usePayoutStatus-b9fb7399.js +70 -0
  14. package/dist/cjs/useVerificationEmail-6aacdb71.js +169 -0
  15. package/dist/collection/collection-manifest.json +1 -1
  16. package/dist/collection/components/sqm-big-stat/useBigStat.js +6 -3
  17. package/dist/collection/components/sqm-payout-button-scroll/PayoutButtonScroll.stories.js +1 -2
  18. package/dist/collection/components/sqm-payout-button-scroll/sqm-payout-button-scroll-view.js +1 -0
  19. package/dist/collection/components/sqm-payout-button-scroll/sqm-payout-button-scroll.js +16 -3
  20. package/dist/collection/components/sqm-widget-verification/sqm-code-verification/WidgetCodeVerification.stories.js +9 -2
  21. package/dist/collection/components/sqm-widget-verification/sqm-code-verification/sqm-code-verification-view.js +20 -10
  22. package/dist/collection/components/sqm-widget-verification/sqm-code-verification/sqm-code-verification.js +34 -63
  23. package/dist/collection/components/sqm-widget-verification/sqm-code-verification/useCodeVerification.js +38 -29
  24. package/dist/collection/components/sqm-widget-verification/sqm-email-verification/WidgetEmailVerification.stories.js +23 -3
  25. package/dist/collection/components/sqm-widget-verification/sqm-email-verification/sqm-email-verification-view.js +17 -4
  26. package/dist/collection/components/sqm-widget-verification/sqm-email-verification/sqm-email-verification.js +65 -11
  27. package/dist/collection/components/sqm-widget-verification/sqm-email-verification/useEmailVerification.js +76 -20
  28. package/dist/collection/components/sqm-widget-verification/sqm-widget-verification-internal.js +327 -15
  29. package/dist/collection/components/sqm-widget-verification/sqm-widget-verification.js +447 -22
  30. package/dist/collection/components/sqm-widget-verification/useVerificationEmail.js +165 -0
  31. package/dist/collection/components/tax-and-cash/BankingForm.stories.js +1 -0
  32. package/dist/collection/components/tax-and-cash/TaxForm.stories.js +78 -0
  33. package/dist/collection/components/tax-and-cash/sqm-banking-info-form/sqm-banking-info-form.js +2 -1
  34. package/dist/collection/components/tax-and-cash/sqm-banking-info-form/useBankingInfoForm.js +7 -0
  35. package/dist/collection/components/tax-and-cash/sqm-docusign-form/docusign-iframe/DocusignIframe.js +0 -1
  36. package/dist/collection/components/tax-and-cash/sqm-payout-status-alert/PayoutStatusAlert.stories.js +10 -0
  37. package/dist/collection/components/tax-and-cash/sqm-payout-status-alert/sqm-payout-status-alert-view.js +72 -13
  38. package/dist/collection/components/tax-and-cash/sqm-payout-status-alert/sqm-payout-status-alert.js +146 -9
  39. package/dist/collection/components/tax-and-cash/sqm-payout-status-alert/usePayoutStatus.js +30 -15
  40. package/dist/collection/components/tax-and-cash/sqm-tax-and-cash/data.js +6 -0
  41. package/dist/collection/components/tax-and-cash/sqm-tax-and-cash/sqm-tax-and-cash.js +8 -8
  42. package/dist/collection/components/tax-and-cash/sqm-tax-and-cash/useTaxAndCash.js +2 -2
  43. package/dist/collection/components/tax-and-cash/sqm-tax-and-cash-dashboard/sqm-tax-and-cash-dashboard-view.js +22 -16
  44. package/dist/collection/components/tax-and-cash/sqm-tax-and-cash-dashboard/sqm-tax-and-cash-dashboard.js +99 -88
  45. package/dist/collection/components/tax-and-cash/sqm-tax-and-cash-dashboard/useTaxAndCashDashboard.js +8 -1
  46. package/dist/collection/components/tax-and-cash/sqm-user-info-form/useUserInfoForm.js +16 -11
  47. package/dist/esm/{ShadowViewAddon-65c8679e.js → ShadowViewAddon-69b61037.js} +6 -3
  48. package/dist/esm/extractProps-ae1afbb3.js +19 -0
  49. package/dist/esm/{keys-a1496e39.js → keys-db1897ae.js} +1 -1
  50. package/dist/esm/loader.js +1 -1
  51. package/dist/esm/mint-components.js +1 -1
  52. package/dist/esm/sqm-banking-info-form_16.entry.js +91 -72
  53. package/dist/esm/sqm-big-stat_39.entry.js +127 -62
  54. package/dist/esm/sqm-code-verification.entry.js +69 -79
  55. package/dist/esm/sqm-email-verification.entry.js +159 -13
  56. package/dist/esm/{sqm-invoice-table-view-08c03ba7.js → sqm-invoice-table-view-d1cfdaf4.js} +79 -0
  57. package/dist/esm/sqm-stencilbook.entry.js +56 -14
  58. package/dist/esm/sqm-widget-verification-internal.entry.js +84 -14
  59. package/dist/esm/sqm-widget-verification.entry.js +104 -21
  60. package/dist/esm/usePayoutStatus-1a635054.js +67 -0
  61. package/dist/esm/useVerificationEmail-c32696ba.js +167 -0
  62. package/dist/esm-es5/ShadowViewAddon-69b61037.js +1 -0
  63. package/dist/esm-es5/extractProps-ae1afbb3.js +1 -0
  64. package/dist/esm-es5/{keys-a1496e39.js → keys-db1897ae.js} +1 -1
  65. package/dist/esm-es5/loader.js +1 -1
  66. package/dist/esm-es5/mint-components.js +1 -1
  67. package/dist/esm-es5/sqm-banking-info-form_16.entry.js +1 -1
  68. package/dist/esm-es5/sqm-big-stat_39.entry.js +1 -1
  69. package/dist/esm-es5/sqm-code-verification.entry.js +1 -1
  70. package/dist/esm-es5/sqm-email-verification.entry.js +1 -1
  71. package/dist/esm-es5/sqm-invoice-table-view-d1cfdaf4.js +1 -0
  72. package/dist/esm-es5/sqm-stencilbook.entry.js +1 -1
  73. package/dist/esm-es5/sqm-widget-verification-internal.entry.js +1 -1
  74. package/dist/esm-es5/sqm-widget-verification.entry.js +1 -1
  75. package/dist/esm-es5/usePayoutStatus-1a635054.js +1 -0
  76. package/dist/esm-es5/useVerificationEmail-c32696ba.js +1 -0
  77. package/dist/mint-components/mint-components.esm.js +1 -1
  78. package/dist/mint-components/p-15c7a1d2.system.entry.js +1 -0
  79. package/dist/mint-components/p-1712a9fd.entry.js +11 -0
  80. package/dist/mint-components/p-1e616d45.system.js +1 -0
  81. package/dist/mint-components/{p-721a89c6.entry.js → p-24092973.entry.js} +2 -2
  82. package/dist/mint-components/p-26468242.js +1 -0
  83. package/dist/mint-components/p-331d060e.entry.js +223 -0
  84. package/dist/mint-components/p-39840341.js +1 -0
  85. package/dist/mint-components/p-4364001c.entry.js +12 -0
  86. package/dist/mint-components/p-4bd7a472.js +1 -0
  87. package/dist/mint-components/p-517224ef.js +19 -0
  88. package/dist/mint-components/p-5a23b560.system.entry.js +1 -0
  89. package/dist/mint-components/p-8300d8c8.system.js +1 -0
  90. package/dist/mint-components/p-8bddb468.system.entry.js +1 -0
  91. package/dist/mint-components/p-9596e97c.system.entry.js +1 -0
  92. package/dist/mint-components/p-974070c4.system.entry.js +1 -0
  93. package/dist/mint-components/{p-b651706a.js → p-9eae245f.js} +6 -3
  94. package/dist/mint-components/p-a8645c1b.system.js +1 -0
  95. package/dist/mint-components/p-b2a99637.system.js +1 -0
  96. package/dist/mint-components/{p-66a04cca.system.entry.js → p-b62faaa5.system.entry.js} +1 -1
  97. package/dist/mint-components/p-c41e1df8.entry.js +195 -0
  98. package/dist/mint-components/p-c510fb88.entry.js +1 -0
  99. package/dist/mint-components/p-ca809fdd.system.js +1 -1
  100. package/dist/mint-components/p-d7806f31.js +48 -0
  101. package/dist/mint-components/p-e01ac27c.system.js +1 -0
  102. package/dist/mint-components/p-e45a8501.system.entry.js +1 -0
  103. package/dist/mint-components/p-e990dc21.system.js +1 -0
  104. package/dist/mint-components/p-f340214f.entry.js +25 -0
  105. package/dist/types/components/sqm-payout-button-scroll/PayoutButtonScroll.stories.d.ts +0 -1
  106. package/dist/types/components/sqm-payout-button-scroll/sqm-payout-button-scroll.d.ts +7 -0
  107. package/dist/types/components/sqm-widget-verification/sqm-code-verification/WidgetCodeVerification.stories.d.ts +1 -0
  108. package/dist/types/components/sqm-widget-verification/sqm-code-verification/sqm-code-verification-view.d.ts +3 -3
  109. package/dist/types/components/sqm-widget-verification/sqm-code-verification/sqm-code-verification.d.ts +4 -10
  110. package/dist/types/components/sqm-widget-verification/sqm-code-verification/useCodeVerification.d.ts +2 -0
  111. package/dist/types/components/sqm-widget-verification/sqm-email-verification/WidgetEmailVerification.stories.d.ts +4 -1
  112. package/dist/types/components/sqm-widget-verification/sqm-email-verification/sqm-email-verification-view.d.ts +6 -1
  113. package/dist/types/components/sqm-widget-verification/sqm-email-verification/sqm-email-verification.d.ts +10 -2
  114. package/dist/types/components/sqm-widget-verification/sqm-email-verification/useEmailVerification.d.ts +3 -2
  115. package/dist/types/components/sqm-widget-verification/sqm-widget-verification-internal.d.ts +15 -0
  116. package/dist/types/components/sqm-widget-verification/sqm-widget-verification.d.ts +79 -0
  117. package/dist/types/components/sqm-widget-verification/useVerificationEmail.d.ts +14 -0
  118. package/dist/types/components/tax-and-cash/TaxForm.stories.d.ts +1 -0
  119. package/dist/types/components/tax-and-cash/sqm-banking-info-form/sqm-banking-info-form-view.d.ts +1 -0
  120. package/dist/types/components/tax-and-cash/sqm-payout-status-alert/PayoutStatusAlert.stories.d.ts +2 -0
  121. package/dist/types/components/tax-and-cash/sqm-payout-status-alert/sqm-payout-status-alert-view.d.ts +12 -0
  122. package/dist/types/components/tax-and-cash/sqm-payout-status-alert/sqm-payout-status-alert.d.ts +41 -0
  123. package/dist/types/components/tax-and-cash/sqm-payout-status-alert/usePayoutStatus.d.ts +12 -0
  124. package/dist/types/components/tax-and-cash/sqm-tax-and-cash/data.d.ts +6 -0
  125. package/dist/types/components/tax-and-cash/sqm-tax-and-cash/sqm-tax-and-cash.d.ts +2 -2
  126. package/dist/types/components/tax-and-cash/sqm-tax-and-cash-dashboard/sqm-tax-and-cash-dashboard-view.d.ts +10 -3
  127. package/dist/types/components/tax-and-cash/sqm-tax-and-cash-dashboard/sqm-tax-and-cash-dashboard.d.ts +19 -18
  128. package/dist/types/components.d.ts +366 -92
  129. package/docs/docs.docx +0 -0
  130. package/docs/raisins.json +1 -1
  131. package/grapesjs/grapesjs.js +1 -1
  132. package/package.json +1 -1
  133. package/dist/cjs/useEmailVerification-30a1c7f6.js +0 -75
  134. package/dist/collection/components/sqm-widget-verification/useWidgetVerification.js +0 -3
  135. package/dist/esm/useEmailVerification-7135732c.js +0 -72
  136. package/dist/esm-es5/ShadowViewAddon-65c8679e.js +0 -1
  137. package/dist/esm-es5/sqm-invoice-table-view-08c03ba7.js +0 -1
  138. package/dist/esm-es5/useEmailVerification-7135732c.js +0 -1
  139. package/dist/mint-components/p-117b4705.system.js +0 -1
  140. package/dist/mint-components/p-1bd0cda8.system.entry.js +0 -1
  141. package/dist/mint-components/p-1ee62d9f.system.entry.js +0 -1
  142. package/dist/mint-components/p-1f9a9b70.system.entry.js +0 -1
  143. package/dist/mint-components/p-23fdd44e.entry.js +0 -1
  144. package/dist/mint-components/p-36f7caec.system.entry.js +0 -1
  145. package/dist/mint-components/p-39397731.entry.js +0 -1
  146. package/dist/mint-components/p-39af4acd.entry.js +0 -240
  147. package/dist/mint-components/p-4c9b6fbe.system.js +0 -1
  148. package/dist/mint-components/p-65e2c043.system.js +0 -1
  149. package/dist/mint-components/p-663303b7.entry.js +0 -8
  150. package/dist/mint-components/p-6cae44d7.js +0 -1
  151. package/dist/mint-components/p-7f5c7bf7.system.entry.js +0 -1
  152. package/dist/mint-components/p-8a337864.js +0 -7
  153. package/dist/mint-components/p-a02afa72.system.js +0 -1
  154. package/dist/mint-components/p-a5a9aa07.entry.js +0 -189
  155. package/dist/mint-components/p-c763c0b2.js +0 -1
  156. package/dist/mint-components/p-e93e5740.entry.js +0 -1
  157. package/dist/mint-components/p-e9ca48fc.system.entry.js +0 -1
  158. package/dist/types/components/sqm-widget-verification/useWidgetVerification.d.ts +0 -1
@@ -1,16 +1,17 @@
1
- import { isDemo } from "@saasquatch/component-boilerplate";
2
- import { withHooks } from "@saasquatch/stencil-hooks";
1
+ import { isDemo, useSetParent } from "@saasquatch/component-boilerplate";
2
+ import { useState, withHooks } from "@saasquatch/stencil-hooks";
3
3
  import { Component, h, Prop } from "@stencil/core";
4
4
  import deepmerge from "deepmerge";
5
5
  import { getProps } from "../../../utils/utils";
6
6
  import { WidgetCodeVerificationView, } from "./sqm-code-verification-view";
7
7
  import { useWidgetCodeVerification } from "./useCodeVerification";
8
+ import { VERIFICATION_PARENT_NAMESPACE } from "../keys";
8
9
  export class WidgetCodeVerification {
9
10
  constructor() {
10
11
  /**
11
12
  * @uiName Verify code widget header text
12
13
  */
13
- this.verifyCodeHeaderText = "Enter the code sent to email@example.com from our referral provider, impact.com.";
14
+ this.verifyCodeHeaderText = "Enter the code sent to {email} from our referral provider, impact.com.";
14
15
  /**
15
16
  * @uiName Reverify code widget header text
16
17
  */
@@ -25,27 +26,16 @@ export class WidgetCodeVerification {
25
26
  * @uiName Resend code label
26
27
  */
27
28
  this.resendCodeLabel = "Resend code";
28
- /**
29
- * The link that appears in the resend code link
30
- * @uiName Resend code link
31
- */
32
- // AL: TODO connect route to resend verification code
33
- this.resendCodeLink = "/resend-code";
34
29
  /**
35
30
  * Link text displayed under verify button
36
31
  * @uiName Resend code text
37
32
  */
38
33
  this.codeResentSuccessfullyText = "Another code has been sent to {email}";
39
- /**
40
- * Link text displayed under the verify button
41
- * @uiName Use different email text
42
- */
43
- this.useDifferentEmailText = "Use a different email";
44
34
  /**
45
35
  * Error text displayed under verification input
46
36
  * @uiName Invalid code text
47
37
  */
48
- this.invalidCodeText = " Please check your code and try again. If you’re still having trouble, try resending your code.";
38
+ this.invalidCodeText = "Please check your code and try again. If you’re still having trouble, try resending your code.";
49
39
  /**
50
40
  * @uiName Verify code button text
51
41
  */
@@ -89,7 +79,7 @@ export class WidgetCodeVerification {
89
79
  },
90
80
  "attribute": "verify-code-header-text",
91
81
  "reflect": false,
92
- "defaultValue": "\"Enter the code sent to email@example.com from our referral provider, impact.com.\""
82
+ "defaultValue": "\"Enter the code sent to {email} from our referral provider, impact.com.\""
93
83
  },
94
84
  "reverifyCodeHeaderText": {
95
85
  "type": "string",
@@ -154,27 +144,6 @@ export class WidgetCodeVerification {
154
144
  "reflect": false,
155
145
  "defaultValue": "\"Resend code\""
156
146
  },
157
- "resendCodeLink": {
158
- "type": "string",
159
- "mutable": false,
160
- "complexType": {
161
- "original": "string",
162
- "resolved": "string",
163
- "references": {}
164
- },
165
- "required": false,
166
- "optional": false,
167
- "docs": {
168
- "tags": [{
169
- "text": "Resend code link",
170
- "name": "uiName"
171
- }],
172
- "text": "The link that appears in the resend code link"
173
- },
174
- "attribute": "resend-code-link",
175
- "reflect": false,
176
- "defaultValue": "\"/resend-code\""
177
- },
178
147
  "codeResentSuccessfullyText": {
179
148
  "type": "string",
180
149
  "mutable": false,
@@ -196,27 +165,6 @@ export class WidgetCodeVerification {
196
165
  "reflect": false,
197
166
  "defaultValue": "\"Another code has been sent to {email}\""
198
167
  },
199
- "useDifferentEmailText": {
200
- "type": "string",
201
- "mutable": false,
202
- "complexType": {
203
- "original": "string",
204
- "resolved": "string",
205
- "references": {}
206
- },
207
- "required": false,
208
- "optional": false,
209
- "docs": {
210
- "tags": [{
211
- "text": "Use different email text",
212
- "name": "uiName"
213
- }],
214
- "text": "Link text displayed under the verify button"
215
- },
216
- "attribute": "use-different-email-text",
217
- "reflect": false,
218
- "defaultValue": "\"Use a different email\""
219
- },
220
168
  "invalidCodeText": {
221
169
  "type": "string",
222
170
  "mutable": false,
@@ -236,7 +184,7 @@ export class WidgetCodeVerification {
236
184
  },
237
185
  "attribute": "invalid-code-text",
238
186
  "reflect": false,
239
- "defaultValue": "\" Please check your code and try again. If you\u2019re still having trouble, try resending your code.\""
187
+ "defaultValue": "\"Please check your code and try again. If you\u2019re still having trouble, try resending your code.\""
240
188
  },
241
189
  "verifyText": {
242
190
  "type": "string",
@@ -285,7 +233,7 @@ export class WidgetCodeVerification {
285
233
  "mutable": false,
286
234
  "complexType": {
287
235
  "original": "DemoData<WidgetCodeVerificationViewProps>",
288
- "resolved": "{ states?: { loading: boolean; email: string; verifyFailed?: boolean; codeResent?: boolean; }; refs?: { codeWrapperRef: any; }; }",
236
+ "resolved": "{ states?: { initialiseLoading: boolean; loading: boolean; email: string; verifyFailed?: boolean; emailResent: boolean; }; refs?: { codeWrapperRef: any; }; }",
289
237
  "references": {
290
238
  "DemoData": {
291
239
  "location": "import",
@@ -309,21 +257,44 @@ export class WidgetCodeVerification {
309
257
  }],
310
258
  "text": ""
311
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
+ }
312
278
  }
313
279
  }; }
314
280
  }
315
281
  function useDemoWidgetCodeVerification(props) {
282
+ const [emailResent, setEmailResent] = useState(false);
283
+ const setVerifiedContext = useSetParent(VERIFICATION_PARENT_NAMESPACE);
316
284
  return deepmerge({
317
285
  states: {
318
286
  loading: false,
319
- email: "",
320
- verifyFailed: false,
287
+ email: "test@example.com",
288
+ emailResent,
289
+ resendError: true,
290
+ verifyFailed: true,
321
291
  },
322
292
  refs: {
323
293
  codeWrapperRef: () => { },
324
294
  },
325
295
  callbacks: {
326
- submitCode: async () => { },
296
+ resendEmail: async () => setEmailResent(true),
297
+ submitCode: async () => setVerifiedContext(true),
327
298
  },
328
299
  text: props.getTextProps(),
329
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
- import { SHOW_CODE_NAMESPACE, VERIFICATION_EMAIL_NAMESPACE, VERIFICATION_EVENT_KEY, } from "../keys";
4
- import { useVerificationEmailMutation } from "../sqm-email-verification/useEmailVerification";
5
3
  import { gql } from "graphql-request";
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
  }
@@ -43,9 +45,8 @@ export function useWidgetCodeVerification(props) {
43
45
  const [emailResent, setEmailResent] = useState(false);
44
46
  const [codeRef, setCodeRef] = useState(null);
45
47
  const [validationError, setValidationError] = useState(false);
46
- // TODO: Need to handle error states for these errors
47
- const [verifyUser, { loading: verifyLoading, errors: verifyErrors }] = useCodeVerificationMutation();
48
- const [request, { loading: resendLoading, data, errors: resendErrors }] = useVerificationEmailMutation();
48
+ const [emailError, setEmailError] = useState(false);
49
+ const { initialized, send: [sendEmail, { loading: sendLoading, errors: sendErrors }], verify: [verifyEmail, { loading: verifyLoading, errors: verifyErrors }], } = useVerificationEmail();
49
50
  useEffect(() => {
50
51
  if (!codeRef)
51
52
  return;
@@ -61,7 +62,7 @@ export function useWidgetCodeVerification(props) {
61
62
  }
62
63
  });
63
64
  element.addEventListener("input", (e) => {
64
- const input = e.target.value;
65
+ const input = e.data;
65
66
  if (!input)
66
67
  return;
67
68
  if (idx === codeElements.length - 1) {
@@ -71,8 +72,10 @@ export function useWidgetCodeVerification(props) {
71
72
  if (input.length > 1) {
72
73
  const rest = input.slice(1);
73
74
  e.target.value = input.slice(0, 1);
74
- codeElements[idx + 1].value = rest;
75
- codeElements[idx + 1].dispatchEvent(new Event("input"));
75
+ codeElements[idx + 1].dispatchEvent(new InputEvent("input", {
76
+ inputType: "insertFromPaste",
77
+ data: rest,
78
+ }));
76
79
  }
77
80
  codeElements[idx + 1].focus();
78
81
  });
@@ -83,14 +86,16 @@ export function useWidgetCodeVerification(props) {
83
86
  setValidationError(false);
84
87
  };
85
88
  const resendEmail = async () => {
86
- // TODO: Error checks, depends on what mutation is set up as
87
- const result = await request();
88
- if (emailSent) {
89
- setEmailResent(true);
90
- setTimeout(() => {
91
- setEmailResent(false);
92
- }, 500);
89
+ // UI should only allow this to be called if initialized, but checking just in case
90
+ if (!initialized)
91
+ return;
92
+ const result = await sendEmail();
93
+ if (!result) {
94
+ setEmailError(true);
95
+ return;
93
96
  }
97
+ if (emailSent)
98
+ setEmailResent(true);
94
99
  setEmailSent(true);
95
100
  };
96
101
  const submitCode = async () => {
@@ -104,16 +109,13 @@ export function useWidgetCodeVerification(props) {
104
109
  codeElements.forEach((element) => {
105
110
  code = `${code}${element.value}`;
106
111
  });
112
+ // UI should only allow this to be called if initialized, but checking just in case
113
+ if (!initialized)
114
+ return;
107
115
  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);
116
+ const res = await verifyEmail(code);
117
+ if (res === null || res === void 0 ? void 0 : res.success) {
118
+ props.onVerification(res.accessKey);
117
119
  reset();
118
120
  }
119
121
  else {
@@ -121,10 +123,15 @@ export function useWidgetCodeVerification(props) {
121
123
  }
122
124
  };
123
125
  useEffect(() => {
126
+ // Wait for mutations to be determined from user lookup
127
+ if (!initialized)
128
+ return;
124
129
  // email should already exist if user has completed email-verification
125
130
  if (!email)
126
131
  resendEmail();
127
- }, []);
132
+ else
133
+ setEmailSent(true);
134
+ }, [initialized]);
128
135
  return {
129
136
  refs: {
130
137
  codeWrapperRef: setCodeRef,
@@ -132,7 +139,9 @@ export function useWidgetCodeVerification(props) {
132
139
  states: {
133
140
  email,
134
141
  emailResent,
135
- loading: verifyLoading || resendLoading,
142
+ resendError: sendErrors || verifyErrors,
143
+ initialiseLoading: !initialized,
144
+ loading: sendLoading || verifyLoading,
136
145
  verifyFailed: !!validationError,
137
146
  },
138
147
  callbacks: {
@@ -4,19 +4,39 @@ export default {
4
4
  };
5
5
  const defaultProps = {
6
6
  email: "",
7
- error: "",
7
+ error: false,
8
8
  loading: false,
9
+ initialLoading: false,
10
+ sendCodeError: false,
9
11
  };
10
12
  export const Default = () => (h("sqm-email-verification", { demoData: {} }));
13
+ export const EmailIsPrefilled = () => (h("sqm-email-verification", { demoData: {
14
+ states: {
15
+ ...defaultProps,
16
+ email: "test@example.com",
17
+ },
18
+ } }));
11
19
  export const Loading = () => (h("sqm-email-verification", { demoData: {
20
+ states: {
21
+ ...defaultProps,
22
+ initialLoading: true,
23
+ },
24
+ } }));
25
+ export const SaveLoading = () => (h("sqm-email-verification", { demoData: {
12
26
  states: {
13
27
  ...defaultProps,
14
28
  loading: true,
15
29
  },
16
30
  } }));
17
- export const Error = () => (h("sqm-email-verification", { demoData: {
31
+ export const InvalidEmail = () => (h("sqm-email-verification", { demoData: {
32
+ states: {
33
+ ...defaultProps,
34
+ error: true,
35
+ },
36
+ } }));
37
+ export const SendCodeError = () => (h("sqm-email-verification", { demoData: {
18
38
  states: {
19
39
  ...defaultProps,
20
- error: "Email is invalid",
40
+ sendCodeError: true,
21
41
  },
22
42
  } }));
@@ -15,6 +15,16 @@ const style = {
15
15
  flexDirection: "column",
16
16
  maxWidth: "320px",
17
17
  },
18
+ ErrorAlertContainer: {
19
+ "&::part(base)": {
20
+ backgroundColor: "var(--sl-color-red-100)",
21
+ borderTop: "none",
22
+ },
23
+ "&::part(message)": {
24
+ display: "flex",
25
+ flexDirection: "column",
26
+ },
27
+ },
18
28
  ContinueButton: {
19
29
  width: "100%",
20
30
  maxWidth: "100px",
@@ -63,15 +73,18 @@ export function WidgetEmailVerificationView(props) {
63
73
  h("style", { type: "text/css" },
64
74
  vanillaStyle,
65
75
  styleString),
66
- states.loading ? (renderLoadingSkeleton()) : (h("div", { class: sheet.classes.Wrapper },
67
- " ",
76
+ states.sendCodeError && (h("sl-alert", { exportparts: "base: alert-base, icon:alert-icon", type: "danger", class: sheet.classes.ErrorAlertContainer, open: true },
77
+ h("sl-icon", { slot: "icon", name: "exclamation-octagon" }),
78
+ h("b", null, text.sendCodeErrorHeader),
79
+ text.sendCodeErrorDescription)),
80
+ states.initialLoading ? (renderLoadingSkeleton()) : (h("div", { class: sheet.classes.Wrapper },
68
81
  h(TextSpanView, { type: "p" }, text.verifyEmailHeaderText),
69
82
  h("sl-form", { "onSl-submit": callbacks.submitEmail },
70
83
  h("div", { class: sheet.classes.InputsContainer },
71
- h("sl-input", Object.assign({ exportparts: "label: input-label, base: input-base", label: text.emailLabel, value: states.email, type: "email", id: "email", name: "email", required: true }, (states.error
84
+ h("sl-input", Object.assign({ exportparts: "label: input-label, base: input-base", label: text.emailLabel, value: states.email, type: "email", id: "email", name: "email", disabled: !!states.email || states.loading }, (states.error
72
85
  ? {
73
86
  class: sheet.classes.ErrorInput,
74
- helpText: "Please enter a valid email",
87
+ helpText: text.emailValidationErrorText,
75
88
  }
76
89
  : {}))),
77
90
  h("sl-button", { submit: true, class: sheet.classes.ContinueButton, loading: states.loading, exportparts: "base: primarybutton-base", type: "primary" }, text.sendCodeText)))))));
@@ -3,8 +3,9 @@ import { Component, h, Prop } from "@stencil/core";
3
3
  import { useWidgetEmailVerification } from "./useEmailVerification";
4
4
  import { WidgetEmailVerificationView, } from "./sqm-email-verification-view";
5
5
  import { getProps } from "../../../utils/utils";
6
- import { isDemo } from "@saasquatch/component-boilerplate";
6
+ import { isDemo, useSetParent } from "@saasquatch/component-boilerplate";
7
7
  import deepmerge from "deepmerge";
8
+ import { SHOW_CODE_NAMESPACE } from "../keys";
8
9
  /**
9
10
  * @uiName Widget Verification Gate
10
11
  */
@@ -15,9 +16,13 @@ export class WidgetEmailVerification {
15
16
  */
16
17
  this.verifyEmailHeaderText = "Start by verifying your email. We’ll send you a code through our referral provider, impact.com.";
17
18
  /**
18
- * @uiName Verify email error text
19
+ * @uiName Send code to email alert header
19
20
  */
20
- this.errorText = "Failed to send an email. If this continues, contact Support with impact.com";
21
+ this.sendCodeErrorHeader = "There was an error sending your code.";
22
+ /**
23
+ * @uiName Send code to email alert description
24
+ */
25
+ this.sendCodeErrorDescription = "Please try again. If this problem continues, contact our program support team.";
21
26
  /**
22
27
  * @uiName Email input label
23
28
  */
@@ -26,6 +31,10 @@ export class WidgetEmailVerification {
26
31
  * @uiName Send code button text
27
32
  */
28
33
  this.sendCodeText = "Send code";
34
+ /**
35
+ * @uiName Send code button text
36
+ */
37
+ this.emailValidationErrorText = "Please enter a valid email";
29
38
  withHooks(this);
30
39
  }
31
40
  disconnectedCallback() { }
@@ -62,7 +71,28 @@ export class WidgetEmailVerification {
62
71
  "reflect": false,
63
72
  "defaultValue": "\"Start by verifying your email. We\u2019ll send you a code through our referral provider, impact.com.\""
64
73
  },
65
- "errorText": {
74
+ "sendCodeErrorHeader": {
75
+ "type": "string",
76
+ "mutable": false,
77
+ "complexType": {
78
+ "original": "string",
79
+ "resolved": "string",
80
+ "references": {}
81
+ },
82
+ "required": false,
83
+ "optional": false,
84
+ "docs": {
85
+ "tags": [{
86
+ "text": "Send code to email alert header",
87
+ "name": "uiName"
88
+ }],
89
+ "text": ""
90
+ },
91
+ "attribute": "send-code-error-header",
92
+ "reflect": false,
93
+ "defaultValue": "\"There was an error sending your code.\""
94
+ },
95
+ "sendCodeErrorDescription": {
66
96
  "type": "string",
67
97
  "mutable": false,
68
98
  "complexType": {
@@ -74,14 +104,14 @@ export class WidgetEmailVerification {
74
104
  "optional": false,
75
105
  "docs": {
76
106
  "tags": [{
77
- "text": "Verify email error text",
107
+ "text": "Send code to email alert description",
78
108
  "name": "uiName"
79
109
  }],
80
110
  "text": ""
81
111
  },
82
- "attribute": "error-text",
112
+ "attribute": "send-code-error-description",
83
113
  "reflect": false,
84
- "defaultValue": "\"Failed to send an email. If this continues, contact Support with impact.com\""
114
+ "defaultValue": "\"Please try again. If this problem continues, contact our program support team.\""
85
115
  },
86
116
  "emailLabel": {
87
117
  "type": "string",
@@ -125,12 +155,33 @@ export class WidgetEmailVerification {
125
155
  "reflect": false,
126
156
  "defaultValue": "\"Send code\""
127
157
  },
158
+ "emailValidationErrorText": {
159
+ "type": "string",
160
+ "mutable": false,
161
+ "complexType": {
162
+ "original": "string",
163
+ "resolved": "string",
164
+ "references": {}
165
+ },
166
+ "required": false,
167
+ "optional": false,
168
+ "docs": {
169
+ "tags": [{
170
+ "text": "Send code button text",
171
+ "name": "uiName"
172
+ }],
173
+ "text": ""
174
+ },
175
+ "attribute": "email-validation-error-text",
176
+ "reflect": false,
177
+ "defaultValue": "\"Please enter a valid email\""
178
+ },
128
179
  "demoData": {
129
180
  "type": "unknown",
130
181
  "mutable": false,
131
182
  "complexType": {
132
183
  "original": "DemoData<WidgetEmailVerificationViewProps>",
133
- "resolved": "{ states?: { error: string; loading: boolean; email: string; }; }",
184
+ "resolved": "{ states?: { error: boolean; initialLoading: boolean; loading: boolean; email: string; sendCodeError: boolean; }; }",
134
185
  "references": {
135
186
  "DemoData": {
136
187
  "location": "import",
@@ -158,14 +209,17 @@ export class WidgetEmailVerification {
158
209
  }; }
159
210
  }
160
211
  function useDemoWidgetEmailVerification(props) {
212
+ const setShowCode = useSetParent(SHOW_CODE_NAMESPACE);
161
213
  return deepmerge({
162
214
  states: {
163
- error: "",
215
+ error: true,
216
+ initialLoading: false,
164
217
  loading: false,
165
- email: "",
218
+ email: "test@example.com",
219
+ sendCodeError: true,
166
220
  },
167
221
  callbacks: {
168
- submitEmail: async () => { },
222
+ submitEmail: async () => setShowCode(true),
169
223
  },
170
224
  text: props.getTextProps(),
171
225
  }, props.demoData || {}, { arrayMerge: (_, a) => a });
@@ -1,24 +1,44 @@
1
- import { useMutation, useParent, useUserIdentity, } from "@saasquatch/component-boilerplate";
2
- import { useState } from "@saasquatch/universal-hooks";
1
+ import { useMutation, useParent, useQuery, useUserIdentity, } from "@saasquatch/component-boilerplate";
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
5
+ import { useVerificationEmail } from "../useVerificationEmail";
6
+ export const UpsertUserEmailMutation = gql `
7
+ mutation upsertUser($userInput: UserInput!) {
8
+ user(userInput: $userInput) {
9
+ id
10
+ accountId
11
+ email
9
12
  }
10
13
  }
11
14
  `;
12
- // TODO: Move to component-boilerplate
13
- export function useVerificationEmailMutation() {
15
+ export const UserLookupQuery = gql `
16
+ query user {
17
+ viewer {
18
+ ... on User {
19
+ id
20
+ accountId
21
+ email
22
+ impactConnection {
23
+ user {
24
+ id
25
+ email
26
+ }
27
+ }
28
+ }
29
+ }
30
+ }
31
+ `;
32
+ export function useUpsertUserEmail() {
14
33
  const user = useUserIdentity();
15
- const [request, { loading, data, errors }] = useMutation(VerificationEmailMutation);
16
- const sendVerificationEmailMutation = async () => {
34
+ const [request, { loading: loading, data, errors }] = useMutation(UpsertUserEmailMutation);
35
+ const upsertUserEmail = async (email) => {
17
36
  try {
18
37
  const result = await request({
19
38
  user: {
20
39
  id: user.id,
21
40
  accountId: user.accountId,
41
+ email,
22
42
  },
23
43
  });
24
44
  if (result instanceof Error || !result)
@@ -26,12 +46,12 @@ export function useVerificationEmailMutation() {
26
46
  return result;
27
47
  }
28
48
  catch (e) {
29
- console.error("Could not send verification email", e);
49
+ console.error("Could not set email on user", e);
30
50
  return undefined;
31
51
  }
32
52
  };
33
53
  return [
34
- sendVerificationEmailMutation,
54
+ upsertUserEmail,
35
55
  {
36
56
  loading,
37
57
  data,
@@ -42,19 +62,53 @@ export function useVerificationEmailMutation() {
42
62
  export function useWidgetEmailVerification(props) {
43
63
  const [_, setShowCode] = useParent(SHOW_CODE_NAMESPACE);
44
64
  const [email, setEmail] = useParent(VERIFICATION_EMAIL_NAMESPACE);
65
+ const [emailExists, setEmailExists] = useState(false);
45
66
  const [error, setError] = useState(false);
46
- const [sendVerificationEmailMutation, { loading, data, errors }] = useVerificationEmailMutation();
67
+ const [mutationError, setMutationError] = useState(false);
68
+ const { initialized, send: [sendEmail, { loading: sendLoading, errors }], } = useVerificationEmail();
69
+ const [upsertUserEmail] = useUpsertUserEmail();
70
+ const [loading, setLoading] = useState(true);
71
+ const { data, loading: initialLoading } = useQuery(UserLookupQuery, {});
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,}))$/;
73
+ useEffect(() => {
74
+ if (!(data === null || data === void 0 ? void 0 : data.viewer))
75
+ return;
76
+ setEmailExists(!!data.viewer.email);
77
+ }, [data]);
78
+ useEffect(() => {
79
+ if (initialized)
80
+ setLoading(false);
81
+ }, [initialized]);
47
82
  const submitEmail = async (e) => {
48
83
  e.preventDefault();
49
- const formData = e.detail.formData;
50
- const toAddress = formData.get("email").toString();
51
- const result = await sendVerificationEmailMutation();
52
- if (!result || !result.requestUserEmailVerification.success)
53
- setError(true);
84
+ if (!(data === null || data === void 0 ? void 0 : data.viewer))
85
+ return;
86
+ setLoading(true);
87
+ const toAddress = data.viewer.email;
88
+ if (!toAddress) {
89
+ // If no email on the user, set one
90
+ const formData = e.detail.formData;
91
+ const newEmail = formData.get("email").toString();
92
+ if (!emailRegex.test(newEmail)) {
93
+ setError(true);
94
+ return;
95
+ }
96
+ const result = await upsertUserEmail(newEmail);
97
+ if (!result || !result.user.email)
98
+ setError(true);
99
+ }
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)
105
+ setMutationError(true);
54
106
  else {
107
+ // This is used to let the code verification widget know an email was already sent
55
108
  setEmail(toAddress);
56
109
  setShowCode(true);
57
110
  }
111
+ setLoading(false);
58
112
  };
59
113
  return {
60
114
  callbacks: {
@@ -62,8 +116,10 @@ export function useWidgetEmailVerification(props) {
62
116
  },
63
117
  states: {
64
118
  loading,
65
- error: error && props.errorText,
66
- email,
119
+ initialLoading: initialLoading && !initialized,
120
+ error,
121
+ email: data === null || data === void 0 ? void 0 : data.viewer.email,
122
+ sendCodeError: mutationError,
67
123
  },
68
124
  text: props.getTextProps(),
69
125
  };