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

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 (159) 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 +92 -78
  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 +77 -21
  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/sqm-user-info-form-view.js +1 -6
  47. package/dist/collection/components/tax-and-cash/sqm-user-info-form/useUserInfoForm.js +16 -11
  48. package/dist/esm/{ShadowViewAddon-65c8679e.js → ShadowViewAddon-69b61037.js} +6 -3
  49. package/dist/esm/extractProps-ae1afbb3.js +19 -0
  50. package/dist/esm/{keys-a1496e39.js → keys-db1897ae.js} +1 -1
  51. package/dist/esm/loader.js +1 -1
  52. package/dist/esm/mint-components.js +1 -1
  53. package/dist/esm/sqm-banking-info-form_16.entry.js +92 -78
  54. package/dist/esm/sqm-big-stat_39.entry.js +127 -62
  55. package/dist/esm/sqm-code-verification.entry.js +69 -79
  56. package/dist/esm/sqm-email-verification.entry.js +159 -13
  57. package/dist/esm/{sqm-invoice-table-view-08c03ba7.js → sqm-invoice-table-view-d1cfdaf4.js} +79 -0
  58. package/dist/esm/sqm-stencilbook.entry.js +56 -14
  59. package/dist/esm/sqm-widget-verification-internal.entry.js +84 -14
  60. package/dist/esm/sqm-widget-verification.entry.js +104 -21
  61. package/dist/esm/usePayoutStatus-1a635054.js +67 -0
  62. package/dist/esm/useVerificationEmail-c32696ba.js +167 -0
  63. package/dist/esm-es5/ShadowViewAddon-69b61037.js +1 -0
  64. package/dist/esm-es5/extractProps-ae1afbb3.js +1 -0
  65. package/dist/esm-es5/{keys-a1496e39.js → keys-db1897ae.js} +1 -1
  66. package/dist/esm-es5/loader.js +1 -1
  67. package/dist/esm-es5/mint-components.js +1 -1
  68. package/dist/esm-es5/sqm-banking-info-form_16.entry.js +1 -1
  69. package/dist/esm-es5/sqm-big-stat_39.entry.js +1 -1
  70. package/dist/esm-es5/sqm-code-verification.entry.js +1 -1
  71. package/dist/esm-es5/sqm-email-verification.entry.js +1 -1
  72. package/dist/esm-es5/sqm-invoice-table-view-d1cfdaf4.js +1 -0
  73. package/dist/esm-es5/sqm-stencilbook.entry.js +1 -1
  74. package/dist/esm-es5/sqm-widget-verification-internal.entry.js +1 -1
  75. package/dist/esm-es5/sqm-widget-verification.entry.js +1 -1
  76. package/dist/esm-es5/usePayoutStatus-1a635054.js +1 -0
  77. package/dist/esm-es5/useVerificationEmail-c32696ba.js +1 -0
  78. package/dist/mint-components/mint-components.esm.js +1 -1
  79. package/dist/mint-components/p-0e45bc0e.system.entry.js +1 -0
  80. package/dist/mint-components/p-1712a9fd.entry.js +11 -0
  81. package/dist/mint-components/p-1e616d45.system.js +1 -0
  82. package/dist/mint-components/{p-721a89c6.entry.js → p-24092973.entry.js} +2 -2
  83. package/dist/mint-components/p-26468242.js +1 -0
  84. package/dist/mint-components/p-282a7d85.entry.js +195 -0
  85. package/dist/mint-components/p-331d060e.entry.js +223 -0
  86. package/dist/mint-components/p-39840341.js +1 -0
  87. package/dist/mint-components/p-4364001c.entry.js +12 -0
  88. package/dist/mint-components/p-4bd7a472.js +1 -0
  89. package/dist/mint-components/p-517224ef.js +19 -0
  90. package/dist/mint-components/p-5f766d09.entry.js +25 -0
  91. package/dist/mint-components/p-8300d8c8.system.js +1 -0
  92. package/dist/mint-components/p-8bddb468.system.entry.js +1 -0
  93. package/dist/mint-components/p-9596e97c.system.entry.js +1 -0
  94. package/dist/mint-components/p-974070c4.system.entry.js +1 -0
  95. package/dist/mint-components/{p-b651706a.js → p-9eae245f.js} +6 -3
  96. package/dist/mint-components/p-a8645c1b.system.js +1 -0
  97. package/dist/mint-components/p-aabab609.system.entry.js +1 -0
  98. package/dist/mint-components/p-b2a99637.system.js +1 -0
  99. package/dist/mint-components/{p-66a04cca.system.entry.js → p-b62faaa5.system.entry.js} +1 -1
  100. package/dist/mint-components/p-c510fb88.entry.js +1 -0
  101. package/dist/mint-components/p-ca809fdd.system.js +1 -1
  102. package/dist/mint-components/p-d7806f31.js +48 -0
  103. package/dist/mint-components/p-e01ac27c.system.js +1 -0
  104. package/dist/mint-components/p-e45a8501.system.entry.js +1 -0
  105. package/dist/mint-components/p-e990dc21.system.js +1 -0
  106. package/dist/types/components/sqm-payout-button-scroll/PayoutButtonScroll.stories.d.ts +0 -1
  107. package/dist/types/components/sqm-payout-button-scroll/sqm-payout-button-scroll.d.ts +7 -0
  108. package/dist/types/components/sqm-widget-verification/sqm-code-verification/WidgetCodeVerification.stories.d.ts +1 -0
  109. package/dist/types/components/sqm-widget-verification/sqm-code-verification/sqm-code-verification-view.d.ts +3 -3
  110. package/dist/types/components/sqm-widget-verification/sqm-code-verification/sqm-code-verification.d.ts +4 -10
  111. package/dist/types/components/sqm-widget-verification/sqm-code-verification/useCodeVerification.d.ts +2 -0
  112. package/dist/types/components/sqm-widget-verification/sqm-email-verification/WidgetEmailVerification.stories.d.ts +4 -1
  113. package/dist/types/components/sqm-widget-verification/sqm-email-verification/sqm-email-verification-view.d.ts +6 -1
  114. package/dist/types/components/sqm-widget-verification/sqm-email-verification/sqm-email-verification.d.ts +10 -2
  115. package/dist/types/components/sqm-widget-verification/sqm-email-verification/useEmailVerification.d.ts +3 -2
  116. package/dist/types/components/sqm-widget-verification/sqm-widget-verification-internal.d.ts +15 -0
  117. package/dist/types/components/sqm-widget-verification/sqm-widget-verification.d.ts +79 -0
  118. package/dist/types/components/sqm-widget-verification/useVerificationEmail.d.ts +14 -0
  119. package/dist/types/components/tax-and-cash/TaxForm.stories.d.ts +1 -0
  120. package/dist/types/components/tax-and-cash/sqm-banking-info-form/sqm-banking-info-form-view.d.ts +1 -0
  121. package/dist/types/components/tax-and-cash/sqm-payout-status-alert/PayoutStatusAlert.stories.d.ts +2 -0
  122. package/dist/types/components/tax-and-cash/sqm-payout-status-alert/sqm-payout-status-alert-view.d.ts +12 -0
  123. package/dist/types/components/tax-and-cash/sqm-payout-status-alert/sqm-payout-status-alert.d.ts +41 -0
  124. package/dist/types/components/tax-and-cash/sqm-payout-status-alert/usePayoutStatus.d.ts +12 -0
  125. package/dist/types/components/tax-and-cash/sqm-tax-and-cash/data.d.ts +6 -0
  126. package/dist/types/components/tax-and-cash/sqm-tax-and-cash/sqm-tax-and-cash.d.ts +2 -2
  127. package/dist/types/components/tax-and-cash/sqm-tax-and-cash-dashboard/sqm-tax-and-cash-dashboard-view.d.ts +10 -3
  128. package/dist/types/components/tax-and-cash/sqm-tax-and-cash-dashboard/sqm-tax-and-cash-dashboard.d.ts +19 -18
  129. package/dist/types/components.d.ts +366 -92
  130. package/docs/docs.docx +0 -0
  131. package/docs/raisins.json +1 -1
  132. package/grapesjs/grapesjs.js +1 -1
  133. package/package.json +1 -1
  134. package/dist/cjs/useEmailVerification-30a1c7f6.js +0 -75
  135. package/dist/collection/components/sqm-widget-verification/useWidgetVerification.js +0 -3
  136. package/dist/esm/useEmailVerification-7135732c.js +0 -72
  137. package/dist/esm-es5/ShadowViewAddon-65c8679e.js +0 -1
  138. package/dist/esm-es5/sqm-invoice-table-view-08c03ba7.js +0 -1
  139. package/dist/esm-es5/useEmailVerification-7135732c.js +0 -1
  140. package/dist/mint-components/p-117b4705.system.js +0 -1
  141. package/dist/mint-components/p-1bd0cda8.system.entry.js +0 -1
  142. package/dist/mint-components/p-1ee62d9f.system.entry.js +0 -1
  143. package/dist/mint-components/p-1f9a9b70.system.entry.js +0 -1
  144. package/dist/mint-components/p-23fdd44e.entry.js +0 -1
  145. package/dist/mint-components/p-36f7caec.system.entry.js +0 -1
  146. package/dist/mint-components/p-39397731.entry.js +0 -1
  147. package/dist/mint-components/p-39af4acd.entry.js +0 -240
  148. package/dist/mint-components/p-4c9b6fbe.system.js +0 -1
  149. package/dist/mint-components/p-65e2c043.system.js +0 -1
  150. package/dist/mint-components/p-663303b7.entry.js +0 -8
  151. package/dist/mint-components/p-6cae44d7.js +0 -1
  152. package/dist/mint-components/p-7f5c7bf7.system.entry.js +0 -1
  153. package/dist/mint-components/p-8a337864.js +0 -7
  154. package/dist/mint-components/p-a02afa72.system.js +0 -1
  155. package/dist/mint-components/p-a5a9aa07.entry.js +0 -189
  156. package/dist/mint-components/p-c763c0b2.js +0 -1
  157. package/dist/mint-components/p-e93e5740.entry.js +0 -1
  158. package/dist/mint-components/p-e9ca48fc.system.entry.js +0 -1
  159. package/dist/types/components/sqm-widget-verification/useWidgetVerification.d.ts +0 -1
@@ -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
+ upsertUser(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
- user: {
38
+ userInput: {
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
  };
@@ -1,27 +1,339 @@
1
- import { useParentState, useUserIdentity, } from "@saasquatch/component-boilerplate";
2
- import { withHooks } from "@saasquatch/stencil-hooks";
3
- import { Component, h } from "@stencil/core";
4
- import { SHOW_CODE_NAMESPACE, VERIFICATION_EMAIL_NAMESPACE } from "./keys";
1
+ import { isDemo, useLazyQuery, useParentState, useSetParent, useUserIdentity, } from "@saasquatch/component-boilerplate";
2
+ import { useState, withHooks } from "@saasquatch/stencil-hooks";
3
+ import { Component, h, Prop } from "@stencil/core";
4
+ import { SHOW_CODE_NAMESPACE, VERIFICATION_EMAIL_NAMESPACE, VERIFICATION_PARENT_NAMESPACE, } from "./keys";
5
+ import { getProps } from "../../utils/utils";
6
+ import { extractProps } from "../tax-and-cash/sqm-tax-and-cash/extractProps";
7
+ import { gql } from "graphql-request";
8
+ import { useEffect } from "@saasquatch/universal-hooks";
9
+ const USER_LOOKUP = gql `
10
+ query checkUserVerification {
11
+ viewer {
12
+ ... on User {
13
+ id
14
+ accountId
15
+ email
16
+ emailVerified
17
+ }
18
+ }
19
+ }
20
+ `;
21
+ function useWidgetVerificationInternal() {
22
+ const userIdentity = useUserIdentity();
23
+ const [showCode, setShowCode] = useParentState({
24
+ namespace: SHOW_CODE_NAMESPACE,
25
+ initialValue: false,
26
+ });
27
+ const [email, setEmail] = useParentState({
28
+ namespace: VERIFICATION_EMAIL_NAMESPACE,
29
+ initialValue: userIdentity === null || userIdentity === void 0 ? void 0 : userIdentity.email,
30
+ });
31
+ const setContext = useSetParent(VERIFICATION_PARENT_NAMESPACE);
32
+ const [loading, setLoading] = useState(true);
33
+ const [fetch] = useLazyQuery(USER_LOOKUP);
34
+ useEffect(() => {
35
+ const checkUser = async () => {
36
+ var _a;
37
+ try {
38
+ const res = await fetch({});
39
+ if (!res || res instanceof Error)
40
+ throw new Error();
41
+ if ((_a = res === null || res === void 0 ? void 0 : res.viewer) === null || _a === void 0 ? void 0 : _a.emailVerified)
42
+ setContext(true);
43
+ }
44
+ catch (e) {
45
+ console.error("Could not fetch user information:", e);
46
+ }
47
+ finally {
48
+ setLoading(false);
49
+ }
50
+ };
51
+ checkUser();
52
+ }, []);
53
+ const onVerification = () => {
54
+ setContext(true);
55
+ };
56
+ return { showCode, onVerification, loading };
57
+ }
5
58
  export class WidgetVerificationInternal {
6
59
  constructor() {
7
60
  withHooks(this);
8
61
  }
9
62
  disconnectedCallback() { }
63
+ getStepTextProps(prefix) {
64
+ const props = getProps(this);
65
+ return extractProps(props, prefix);
66
+ }
10
67
  render() {
11
- const userIdentity = useUserIdentity();
12
- const [showCode, setShowCode] = useParentState({
13
- namespace: SHOW_CODE_NAMESPACE,
14
- initialValue: false,
15
- });
16
- const [email, setEmail] = useParentState({
17
- namespace: VERIFICATION_EMAIL_NAMESPACE,
18
- initialValue: userIdentity === null || userIdentity === void 0 ? void 0 : userIdentity.email,
19
- });
68
+ const { showCode, onVerification, loading } = isDemo()
69
+ ? useDemoWidgetVerificationInternal()
70
+ : useWidgetVerificationInternal();
71
+ // TODO: Shoelace spinner is throwing errors
72
+ if (loading)
73
+ return h("div", null);
74
+ // if (loading) {
75
+ // return <sl-spinner style="font-size: 2rem;"></sl-spinner>;
76
+ // }
20
77
  if (showCode) {
21
- return h("sqm-code-verification", null);
78
+ return (h("sqm-code-verification", Object.assign({ onVerification: onVerification }, this.getStepTextProps("codeStep_"))));
22
79
  }
23
- return h("sqm-email-verification", null);
80
+ return (h("sqm-email-verification", Object.assign({}, this.getStepTextProps("emailStep_"))));
24
81
  }
25
82
  static get is() { return "sqm-widget-verification-internal"; }
26
83
  static get encapsulation() { return "shadow"; }
84
+ static get properties() { return {
85
+ "emailStep_verifyEmailHeaderText": {
86
+ "type": "string",
87
+ "mutable": false,
88
+ "complexType": {
89
+ "original": "string",
90
+ "resolved": "string",
91
+ "references": {}
92
+ },
93
+ "required": false,
94
+ "optional": false,
95
+ "docs": {
96
+ "tags": [],
97
+ "text": ""
98
+ },
99
+ "attribute": "email-step_verify-email-header-text",
100
+ "reflect": false
101
+ },
102
+ "emailStep_sendCodeErrorHeader": {
103
+ "type": "string",
104
+ "mutable": false,
105
+ "complexType": {
106
+ "original": "string",
107
+ "resolved": "string",
108
+ "references": {}
109
+ },
110
+ "required": false,
111
+ "optional": false,
112
+ "docs": {
113
+ "tags": [],
114
+ "text": ""
115
+ },
116
+ "attribute": "email-step_send-code-error-header",
117
+ "reflect": false
118
+ },
119
+ "emailStep_sendCodeErrorDescription": {
120
+ "type": "string",
121
+ "mutable": false,
122
+ "complexType": {
123
+ "original": "string",
124
+ "resolved": "string",
125
+ "references": {}
126
+ },
127
+ "required": false,
128
+ "optional": false,
129
+ "docs": {
130
+ "tags": [],
131
+ "text": ""
132
+ },
133
+ "attribute": "email-step_send-code-error-description",
134
+ "reflect": false
135
+ },
136
+ "emailStep_emailLabel": {
137
+ "type": "string",
138
+ "mutable": false,
139
+ "complexType": {
140
+ "original": "string",
141
+ "resolved": "string",
142
+ "references": {}
143
+ },
144
+ "required": false,
145
+ "optional": false,
146
+ "docs": {
147
+ "tags": [],
148
+ "text": ""
149
+ },
150
+ "attribute": "email-step_email-label",
151
+ "reflect": false
152
+ },
153
+ "emailStep_sendCodeText": {
154
+ "type": "string",
155
+ "mutable": false,
156
+ "complexType": {
157
+ "original": "string",
158
+ "resolved": "string",
159
+ "references": {}
160
+ },
161
+ "required": false,
162
+ "optional": false,
163
+ "docs": {
164
+ "tags": [],
165
+ "text": ""
166
+ },
167
+ "attribute": "email-step_send-code-text",
168
+ "reflect": false
169
+ },
170
+ "emailStep_emailValidationErrorText": {
171
+ "type": "string",
172
+ "mutable": false,
173
+ "complexType": {
174
+ "original": "string",
175
+ "resolved": "string",
176
+ "references": {}
177
+ },
178
+ "required": false,
179
+ "optional": false,
180
+ "docs": {
181
+ "tags": [],
182
+ "text": ""
183
+ },
184
+ "attribute": "email-step_email-validation-error-text",
185
+ "reflect": false
186
+ },
187
+ "codeStep_verifyCodeHeaderText": {
188
+ "type": "string",
189
+ "mutable": false,
190
+ "complexType": {
191
+ "original": "string",
192
+ "resolved": "string",
193
+ "references": {}
194
+ },
195
+ "required": false,
196
+ "optional": false,
197
+ "docs": {
198
+ "tags": [],
199
+ "text": ""
200
+ },
201
+ "attribute": "code-step_verify-code-header-text",
202
+ "reflect": false
203
+ },
204
+ "codeStep_reverifyCodeHeaderText": {
205
+ "type": "string",
206
+ "mutable": false,
207
+ "complexType": {
208
+ "original": "string",
209
+ "resolved": "string",
210
+ "references": {}
211
+ },
212
+ "required": false,
213
+ "optional": false,
214
+ "docs": {
215
+ "tags": [],
216
+ "text": ""
217
+ },
218
+ "attribute": "code-step_reverify-code-header-text",
219
+ "reflect": false
220
+ },
221
+ "codeStep_resendCodeText": {
222
+ "type": "string",
223
+ "mutable": false,
224
+ "complexType": {
225
+ "original": "string",
226
+ "resolved": "string",
227
+ "references": {}
228
+ },
229
+ "required": false,
230
+ "optional": false,
231
+ "docs": {
232
+ "tags": [],
233
+ "text": ""
234
+ },
235
+ "attribute": "code-step_resend-code-text",
236
+ "reflect": false
237
+ },
238
+ "codeStep_resendCodeLabel": {
239
+ "type": "string",
240
+ "mutable": false,
241
+ "complexType": {
242
+ "original": "string",
243
+ "resolved": "string",
244
+ "references": {}
245
+ },
246
+ "required": false,
247
+ "optional": false,
248
+ "docs": {
249
+ "tags": [],
250
+ "text": ""
251
+ },
252
+ "attribute": "code-step_resend-code-label",
253
+ "reflect": false
254
+ },
255
+ "codeStep_codeResentSuccessfullyText": {
256
+ "type": "string",
257
+ "mutable": false,
258
+ "complexType": {
259
+ "original": "string",
260
+ "resolved": "string",
261
+ "references": {}
262
+ },
263
+ "required": false,
264
+ "optional": false,
265
+ "docs": {
266
+ "tags": [],
267
+ "text": ""
268
+ },
269
+ "attribute": "code-step_code-resent-successfully-text",
270
+ "reflect": false
271
+ },
272
+ "codeStep_invalidCodeText": {
273
+ "type": "string",
274
+ "mutable": false,
275
+ "complexType": {
276
+ "original": "string",
277
+ "resolved": "string",
278
+ "references": {}
279
+ },
280
+ "required": false,
281
+ "optional": false,
282
+ "docs": {
283
+ "tags": [],
284
+ "text": ""
285
+ },
286
+ "attribute": "code-step_invalid-code-text",
287
+ "reflect": false
288
+ },
289
+ "codeStep_verifyText": {
290
+ "type": "string",
291
+ "mutable": false,
292
+ "complexType": {
293
+ "original": "string",
294
+ "resolved": "string",
295
+ "references": {}
296
+ },
297
+ "required": false,
298
+ "optional": false,
299
+ "docs": {
300
+ "tags": [],
301
+ "text": ""
302
+ },
303
+ "attribute": "code-step_verify-text",
304
+ "reflect": false
305
+ },
306
+ "codeStep_networkErrorMessage": {
307
+ "type": "string",
308
+ "mutable": false,
309
+ "complexType": {
310
+ "original": "string",
311
+ "resolved": "string",
312
+ "references": {}
313
+ },
314
+ "required": false,
315
+ "optional": false,
316
+ "docs": {
317
+ "tags": [],
318
+ "text": ""
319
+ },
320
+ "attribute": "code-step_network-error-message",
321
+ "reflect": false
322
+ }
323
+ }; }
324
+ }
325
+ function useDemoWidgetVerificationInternal() {
326
+ const [showCode, setShowCode] = useParentState({
327
+ namespace: SHOW_CODE_NAMESPACE,
328
+ initialValue: false,
329
+ });
330
+ const [email, setEmail] = useParentState({
331
+ namespace: VERIFICATION_EMAIL_NAMESPACE,
332
+ initialValue: undefined,
333
+ });
334
+ const setContext = useSetParent(VERIFICATION_PARENT_NAMESPACE);
335
+ const onVerification = () => {
336
+ setContext(true);
337
+ };
338
+ return { showCode, onVerification, loading: false };
27
339
  }