@saasquatch/mint-components 2.3.0-11 → 2.3.0-13

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 (85) hide show
  1. package/dist/cjs/{usePortalRegistrationForm-23ee2d62.js → AsYouType-d15caac8.js} +265 -223
  2. package/dist/cjs/sqm-banking-info-form_10.cjs.entry.js +46 -27
  3. package/dist/cjs/sqm-big-stat_47.cjs.entry.js +17 -13
  4. package/dist/cjs/sqm-portal-forgot-password_6.cjs.entry.js +3 -2
  5. package/dist/cjs/sqm-stencilbook.cjs.entry.js +59 -2
  6. package/dist/cjs/{sqm-user-info-form-view-8f7186b8.js → sqm-user-info-form-view-60e09262.js} +1004 -8
  7. package/dist/cjs/subregions-3542b0b8.js +1068 -0
  8. package/dist/cjs/{useIndirectTaxForm-112914a0.js → useIndirectTaxForm-c439eb81.js} +6 -2
  9. package/dist/cjs/usePortalRegistrationForm-8a3a14ac.js +215 -0
  10. package/dist/collection/components/tax-and-cash/TaxForm.stories.js +3 -0
  11. package/dist/collection/components/tax-and-cash/phoneExtensions.js +12 -0
  12. package/dist/collection/components/tax-and-cash/sqm-indirect-tax-form/sqm-indirect-tax-form-view.js +8 -0
  13. package/dist/collection/components/tax-and-cash/sqm-indirect-tax-form/sqm-indirect-tax-form.js +2 -1
  14. package/dist/collection/components/tax-and-cash/sqm-indirect-tax-form/useIndirectTaxForm.js +5 -1
  15. package/dist/collection/components/tax-and-cash/sqm-tax-and-cash/useTaxAndCash.js +12 -9
  16. package/dist/collection/components/tax-and-cash/sqm-user-info-form/UserInfoFormView.stories.js +52 -0
  17. package/dist/collection/components/tax-and-cash/sqm-user-info-form/sqm-user-info-form-view.js +18 -5
  18. package/dist/collection/components/tax-and-cash/sqm-user-info-form/sqm-user-info-form.js +3 -1
  19. package/dist/collection/components/tax-and-cash/sqm-user-info-form/useUserInfoForm.js +31 -27
  20. package/dist/collection/components/tax-and-cash/utils.js +30 -27
  21. package/dist/esm/{usePortalRegistrationForm-3a1f36a2.js → AsYouType-2d56519e.js} +248 -223
  22. package/dist/esm/sqm-banking-info-form_10.entry.js +46 -27
  23. package/dist/esm/sqm-big-stat_47.entry.js +16 -12
  24. package/dist/esm/sqm-portal-forgot-password_6.entry.js +2 -1
  25. package/dist/esm/sqm-stencilbook.entry.js +59 -2
  26. package/dist/esm/{sqm-user-info-form-view-599a6922.js → sqm-user-info-form-view-647a2bd5.js} +1002 -6
  27. package/dist/esm/subregions-7c5112e8.js +1055 -0
  28. package/dist/esm/{useIndirectTaxForm-a6ac7e7e.js → useIndirectTaxForm-38cd984e.js} +6 -2
  29. package/dist/esm/usePortalRegistrationForm-78fdfd93.js +213 -0
  30. package/dist/esm-es5/AsYouType-2d56519e.js +1 -0
  31. package/dist/esm-es5/sqm-banking-info-form_10.entry.js +1 -1
  32. package/dist/esm-es5/sqm-big-stat_47.entry.js +1 -1
  33. package/dist/esm-es5/sqm-portal-forgot-password_6.entry.js +1 -1
  34. package/dist/esm-es5/sqm-stencilbook.entry.js +1 -1
  35. package/dist/esm-es5/sqm-user-info-form-view-647a2bd5.js +1 -0
  36. package/dist/esm-es5/subregions-7c5112e8.js +1 -0
  37. package/dist/esm-es5/{useIndirectTaxForm-a6ac7e7e.js → useIndirectTaxForm-38cd984e.js} +2 -2
  38. package/dist/esm-es5/usePortalRegistrationForm-78fdfd93.js +1 -0
  39. package/dist/mint-components/mint-components.esm.js +1 -1
  40. package/dist/mint-components/p-1f387c7b.system.js +1 -1
  41. package/dist/mint-components/p-34179541.system.js +1 -0
  42. package/dist/mint-components/p-4065ae93.entry.js +9 -0
  43. package/dist/mint-components/p-5c3bff99.entry.js +1 -0
  44. package/dist/mint-components/p-6fd8981d.system.entry.js +1 -0
  45. package/dist/mint-components/p-769166a5.system.js +1 -0
  46. package/dist/mint-components/p-7c72eeb5.js +1 -0
  47. package/dist/mint-components/p-8d30945a.js +1 -0
  48. package/dist/mint-components/p-8dcd72fe.system.entry.js +1 -0
  49. package/dist/mint-components/p-a08157c4.js +1 -0
  50. package/dist/mint-components/p-a779e577.js +13 -0
  51. package/dist/mint-components/{p-2d4132fb.js → p-aa2c6585.js} +7 -5
  52. package/dist/mint-components/{p-6ef373ed.system.js → p-aab8a207.system.js} +2 -2
  53. package/dist/mint-components/p-af8b8c06.system.entry.js +1 -0
  54. package/dist/mint-components/{p-86231add.entry.js → p-b3f25c0e.entry.js} +8 -8
  55. package/dist/mint-components/p-c31966e3.system.entry.js +1 -0
  56. package/dist/mint-components/p-d463fa82.system.js +1 -0
  57. package/dist/mint-components/{p-339ce676.entry.js → p-dd5c1db9.entry.js} +11 -11
  58. package/dist/mint-components/p-ee91aeac.system.js +1 -0
  59. package/dist/types/components/tax-and-cash/phoneExtensions.d.ts +12 -0
  60. package/dist/types/components/tax-and-cash/sqm-indirect-tax-form/sqm-indirect-tax-form-view.d.ts +1 -0
  61. package/dist/types/components/tax-and-cash/sqm-indirect-tax-form/useIndirectTaxForm.d.ts +1 -0
  62. package/dist/types/components/tax-and-cash/sqm-user-info-form/UserInfoFormView.stories.d.ts +1 -0
  63. package/dist/types/components/tax-and-cash/sqm-user-info-form/sqm-user-info-form-view.d.ts +2 -0
  64. package/dist/types/components/tax-and-cash/sqm-user-info-form/useUserInfoForm.d.ts +2 -0
  65. package/dist/types/components/tax-and-cash/utils.d.ts +8 -2
  66. package/docs/docs.docx +0 -0
  67. package/grapesjs/grapesjs.js +1 -1
  68. package/package.json +1 -1
  69. package/dist/cjs/subregions-984e30d7.js +0 -1505
  70. package/dist/esm/subregions-7c9778d0.js +0 -1492
  71. package/dist/esm-es5/sqm-user-info-form-view-599a6922.js +0 -1
  72. package/dist/esm-es5/subregions-7c9778d0.js +0 -1
  73. package/dist/esm-es5/usePortalRegistrationForm-3a1f36a2.js +0 -1
  74. package/dist/mint-components/p-26a4ebfd.js +0 -1
  75. package/dist/mint-components/p-335a5736.entry.js +0 -1
  76. package/dist/mint-components/p-3a41b39c.js +0 -13
  77. package/dist/mint-components/p-40894343.entry.js +0 -9
  78. package/dist/mint-components/p-5fdf0286.system.js +0 -1
  79. package/dist/mint-components/p-7f29622d.js +0 -1
  80. package/dist/mint-components/p-81270b9f.system.js +0 -1
  81. package/dist/mint-components/p-b62d8b95.system.entry.js +0 -1
  82. package/dist/mint-components/p-bd03efe0.system.js +0 -1
  83. package/dist/mint-components/p-c9d2ccfc.system.entry.js +0 -1
  84. package/dist/mint-components/p-db6bf7cf.system.entry.js +0 -1
  85. package/dist/mint-components/p-f0ef09a0.system.entry.js +0 -1
@@ -3,7 +3,7 @@ import { useEffect, useMemo, useRef, useState, } from "@saasquatch/universal-hoo
3
3
  import jsonpointer from "jsonpointer";
4
4
  import { CURRENCIES_NAMESPACE, SORTED_COUNTRIES_NAMESPACE, TAX_CONTEXT_NAMESPACE, TAX_FORM_CONTEXT_NAMESPACE, USER_FORM_CONTEXT_NAMESPACE, USER_QUERY_NAMESPACE, } from "../data";
5
5
  import { ADDRESS_REGIONS } from "../subregions";
6
- import { objectIsFull, validTaxDocument } from "../utils";
6
+ import { objectIsFull, toDomesticNumber, validTaxDocument } from "../utils";
7
7
  import { TAX_FORM_UPDATED_EVENT_KEY } from "../eventKeys";
8
8
  import { CONNECT_PARTNER, COMPLETE_PARTNER, } from "../sqm-indirect-tax-form/useIndirectTaxForm";
9
9
  import { gql } from "graphql-request";
@@ -16,7 +16,7 @@ const GET_INDIRECT_TAX_COUNTRY_CODE = gql `
16
16
  }
17
17
  `;
18
18
  export function useUserInfoForm(props) {
19
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
19
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
20
20
  const currencyRef = useRef(undefined);
21
21
  const phoneCountryRef = useRef(undefined);
22
22
  const formRef = useRef(null);
@@ -136,7 +136,7 @@ export function useUserInfoForm(props) {
136
136
  }
137
137
  }, [currencySearch, currencies]);
138
138
  async function connectPartner(formData) {
139
- var _a, _b, _c, _d;
139
+ var _a, _b, _c, _d, _e, _f;
140
140
  const vars = {
141
141
  user: {
142
142
  id: user.id,
@@ -150,39 +150,34 @@ export function useUserInfoForm(props) {
150
150
  city: formData.city,
151
151
  state: formData.state,
152
152
  postalCode: formData.postalCode,
153
- phoneNumber: formData.phoneNumber,
153
+ phoneNumber: toDomesticNumber(formData.phoneNumberCountryCode, formData.phoneNumber),
154
154
  phoneNumberCountryCode: formData.phoneNumberCountryCode,
155
155
  };
156
- // If the partner has already been started call completeImpactPartner to
157
- // update the remaining details. Otherwise create a new connection.
156
+ // if user went through early partner creation, connectionStatus === "STARTED"
157
+ // otherwise trigger legacy partner creation
158
158
  const userData = data === null || data === void 0 ? void 0 : data.user;
159
159
  let result = null;
160
160
  let connectionResult;
161
- result = await completeImpactPartner({
162
- vars,
163
- });
164
- connectionResult = (_a = result) === null || _a === void 0 ? void 0 : _a.completeImpactConnection;
165
- // if (userData?.impactConnection?.connectionStatus === "STARTED") {
166
- // result = await completeImpactPartner({
167
- // vars,
168
- // });
169
- // connectionResult = (result as CompletePartnerResult)
170
- // ?.completeImpactConnection;
171
- // } else {
172
- // result = await connectImpactPartner({
173
- // vars,
174
- // });
175
- // connectionResult = (result as ConnectPartnerResult)
176
- // ?.createImpactConnection;
177
- // }
178
- if (!result || ((_b = result) === null || _b === void 0 ? void 0 : _b.message))
161
+ if (((_a = userData === null || userData === void 0 ? void 0 : userData.impactConnection) === null || _a === void 0 ? void 0 : _a.connectionStatus) === "STARTED") {
162
+ result = await completeImpactPartner({
163
+ vars,
164
+ });
165
+ connectionResult = (_b = result) === null || _b === void 0 ? void 0 : _b.completeImpactConnection;
166
+ }
167
+ else {
168
+ result = await connectImpactPartner({
169
+ vars,
170
+ });
171
+ connectionResult = (_c = result) === null || _c === void 0 ? void 0 : _c.createImpactConnection;
172
+ }
173
+ if (!result || ((_d = result) === null || _d === void 0 ? void 0 : _d.message))
179
174
  throw new Error();
180
175
  if (!(connectionResult === null || connectionResult === void 0 ? void 0 : connectionResult.success)) {
181
176
  console.error("Failed to create Impact connection: ", connectionResult === null || connectionResult === void 0 ? void 0 : connectionResult.validationErrors);
182
177
  throw new Error();
183
178
  }
184
179
  await refetch();
185
- const resultPublisher = (_d = (_c = connectionResult === null || connectionResult === void 0 ? void 0 : connectionResult.user) === null || _c === void 0 ? void 0 : _c.impactConnection) === null || _d === void 0 ? void 0 : _d.publisher;
180
+ const resultPublisher = (_f = (_e = connectionResult === null || connectionResult === void 0 ? void 0 : connectionResult.user) === null || _e === void 0 ? void 0 : _e.impactConnection) === null || _f === void 0 ? void 0 : _f.publisher;
186
181
  const hasValidCurrentDocument = validTaxDocument(resultPublisher === null || resultPublisher === void 0 ? void 0 : resultPublisher.requiredTaxDocumentType) && (resultPublisher === null || resultPublisher === void 0 ? void 0 : resultPublisher.currentTaxDocument);
187
182
  // Fire form change event
188
183
  window.dispatchEvent(new Event(TAX_FORM_UPDATED_EVENT_KEY));
@@ -220,12 +215,13 @@ export function useUserInfoForm(props) {
220
215
  return;
221
216
  }
222
217
  const { allowBankingCollection, ...userData } = formData;
218
+ const normalizedPhoneNumber = toDomesticNumber(userData.phoneNumberCountryCode, userData.phoneNumber);
223
219
  setUserFormContext({
224
220
  ...userFormContext,
225
221
  firstName: userData.firstName,
226
222
  lastName: userData.lastName,
227
223
  phoneNumberCountryCode: userData.phoneNumberCountryCode,
228
- phoneNumber: userData.phoneNumber,
224
+ phoneNumber: normalizedPhoneNumber,
229
225
  countryCode: userData.countryCode,
230
226
  address: userData.address,
231
227
  city: userData.city,
@@ -236,7 +232,10 @@ export function useUserInfoForm(props) {
236
232
  const skipNextStep = getSkipNextStep(userData);
237
233
  if (skipNextStep) {
238
234
  try {
239
- const { resultPublisher, hasValidCurrentDocument } = await connectPartner(formData);
235
+ const { resultPublisher, hasValidCurrentDocument } = await connectPartner({
236
+ ...formData,
237
+ phoneNumber: normalizedPhoneNumber,
238
+ });
240
239
  if ((resultPublisher === null || resultPublisher === void 0 ? void 0 : resultPublisher.requiredTaxDocumentType) &&
241
240
  !hasValidCurrentDocument) {
242
241
  // Go to docusign form
@@ -312,6 +311,11 @@ export function useUserInfoForm(props) {
312
311
  loading: loading || connectLoading || completeLoading,
313
312
  isPartner: !!((_g = (_f = data === null || data === void 0 ? void 0 : data.user) === null || _f === void 0 ? void 0 : _f.impactConnection) === null || _g === void 0 ? void 0 : _g.publisher),
314
313
  isUser: !!((_j = (_h = data === null || data === void 0 ? void 0 : data.user) === null || _h === void 0 ? void 0 : _h.impactConnection) === null || _j === void 0 ? void 0 : _j.user),
314
+ // Show banner when pre-existing partner is created with legacy mutation createImpactConnection
315
+ isUserLegacy: !!((_l = (_k = data === null || data === void 0 ? void 0 : data.user) === null || _k === void 0 ? void 0 : _k.impactConnection) === null || _l === void 0 ? void 0 : _l.user) &&
316
+ ((_o = (_m = data === null || data === void 0 ? void 0 : data.user) === null || _m === void 0 ? void 0 : _m.impactConnection) === null || _o === void 0 ? void 0 : _o.connectionStatus) !== "STARTED",
317
+ isPartnerLegacy: !!((_q = (_p = data === null || data === void 0 ? void 0 : data.user) === null || _p === void 0 ? void 0 : _p.impactConnection) === null || _q === void 0 ? void 0 : _q.publisher) &&
318
+ ((_s = (_r = data === null || data === void 0 ? void 0 : data.user) === null || _r === void 0 ? void 0 : _r.impactConnection) === null || _s === void 0 ? void 0 : _s.connectionStatus) !== "STARTED",
315
319
  formState: {
316
320
  ...userFormContext,
317
321
  errors: formErrors,
@@ -1,31 +1,46 @@
1
+ import { parsePhoneNumberFromString } from "libphonenumber-js";
1
2
  import { intl } from "../../global/global";
2
- import { PHONE_EXTENSIONS } from "./phoneExtensions";
3
- function stripLeadingZero(d) {
4
- return d.startsWith("0") ? d.slice(1) : d;
3
+ /**
4
+ * Normalize user input to the domestic form Impact stores: digits only,
5
+ * with the country dial code and trunk-zero prefix removed.
6
+ */
7
+ export function toDomesticNumber(phoneCountryCode, input) {
8
+ var _a;
9
+ if (!input)
10
+ return "";
11
+ const parsed = parsePhoneNumberFromString(input, phoneCountryCode === null || phoneCountryCode === void 0 ? void 0 : phoneCountryCode.toUpperCase());
12
+ return (_a = parsed === null || parsed === void 0 ? void 0 : parsed.nationalNumber) !== null && _a !== void 0 ? _a : input.replace(/\D/g, "");
5
13
  }
6
14
  /**
7
- * Mirrors Impact's I18nPhoneNumberParams validation rules per country.
8
- * Returns true when the phone number is valid for the given the phoneNumberCountryCode country.
15
+ * Validates a phone number against both libphonenumber-js's per-country
16
+ * pattern rules AND Impact's I18nPhoneNumber length rules, applied to the
17
+ * sanitized value we'll submit.
9
18
  */
10
19
  export function isValidI18nPhoneNumber(phoneCountryCode, phoneNumber) {
11
- var _a, _b;
12
20
  if (!phoneCountryCode || !(phoneNumber === null || phoneNumber === void 0 ? void 0 : phoneNumber.trim()))
13
21
  return false;
14
22
  const country = phoneCountryCode.toUpperCase();
15
- const digits = phoneNumber.replace(/\D/g, "");
23
+ const parsed = parsePhoneNumberFromString(phoneNumber, country);
24
+ if (!(parsed === null || parsed === void 0 ? void 0 : parsed.isValid()))
25
+ return false;
26
+ return passesImpactBackendLengthCheck(country, toDomesticNumber(country, phoneNumber));
27
+ }
28
+ /**
29
+ * Mirrors estalea.bucket.phone.I18nPhoneNumber.isValidI18nPhoneNumber()
30
+ * length rules on the already-sanitized (digits-only) submission value.
31
+ */
32
+ function passesImpactBackendLengthCheck(country, digits) {
33
+ if (!digits)
34
+ return false;
16
35
  switch (country) {
17
36
  case "US":
18
37
  case "CA": {
19
- // strip a single leading "1", then exactly 10 digits
20
38
  const n = digits.startsWith("1") ? digits.slice(1) : digits;
21
39
  return n.length === 10;
22
40
  }
23
41
  case "AU":
24
- // 9 or 10 digits
25
42
  return digits.length === 9 || digits.length === 10;
26
43
  case "NZ": {
27
- // trim "640" country prefix or leading "0" (only when >9 digits),
28
- // then 8–10 digits
29
44
  let n = digits;
30
45
  if (n.length > 9) {
31
46
  if (n.startsWith("640"))
@@ -35,25 +50,13 @@ export function isValidI18nPhoneNumber(phoneCountryCode, phoneNumber) {
35
50
  }
36
51
  return n.length >= 8 && n.length <= 10;
37
52
  }
38
- case "GB":
39
- // >= 6 digits after stripping a single leading "0", no dialing-code check
53
+ default:
40
54
  return stripLeadingZero(digits).length >= 6;
41
- default: {
42
- // All other countries: strip a single leading "0", then >= 6 digits
43
- if (stripLeadingZero(digits).length < 6)
44
- return false;
45
- // If input starts with "+", the dialing code (first whitespace-split
46
- // token) must match the selected country exactly. Splits on first
47
- // whitespace, so "+4420 7946 0958" supplies "4420" (not "44") and fails.
48
- if (phoneNumber.trim().startsWith("+")) {
49
- const supplied = phoneNumber.trim().split(/\s/)[0].slice(1);
50
- const expected = (_b = (_a = PHONE_EXTENSIONS[country]) === null || _a === void 0 ? void 0 : _a.dial_code) === null || _b === void 0 ? void 0 : _b.replace(/^\+/, "");
51
- return expected === supplied;
52
- }
53
- return true;
54
- }
55
55
  }
56
56
  }
57
+ function stripLeadingZero(digits) {
58
+ return digits.startsWith("0") ? digits.slice(1) : digits;
59
+ }
57
60
  export function validTaxDocument(requiredType) {
58
61
  const validTypes = ["W9", "W8BENE", "W8BEN"];
59
62
  if (validTypes.includes(requiredType))