@saasquatch/mint-components 1.12.0-15 → 1.12.0-20

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 (96) 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 → sqm-banking-info-form_17.cjs.entry.js} +443 -91
  4. package/dist/cjs/sqm-big-stat_39.cjs.entry.js +2 -2
  5. package/dist/cjs/sqm-empty_4.cjs.entry.js +1 -1
  6. package/dist/cjs/{sqm-invoice-table-view-b0602970.js → sqm-invoice-table-view-4fcf021f.js} +1 -0
  7. package/dist/cjs/sqm-stencilbook.cjs.entry.js +43 -8
  8. package/dist/cjs/sqm-widget-verification-controller.cjs.entry.js +113 -0
  9. package/dist/cjs/sqm-widget-verification.cjs.entry.js +86 -108
  10. package/dist/collection/collection-manifest.json +1 -1
  11. package/dist/collection/components/sqm-payout-button-scroll/sqm-payout-button-scroll-view.js +2 -2
  12. package/dist/collection/components/sqm-text/sqm-text.js +1 -1
  13. package/dist/collection/components/sqm-widget-verification/sqm-email-verification/WidgetEmailVerification.stories.js +22 -6
  14. package/dist/collection/components/sqm-widget-verification/sqm-widget-verification-controller.js +120 -0
  15. package/dist/collection/components/sqm-widget-verification/sqm-widget-verification.js +95 -125
  16. package/dist/collection/components/tax-and-cash/BankingForm.stories.js +17 -0
  17. package/dist/collection/components/tax-and-cash/TaxForm.stories.js +1 -0
  18. package/dist/collection/components/tax-and-cash/sqm-banking-info-form/sqm-banking-info-form.js +71 -5
  19. package/dist/collection/components/tax-and-cash/sqm-banking-info-form/useBankingInfoForm.js +2 -1
  20. package/dist/esm/{keys-db1897ae.js → keys-406491dc.js} +1 -1
  21. package/dist/esm/loader.js +1 -1
  22. package/dist/esm/mint-components.js +1 -1
  23. package/dist/esm/{sqm-banking-info-form_16.entry.js → sqm-banking-info-form_17.entry.js} +445 -94
  24. package/dist/esm/sqm-big-stat_39.entry.js +2 -2
  25. package/dist/esm/sqm-email-verification.entry.js +1 -1
  26. package/dist/esm/sqm-empty_4.entry.js +1 -1
  27. package/dist/esm/{sqm-invoice-table-view-b1ac1bfc.js → sqm-invoice-table-view-b3127605.js} +1 -0
  28. package/dist/esm/sqm-stencilbook.entry.js +43 -8
  29. package/dist/esm/sqm-widget-verification-controller.entry.js +109 -0
  30. package/dist/esm/sqm-widget-verification.entry.js +90 -112
  31. package/dist/esm-es5/{keys-db1897ae.js → keys-406491dc.js} +1 -1
  32. package/dist/esm-es5/loader.js +1 -1
  33. package/dist/esm-es5/mint-components.js +1 -1
  34. package/dist/esm-es5/sqm-banking-info-form_17.entry.js +1 -0
  35. package/dist/esm-es5/sqm-big-stat_39.entry.js +1 -1
  36. package/dist/esm-es5/sqm-email-verification.entry.js +1 -1
  37. package/dist/esm-es5/sqm-empty_4.entry.js +1 -1
  38. package/dist/esm-es5/sqm-invoice-table-view-b3127605.js +1 -0
  39. package/dist/esm-es5/sqm-stencilbook.entry.js +1 -1
  40. package/dist/esm-es5/sqm-widget-verification-controller.entry.js +1 -0
  41. package/dist/esm-es5/sqm-widget-verification.entry.js +1 -1
  42. package/dist/mint-components/mint-components.esm.js +1 -1
  43. package/dist/mint-components/{p-e11b605d.entry.js → p-021ccc29.entry.js} +1 -1
  44. package/dist/mint-components/{p-158568e5.system.entry.js → p-0a94fe9f.system.entry.js} +1 -1
  45. package/dist/mint-components/p-156e37c2.system.entry.js +1 -0
  46. package/dist/mint-components/{p-c58250e6.system.entry.js → p-2c342de3.system.entry.js} +1 -1
  47. package/dist/mint-components/p-3007fb7d.system.entry.js +1 -0
  48. package/dist/mint-components/p-38c7775a.js +1 -0
  49. package/dist/mint-components/{p-a8e79cad.entry.js → p-478a3755.entry.js} +2 -2
  50. package/dist/mint-components/p-57dd28bd.system.js +1 -0
  51. package/dist/mint-components/{p-9ec008cb.system.entry.js → p-70af9ba2.system.entry.js} +1 -1
  52. package/dist/mint-components/p-97c92e75.entry.js +16 -0
  53. package/dist/mint-components/p-9bd417fd.entry.js +1 -0
  54. package/dist/mint-components/{p-a5c96f2a.entry.js → p-a954c299.entry.js} +21 -11
  55. package/dist/mint-components/p-c1fa5e04.system.js +1 -0
  56. package/dist/mint-components/p-ca809fdd.system.js +1 -1
  57. package/dist/mint-components/p-cb55d3c4.system.entry.js +1 -0
  58. package/dist/mint-components/{p-4671e644.entry.js → p-cd200c95.entry.js} +1 -1
  59. package/dist/mint-components/p-d4877a65.system.entry.js +1 -0
  60. package/dist/mint-components/p-f1184442.js +1 -0
  61. package/dist/mint-components/{p-fc17c2d2.entry.js → p-f196d71a.entry.js} +11 -11
  62. package/dist/types/components/sqm-widget-verification/sqm-email-verification/WidgetEmailVerification.stories.d.ts +1 -0
  63. package/dist/types/components/sqm-widget-verification/sqm-widget-verification-controller.d.ts +12 -0
  64. package/dist/types/components/sqm-widget-verification/sqm-widget-verification.d.ts +3 -4
  65. package/dist/types/components/tax-and-cash/BankingForm.stories.d.ts +1 -0
  66. package/dist/types/components/tax-and-cash/sqm-banking-info-form/sqm-banking-info-form-view.d.ts +3 -0
  67. package/dist/types/components/tax-and-cash/sqm-banking-info-form/sqm-banking-info-form.d.ts +9 -0
  68. package/dist/types/components/tax-and-cash/sqm-tax-and-cash/extractProps.d.ts +5 -1
  69. package/dist/types/components/tax-and-cash/sqm-tax-and-cash/sqm-tax-and-cash.d.ts +1 -1
  70. package/dist/types/components.d.ts +27 -37
  71. package/docs/docs.docx +0 -0
  72. package/docs/raisins.json +1 -1
  73. package/grapesjs/grapesjs.js +1 -1
  74. package/package.json +1 -1
  75. package/dist/cjs/sqm-code-verification.cjs.entry.js +0 -342
  76. package/dist/cjs/sqm-widget-verification-internal.cjs.entry.js +0 -109
  77. package/dist/collection/components/sqm-widget-verification/sqm-widget-verification-internal.js +0 -345
  78. package/dist/esm/sqm-code-verification.entry.js +0 -338
  79. package/dist/esm/sqm-widget-verification-internal.entry.js +0 -105
  80. package/dist/esm-es5/sqm-banking-info-form_16.entry.js +0 -1
  81. package/dist/esm-es5/sqm-code-verification.entry.js +0 -1
  82. package/dist/esm-es5/sqm-invoice-table-view-b1ac1bfc.js +0 -1
  83. package/dist/esm-es5/sqm-widget-verification-internal.entry.js +0 -1
  84. package/dist/mint-components/p-02892b2a.entry.js +0 -11
  85. package/dist/mint-components/p-03e1ac96.system.entry.js +0 -1
  86. package/dist/mint-components/p-2584baa5.entry.js +0 -16
  87. package/dist/mint-components/p-39840341.js +0 -1
  88. package/dist/mint-components/p-7789349d.system.js +0 -1
  89. package/dist/mint-components/p-8fa2809f.system.entry.js +0 -1
  90. package/dist/mint-components/p-9596e97c.system.entry.js +0 -1
  91. package/dist/mint-components/p-9e788a1a.js +0 -1
  92. package/dist/mint-components/p-b2a99637.system.js +0 -1
  93. package/dist/mint-components/p-b99108a6.system.entry.js +0 -1
  94. package/dist/mint-components/p-bfd92031.system.entry.js +0 -1
  95. package/dist/mint-components/p-c510fb88.entry.js +0 -1
  96. package/dist/types/components/sqm-widget-verification/sqm-widget-verification-internal.d.ts +0 -20
@@ -1,345 +0,0 @@
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
- managedIdentity {
18
- email
19
- emailVerified
20
- }
21
- }
22
- }
23
- }
24
- `;
25
- function useWidgetVerificationInternal() {
26
- const userIdentity = useUserIdentity();
27
- const [showCode, setShowCode] = useParentState({
28
- namespace: SHOW_CODE_NAMESPACE,
29
- initialValue: false,
30
- });
31
- const [email, setEmail] = useParentState({
32
- namespace: VERIFICATION_EMAIL_NAMESPACE,
33
- initialValue: userIdentity === null || userIdentity === void 0 ? void 0 : userIdentity.email,
34
- });
35
- const setContext = useSetParent(VERIFICATION_PARENT_NAMESPACE);
36
- const [loading, setLoading] = useState(true);
37
- const [fetch] = useLazyQuery(USER_LOOKUP);
38
- useEffect(() => {
39
- const checkUser = async () => {
40
- var _a, _b, _c;
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
- else if ((_c = (_b = res === null || res === void 0 ? void 0 : res.viewer) === null || _b === void 0 ? void 0 : _b.managedIdentity) === null || _c === void 0 ? void 0 : _c.emailVerified)
48
- setContext(true);
49
- }
50
- catch (e) {
51
- console.error("Could not fetch user information:", e);
52
- }
53
- finally {
54
- setLoading(false);
55
- }
56
- };
57
- checkUser();
58
- }, []);
59
- const onVerification = () => {
60
- setContext(true);
61
- };
62
- return { showCode, onVerification, loading };
63
- }
64
- export class WidgetVerificationInternal {
65
- constructor() {
66
- withHooks(this);
67
- }
68
- disconnectedCallback() { }
69
- getStepTextProps(prefix) {
70
- const props = getProps(this);
71
- return extractProps(props, prefix);
72
- }
73
- render() {
74
- const { showCode, onVerification, loading } = isDemo()
75
- ? useDemoWidgetVerificationInternal()
76
- : useWidgetVerificationInternal();
77
- // TODO: Shoelace spinner is throwing errors
78
- if (loading)
79
- return h("div", null);
80
- // if (loading) {
81
- // return <sl-spinner style="font-size: 2rem;"></sl-spinner>;
82
- // }
83
- if (showCode) {
84
- return (h("sqm-code-verification", Object.assign({ onVerification: onVerification }, this.getStepTextProps("codeStep_"))));
85
- }
86
- return (h("sqm-email-verification", Object.assign({}, this.getStepTextProps("emailStep_"))));
87
- }
88
- static get is() { return "sqm-widget-verification-internal"; }
89
- static get encapsulation() { return "shadow"; }
90
- static get properties() { return {
91
- "emailStep_verifyEmailHeaderText": {
92
- "type": "string",
93
- "mutable": false,
94
- "complexType": {
95
- "original": "string",
96
- "resolved": "string",
97
- "references": {}
98
- },
99
- "required": false,
100
- "optional": false,
101
- "docs": {
102
- "tags": [],
103
- "text": ""
104
- },
105
- "attribute": "email-step_verify-email-header-text",
106
- "reflect": false
107
- },
108
- "emailStep_sendCodeErrorHeader": {
109
- "type": "string",
110
- "mutable": false,
111
- "complexType": {
112
- "original": "string",
113
- "resolved": "string",
114
- "references": {}
115
- },
116
- "required": false,
117
- "optional": false,
118
- "docs": {
119
- "tags": [],
120
- "text": ""
121
- },
122
- "attribute": "email-step_send-code-error-header",
123
- "reflect": false
124
- },
125
- "emailStep_sendCodeErrorDescription": {
126
- "type": "string",
127
- "mutable": false,
128
- "complexType": {
129
- "original": "string",
130
- "resolved": "string",
131
- "references": {}
132
- },
133
- "required": false,
134
- "optional": false,
135
- "docs": {
136
- "tags": [],
137
- "text": ""
138
- },
139
- "attribute": "email-step_send-code-error-description",
140
- "reflect": false
141
- },
142
- "emailStep_emailLabel": {
143
- "type": "string",
144
- "mutable": false,
145
- "complexType": {
146
- "original": "string",
147
- "resolved": "string",
148
- "references": {}
149
- },
150
- "required": false,
151
- "optional": false,
152
- "docs": {
153
- "tags": [],
154
- "text": ""
155
- },
156
- "attribute": "email-step_email-label",
157
- "reflect": false
158
- },
159
- "emailStep_sendCodeText": {
160
- "type": "string",
161
- "mutable": false,
162
- "complexType": {
163
- "original": "string",
164
- "resolved": "string",
165
- "references": {}
166
- },
167
- "required": false,
168
- "optional": false,
169
- "docs": {
170
- "tags": [],
171
- "text": ""
172
- },
173
- "attribute": "email-step_send-code-text",
174
- "reflect": false
175
- },
176
- "emailStep_emailValidationErrorText": {
177
- "type": "string",
178
- "mutable": false,
179
- "complexType": {
180
- "original": "string",
181
- "resolved": "string",
182
- "references": {}
183
- },
184
- "required": false,
185
- "optional": false,
186
- "docs": {
187
- "tags": [],
188
- "text": ""
189
- },
190
- "attribute": "email-step_email-validation-error-text",
191
- "reflect": false
192
- },
193
- "codeStep_verifyCodeHeaderText": {
194
- "type": "string",
195
- "mutable": false,
196
- "complexType": {
197
- "original": "string",
198
- "resolved": "string",
199
- "references": {}
200
- },
201
- "required": false,
202
- "optional": false,
203
- "docs": {
204
- "tags": [],
205
- "text": ""
206
- },
207
- "attribute": "code-step_verify-code-header-text",
208
- "reflect": false
209
- },
210
- "codeStep_reverifyCodeHeaderText": {
211
- "type": "string",
212
- "mutable": false,
213
- "complexType": {
214
- "original": "string",
215
- "resolved": "string",
216
- "references": {}
217
- },
218
- "required": false,
219
- "optional": false,
220
- "docs": {
221
- "tags": [],
222
- "text": ""
223
- },
224
- "attribute": "code-step_reverify-code-header-text",
225
- "reflect": false
226
- },
227
- "codeStep_resendCodeText": {
228
- "type": "string",
229
- "mutable": false,
230
- "complexType": {
231
- "original": "string",
232
- "resolved": "string",
233
- "references": {}
234
- },
235
- "required": false,
236
- "optional": false,
237
- "docs": {
238
- "tags": [],
239
- "text": ""
240
- },
241
- "attribute": "code-step_resend-code-text",
242
- "reflect": false
243
- },
244
- "codeStep_resendCodeLabel": {
245
- "type": "string",
246
- "mutable": false,
247
- "complexType": {
248
- "original": "string",
249
- "resolved": "string",
250
- "references": {}
251
- },
252
- "required": false,
253
- "optional": false,
254
- "docs": {
255
- "tags": [],
256
- "text": ""
257
- },
258
- "attribute": "code-step_resend-code-label",
259
- "reflect": false
260
- },
261
- "codeStep_codeResentSuccessfullyText": {
262
- "type": "string",
263
- "mutable": false,
264
- "complexType": {
265
- "original": "string",
266
- "resolved": "string",
267
- "references": {}
268
- },
269
- "required": false,
270
- "optional": false,
271
- "docs": {
272
- "tags": [],
273
- "text": ""
274
- },
275
- "attribute": "code-step_code-resent-successfully-text",
276
- "reflect": false
277
- },
278
- "codeStep_invalidCodeText": {
279
- "type": "string",
280
- "mutable": false,
281
- "complexType": {
282
- "original": "string",
283
- "resolved": "string",
284
- "references": {}
285
- },
286
- "required": false,
287
- "optional": false,
288
- "docs": {
289
- "tags": [],
290
- "text": ""
291
- },
292
- "attribute": "code-step_invalid-code-text",
293
- "reflect": false
294
- },
295
- "codeStep_verifyText": {
296
- "type": "string",
297
- "mutable": false,
298
- "complexType": {
299
- "original": "string",
300
- "resolved": "string",
301
- "references": {}
302
- },
303
- "required": false,
304
- "optional": false,
305
- "docs": {
306
- "tags": [],
307
- "text": ""
308
- },
309
- "attribute": "code-step_verify-text",
310
- "reflect": false
311
- },
312
- "codeStep_networkErrorMessage": {
313
- "type": "string",
314
- "mutable": false,
315
- "complexType": {
316
- "original": "string",
317
- "resolved": "string",
318
- "references": {}
319
- },
320
- "required": false,
321
- "optional": false,
322
- "docs": {
323
- "tags": [],
324
- "text": ""
325
- },
326
- "attribute": "code-step_network-error-message",
327
- "reflect": false
328
- }
329
- }; }
330
- }
331
- function useDemoWidgetVerificationInternal() {
332
- const [showCode, setShowCode] = useParentState({
333
- namespace: SHOW_CODE_NAMESPACE,
334
- initialValue: false,
335
- });
336
- const [email, setEmail] = useParentState({
337
- namespace: VERIFICATION_EMAIL_NAMESPACE,
338
- initialValue: undefined,
339
- });
340
- const setContext = useSetParent(VERIFICATION_PARENT_NAMESPACE);
341
- const onVerification = () => {
342
- setContext(true);
343
- };
344
- return { showCode, onVerification, loading: false };
345
- }
@@ -1,338 +0,0 @@
1
- import { h, r as registerInstance } from './index-17b4da69.js';
2
- import { l, k as useState, f as useEffect, n as h$1 } from './stencil-hooks.module-ac12ca1c.js';
3
- import { i as intl } from './global-6306a9b8.js';
4
- import { d as dist, M as Mn, D as Dn, i as isDemo, S as Sn } from './index.module-6c840c4e.js';
5
- import { c as cjs } from './cjs-bdfb4486.js';
6
- import { E as ErrorStyles } from './mixins-f60a614c.js';
7
- import { c as createStyleSheet } from './JSS-67b5cff8.js';
8
- import { g as getProps } from './utils-334c1e34.js';
9
- import { T as TextSpanView } from './sqm-text-span-view-8d140661.js';
10
- import { a as VERIFICATION_EMAIL_NAMESPACE, S as SHOW_CODE_NAMESPACE, V as VERIFICATION_PARENT_NAMESPACE } from './keys-db1897ae.js';
11
- import { u as useVerificationEmail } from './useVerificationEmail-2a21d0e3.js';
12
-
13
- const style = {
14
- Wrapper: {
15
- display: "flex",
16
- flexDirection: "column",
17
- gap: "var(--sl-spacing-medium)",
18
- maxWidth: "550px",
19
- },
20
- HeaderContainer: {
21
- display: "flex",
22
- flexDirection: "column",
23
- },
24
- InputsContainer: {
25
- display: "flex",
26
- gap: "var(--sl-spacing-medium)",
27
- position: "relative",
28
- flexDirection: "column",
29
- },
30
- CodeInputContainer: {
31
- display: "flex",
32
- gap: "var(--sl-spacing-medium)",
33
- },
34
- CodeInput: {
35
- maxWidth: "40px",
36
- "&::part(input)": {
37
- margin: "0",
38
- padding: "0 var(--sl-input-spacing-small)",
39
- fontSize: "var(--sl-font-size-large)",
40
- },
41
- },
42
- CodeInputError: {
43
- ...ErrorStyles,
44
- maxWidth: "40px",
45
- "&::part(input)": {
46
- margin: "0",
47
- padding: "0 var(--sl-input-spacing-small)",
48
- fontSize: "var(--sl-font-size-large)",
49
- },
50
- },
51
- ErrorText: {
52
- color: "var(--sl-color-danger-500)",
53
- fontSize: "var(--sl-font-size-small)",
54
- margin: "0",
55
- },
56
- ContinueButton: {
57
- width: "100%",
58
- maxWidth: "100px",
59
- },
60
- FooterContainer: {
61
- display: "flex",
62
- flexDirection: "column",
63
- },
64
- SkeletonOne: {
65
- width: "50%",
66
- height: "16px",
67
- },
68
- SkeletonTwo: {
69
- width: "30%",
70
- height: "34px",
71
- },
72
- SkeletonThree: {
73
- width: "15%",
74
- height: "24px",
75
- },
76
- };
77
- const vanillaStyle = `
78
- :host {
79
- display: block;
80
- }
81
- :host([hidden]): {
82
- display: none;
83
- }
84
-
85
-
86
- `;
87
- const sheet = createStyleSheet(style);
88
- const styleString = sheet.toString();
89
- function WidgetCodeVerificationView(props) {
90
- const { states, refs, callbacks, text } = props;
91
- const resendCodeText = intl.formatMessage({
92
- id: "resendCodeText",
93
- defaultMessage: text.resendCodeText,
94
- }, {
95
- resendCodeLink: (h("a", { href: "", style: { textDecoration: "none" }, onClick: (e) => {
96
- e.preventDefault();
97
- callbacks.resendEmail();
98
- } }, text.resendCodeLabel)),
99
- });
100
- const codeResentSuccessfully = intl.formatMessage({
101
- id: "codeResentSuccessfully",
102
- defaultMessage: text.codeResentSuccessfullyText,
103
- }, {
104
- email: states.email,
105
- });
106
- const inputClass = states.verifyFailed
107
- ? sheet.classes.CodeInputError
108
- : sheet.classes.CodeInput;
109
- return (h("div", { part: "sqm-base" },
110
- h("style", { type: "text/css" },
111
- vanillaStyle,
112
- styleString),
113
- h("div", { class: sheet.classes.Wrapper },
114
- h("div", { class: sheet.classes.HeaderContainer },
115
- h(TextSpanView, { type: "p" }, intl.formatMessage({
116
- id: `emailHeaderText`,
117
- defaultMessage: states.verifyFailed
118
- ? text.reverifyCodeHeaderText
119
- : text.verifyCodeHeaderText,
120
- }, { email: states.email }))),
121
- states.emailResent && (h("sqm-form-message", { type: "success", exportparts: "successalert-icon" },
122
- h("b", null, codeResentSuccessfully))),
123
- h("div", { class: sheet.classes.InputsContainer },
124
- h("div", { ref: refs.codeWrapperRef, class: sheet.classes.CodeInputContainer },
125
- h("sl-input", { class: inputClass, name: "code" }),
126
- h("sl-input", { class: inputClass, name: "code" }),
127
- h("sl-input", { class: inputClass, name: "code" }),
128
- h("sl-input", { class: inputClass, name: "code" }),
129
- h("sl-input", { class: inputClass, name: "code" }),
130
- h("sl-input", { class: inputClass, name: "code" })),
131
- states.verifyFailed && (h("p", { class: sheet.classes.ErrorText }, text.invalidCodeText)),
132
- 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)),
133
- h("div", { class: sheet.classes.FooterContainer },
134
- h(TextSpanView, { type: "p" }, resendCodeText)))));
135
- }
136
-
137
- const VerifyEmailWithCodeMutation = dist.gql `
138
- mutation submitImpactPublisherEmail2FACode(
139
- $user: UserIdInput!
140
- $code: String!
141
- ) {
142
- submitImpactPublisherEmail2FACode(user: $user, code: $code) {
143
- verifiedEmail
144
- accessKey
145
- }
146
- }
147
- `;
148
- function useWidgetCodeVerification(props) {
149
- const host = l();
150
- const [_, setShowCode] = Mn(SHOW_CODE_NAMESPACE);
151
- const email = Dn(VERIFICATION_EMAIL_NAMESPACE);
152
- const [emailSent, setEmailSent] = useState(false);
153
- const [emailResent, setEmailResent] = useState(false);
154
- const [codeRef, setCodeRef] = useState(null);
155
- const [validationError, setValidationError] = useState(false);
156
- const [emailError, setEmailError] = useState(false);
157
- const { initialized, verificationEmail, send: [sendEmail, { loading: sendLoading, errors: sendErrors }], verify: [verifyEmail, { loading: verifyLoading, errors: verifyErrors }], } = useVerificationEmail();
158
- useEffect(() => {
159
- if (!codeRef)
160
- return;
161
- const slInputs = codeRef.querySelectorAll("sl-input");
162
- const codeElements = Array.from(slInputs).map((node) => node.shadowRoot.querySelector(`input[name="code"]`));
163
- codeElements.forEach((element, idx) => {
164
- element.addEventListener("focus", (e) => {
165
- e.target.select();
166
- });
167
- element.addEventListener("keydown", (e) => {
168
- if (e.key === "Backspace" && e.target.value === "") {
169
- codeElements[Math.max(0, idx - 1)].focus();
170
- }
171
- });
172
- element.addEventListener("input", (e) => {
173
- const input = e.data;
174
- if (!input)
175
- return;
176
- if (idx === codeElements.length - 1) {
177
- e.target.value = input.slice(0, 1);
178
- return;
179
- }
180
- if (input.length > 1) {
181
- const rest = input.slice(1);
182
- e.target.value = input.slice(0, 1);
183
- codeElements[idx + 1].dispatchEvent(new InputEvent("input", {
184
- inputType: "insertFromPaste",
185
- data: rest,
186
- }));
187
- }
188
- codeElements[idx + 1].focus();
189
- });
190
- });
191
- }, [codeRef]);
192
- const reset = () => {
193
- setShowCode(false);
194
- setValidationError(false);
195
- };
196
- const resendEmail = async () => {
197
- // UI should only allow this to be called if initialized, but checking just in case
198
- if (!initialized)
199
- return;
200
- const result = await sendEmail();
201
- if (!result) {
202
- setEmailError(true);
203
- return;
204
- }
205
- if (emailSent)
206
- setEmailResent(true);
207
- setEmailSent(true);
208
- };
209
- const submitCode = async () => {
210
- const slInputs = codeRef.querySelectorAll("sl-input");
211
- const codeElements = Array.from(slInputs).map((node) => node.shadowRoot.querySelector(`input[name="code"]`));
212
- if (codeElements.find((el) => !el.value)) {
213
- setValidationError(true);
214
- return;
215
- }
216
- let code = "";
217
- codeElements.forEach((element) => {
218
- code = `${code}${element.value}`;
219
- });
220
- // UI should only allow this to be called if initialized, but checking just in case
221
- if (!initialized)
222
- return;
223
- setValidationError(false);
224
- const res = await verifyEmail(code);
225
- if (res === null || res === void 0 ? void 0 : res.success) {
226
- props.onVerification(res.accessKey);
227
- reset();
228
- }
229
- else {
230
- setValidationError(true);
231
- }
232
- };
233
- useEffect(() => {
234
- // Wait for mutations to be determined from user lookup
235
- if (!initialized)
236
- return;
237
- // email should already exist if user has completed email-verification
238
- if (!email)
239
- resendEmail();
240
- else
241
- setEmailSent(true);
242
- }, [initialized]);
243
- return {
244
- refs: {
245
- codeWrapperRef: setCodeRef,
246
- },
247
- states: {
248
- email: verificationEmail,
249
- emailResent,
250
- resendError: sendErrors || verifyErrors,
251
- initialiseLoading: !initialized,
252
- loading: sendLoading || verifyLoading,
253
- verifyFailed: !!validationError,
254
- },
255
- callbacks: {
256
- resendEmail,
257
- submitCode,
258
- },
259
- text: props.getTextProps(),
260
- };
261
- }
262
-
263
- const WidgetCodeVerification = class {
264
- constructor(hostRef) {
265
- registerInstance(this, hostRef);
266
- /**
267
- * @uiName Verify code widget header text
268
- */
269
- this.verifyCodeHeaderText = "Enter the code sent to {email} from our referral provider, impact.com.";
270
- /**
271
- * @uiName Reverify code widget header text
272
- */
273
- this.reverifyCodeHeaderText = "Enter the code sent to {email} from our referral provider, impact.com.";
274
- /**
275
- * Text displayed under verify button
276
- * @uiName Resend code text
277
- */
278
- this.resendCodeText = "Didn't receive your code? {resendCodeLink}";
279
- /**
280
- * The link that appears in the resend code link
281
- * @uiName Resend code label
282
- */
283
- this.resendCodeLabel = "Resend code";
284
- /**
285
- * Link text displayed under verify button
286
- * @uiName Resend code text
287
- */
288
- this.codeResentSuccessfullyText = "Another code has been sent to {email}";
289
- /**
290
- * Error text displayed under verification input
291
- * @uiName Invalid code text
292
- */
293
- this.invalidCodeText = "Please check your code and try again. If you’re still having trouble, try resending your code.";
294
- /**
295
- * @uiName Verify code button text
296
- */
297
- this.verifyText = "Verify";
298
- /**
299
- * Displayed when the email verification fails due to a network error. The participant can try refreshing the page.
300
- * @uiName Network error message
301
- */
302
- this.networkErrorMessage = "An error occurred while verifying your email. Please refresh the page and try again.";
303
- h$1(this);
304
- }
305
- disconnectedCallback() { }
306
- getTextProps() {
307
- return getProps(this);
308
- }
309
- render() {
310
- const props = isDemo()
311
- ? useDemoWidgetCodeVerification(this)
312
- : useWidgetCodeVerification(this);
313
- return h(WidgetCodeVerificationView, Object.assign({}, props));
314
- }
315
- };
316
- function useDemoWidgetCodeVerification(props) {
317
- const [emailResent, setEmailResent] = useState(false);
318
- const setVerifiedContext = Sn(VERIFICATION_PARENT_NAMESPACE);
319
- return cjs({
320
- states: {
321
- loading: false,
322
- email: "test@example.com",
323
- emailResent,
324
- resendError: true,
325
- verifyFailed: true,
326
- },
327
- refs: {
328
- codeWrapperRef: () => { },
329
- },
330
- callbacks: {
331
- resendEmail: async () => setEmailResent(true),
332
- submitCode: async () => setVerifiedContext(true),
333
- },
334
- text: props.getTextProps(),
335
- }, props.demoData || {}, { arrayMerge: (_, a) => a });
336
- }
337
-
338
- export { WidgetCodeVerification as sqm_code_verification };