@afosto/checkout-ui 0.0.6 → 0.0.7

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.
@@ -1 +1 @@
1
- {"version":3,"file":"informationStep.d.ts","sourceRoot":"","sources":["../../src/steps/informationStep.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EACV,aAAa,EACb,YAAY,IAAI,gBAAgB,EAEjC,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAMjG,MAAM,WAAW,6BAA6B;IAC5C,IAAI,EAAE,UAAU,GAAG,SAAS,CAAC;IAC7B,OAAO,EAAE,8BAA8B,GAAG,IAAI,CAAC;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE;QACZ,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,gBAAgB,EAAE,aAAa,GAAG,IAAI,CAAC;KACxC,CAAC;IACF,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB,EAAE,aAAa,GAAG,IAAI,CAAC;IACzC,aAAa,EAAE,MAAM,CAAC;IACtB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,4BAA4B,EAAE,OAAO,CAAC;IACtC,QAAQ,EAAE,aAAa,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,aAAa,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,EAAE,OAAO,CAAC;CAC9B;AAYD,eAAO,MAAM,eAAe,EAAE,gBAAgB,CAAC,6BAA6B,CA+hCzE,CAAC"}
1
+ {"version":3,"file":"informationStep.d.ts","sourceRoot":"","sources":["../../src/steps/informationStep.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EACV,aAAa,EACb,YAAY,IAAI,gBAAgB,EAEjC,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAMjG,MAAM,WAAW,6BAA6B;IAC5C,IAAI,EAAE,UAAU,GAAG,SAAS,CAAC;IAC7B,OAAO,EAAE,8BAA8B,GAAG,IAAI,CAAC;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE;QACZ,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,gBAAgB,EAAE,aAAa,GAAG,IAAI,CAAC;KACxC,CAAC;IACF,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB,EAAE,aAAa,GAAG,IAAI,CAAC;IACzC,aAAa,EAAE,MAAM,CAAC;IACtB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,4BAA4B,EAAE,OAAO,CAAC;IACtC,QAAQ,EAAE,aAAa,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,aAAa,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,EAAE,OAAO,CAAC;CAC9B;AAYD,eAAO,MAAM,eAAe,EAAE,gBAAgB,CAAC,6BAA6B,CAqjCzE,CAAC"}
@@ -1,24 +1,24 @@
1
- import { CheckoutInformationStep as Y } from "../CheckoutInformationStep/CheckoutInformationStep.js";
1
+ import { CheckoutInformationStep as ni } from "../CheckoutInformationStep/CheckoutInformationStep.js";
2
2
  import { addressDefaultValues as q } from "../constants/addressDefaultValues.js";
3
3
  import { formatAddressResponse as j } from "../utils/formatAddressResponse.js";
4
- import { getErrorMessage as K } from "../utils/getErrorMessage.js";
5
- import { capitalize as Q, isDefined as O } from "@afosto/utils";
4
+ import { getErrorMessage as W } from "../utils/getErrorMessage.js";
5
+ import { capitalize as X, isDefined as D } from "@afosto/utils";
6
6
  import * as u from "yup";
7
- import { formatUpdateAccountInformationPayload as Z } from "../utils/formatUpdateAccountInformationPayload.js";
8
- import { formatUpdateOrganisationOnAccountPayload as ii } from "../utils/formatUpdateOrganisationOnAccountPayload.js";
9
- import { setupCustomValidationRules as ei } from "../utils/setupCustomValidationRules.js";
10
- import { formatInformationStepPayload as ni } from "../utils/formatInformationStepPayload.js";
11
- ei();
12
- const si = {
7
+ import { formatUpdateAccountInformationPayload as si } from "../utils/formatUpdateAccountInformationPayload.js";
8
+ import { formatUpdateOrganisationOnAccountPayload as ri } from "../utils/formatUpdateOrganisationOnAccountPayload.js";
9
+ import { setupCustomValidationRules as ti } from "../utils/setupCustomValidationRules.js";
10
+ import { formatInformationStepPayload as oi } from "../utils/formatInformationStepPayload.js";
11
+ ti();
12
+ const ai = {
13
13
  signUpFailedTitle: "Sign up failed",
14
14
  signUpFailedDescription: "Failed to create an account. Try again or continue as guest.",
15
15
  signUpFailedActionLabel: "Continue as guest",
16
16
  informationStepErrorTitle: "Could not process information",
17
17
  informationStepErrorDescription: "Something went wrong while processing the contact and address information. Please check your input and try again."
18
- }, gi = {
18
+ }, yi = {
19
19
  key: "information",
20
20
  label: "Information",
21
- component: Y,
21
+ component: ni,
22
22
  reviewTargets: [
23
23
  "contactDetails",
24
24
  "businessDetails",
@@ -26,7 +26,7 @@ const si = {
26
26
  "billingAddress"
27
27
  ],
28
28
  defaultValues: (S) => {
29
- const { defaultCountry: a, formatCountryAsOption: v, settings: D } = S || {}, { isB2cExcluded: y, isSharedOrganisationRequired: s } = D || {};
29
+ const { defaultCountry: a, formatCountryAsOption: v, settings: O } = S || {}, { isB2cExcluded: y, isSharedOrganisationRequired: s } = O || {};
30
30
  return {
31
31
  type: y ? "business" : "private",
32
32
  contact: null,
@@ -64,13 +64,13 @@ const si = {
64
64
  },
65
65
  initialize: (S, a, v) => {
66
66
  const {
67
- defaultCountry: D,
67
+ defaultCountry: O,
68
68
  formatCountryAsOption: y,
69
69
  getCountryByCode: s,
70
70
  settings: f,
71
71
  step: g
72
72
  } = v || {}, { defaultValues: C } = g || {}, { addressOptions: B } = a || {}, { countryCode: N } = B || {}, { isB2bExcluded: U, isB2cExcluded: $ } = f || {}, n = typeof C == "function" ? C(v) : C, {
73
- billing: z,
73
+ billing: M,
74
74
  customer: e,
75
75
  delivery: m,
76
76
  expressPayment: b,
@@ -80,23 +80,31 @@ const si = {
80
80
  contact: t,
81
81
  countryCode: d,
82
82
  organisation: r
83
- } = e || {}, { address: A } = z || {}, { address: P } = m || {}, { address: E, customer: p } = b?.details?.express || {}, { shipping: x } = i || {}, { countries: V } = x || {}, I = s(N) || D, R = s(d), c = !!r?.id && !U || $, _ = c ? r?.phoneNumbers?.primary : t?.phoneNumbers?.primary, w = s(
83
+ } = e || {}, { address: A } = M || {}, { address: P } = m || {}, { address: E, customer: p } = b?.details?.express || {}, { shipping: x } = i || {}, { countries: V } = x || {}, I = s(N) || O, R = s(d), c = !!r?.id && !U || $, _ = c ? r?.phoneNumbers?.primary : t?.phoneNumbers?.primary, w = s(
84
84
  o?.countryCode || _?.countryCode
85
- ) || R || I || null, [L] = w?.callingCodes || [], k = (O(o?.number) ? o.number : _?.number || n.phoneNumber).replace(`+${L}`, ""), T = c ? r?.addressing?.shipping?.primary : t?.addressing?.shipping?.primary, l = j(
85
+ ) || R || I || null, [L] = w?.callingCodes || [], k = (D(o?.number) ? o.number : _?.number || n.phoneNumber).replace(`+${L}`, ""), T = c ? r?.addressing?.shipping?.primary : t?.addressing?.shipping?.primary, l = j(
86
86
  P?.addressLine1 ? P : E || T || {}
87
87
  );
88
- let H = null;
88
+ let G = null;
89
89
  if (R && V?.includes(R?.alpha2Code))
90
- H = R;
90
+ G = R;
91
91
  else if (I && V?.includes(I?.alpha2Code))
92
- H = I;
92
+ G = I;
93
93
  else {
94
- const [X] = V || [];
95
- H = s(X);
94
+ const [ei] = V || [];
95
+ G = s(ei);
96
96
  }
97
- const M = s(l?.countryCode) || H, F = O(M) ? y(M) : n.shipping.country, W = c ? r?.addressing?.billing?.primary : t?.addressing?.billing?.primary, h = j(
98
- A?.addressLine1 ? A : W || {}
99
- ), G = s(h?.countryCode) || I, J = O(G) ? y(G) : n.billing.country;
97
+ const J = s(l?.countryCode) || G, F = D(J) ? y(J) : n.shipping.country, z = l?.administrativeArea || n.shipping.administrativeArea, Y = z && typeof z == "string" ? {
98
+ code: z,
99
+ label: z,
100
+ value: z
101
+ } : z, Z = c ? r?.addressing?.billing?.primary : t?.addressing?.billing?.primary, h = j(
102
+ A?.addressLine1 ? A : Z || {}
103
+ ), K = s(h?.countryCode) || I, Q = D(K) ? y(K) : n.billing.country, H = h?.administrativeArea || n.billing.administrativeArea, ii = H && typeof H == "string" ? {
104
+ code: H,
105
+ label: H,
106
+ value: H
107
+ } : H;
100
108
  return {
101
109
  ...n,
102
110
  defaultCountry: y(I),
@@ -119,7 +127,7 @@ const si = {
119
127
  }
120
128
  },
121
129
  phoneNumber: k,
122
- phoneNumberCountry: O(w) ? y(w) : n.phoneNumberCountry,
130
+ phoneNumberCountry: D(w) ? y(w) : n.phoneNumberCountry,
123
131
  phoneNumberId: o?.id || _?.id || n.phoneNumberId,
124
132
  shipping: {
125
133
  ...n.shipping,
@@ -138,7 +146,7 @@ const si = {
138
146
  premiseNumberSuffix: l?.premiseNumberSuffix || n.shipping.premiseNumberSuffix,
139
147
  thoroughfare: l?.thoroughfare || n.shipping.thoroughfare,
140
148
  locality: l?.locality || n.shipping.locality,
141
- administrativeArea: l?.administrativeArea || n.shipping.administrativeArea
149
+ administrativeArea: Y
142
150
  },
143
151
  shippingAddressId: l?.id || n.shippingAddressId,
144
152
  billing: {
@@ -150,25 +158,25 @@ const si = {
150
158
  address_line_2: h?.address_line_2 || n.billing.address_line_2,
151
159
  addressLine1: h?.addressLine1 || n.billing.addressLine1,
152
160
  addressLine2: h?.addressLine2 || n.billing.addressLine2,
153
- country: J,
154
- countryCode: J?.value || n.billing.countryCode,
161
+ country: Q,
162
+ countryCode: Q?.value || n.billing.countryCode,
155
163
  organisation: h?.organisation || n.billing.organisation,
156
164
  postalCode: h?.postalCode || n.billing.postalCode,
157
165
  premiseNumber: h?.premiseNumber || n.billing.premiseNumber,
158
166
  premiseNumberSuffix: h?.premiseNumberSuffix || n.billing.premiseNumberSuffix,
159
167
  thoroughfare: h?.thoroughfare || n.billing.thoroughfare,
160
168
  locality: h?.locality || n.billing.locality,
161
- administrativeArea: h?.administrativeArea || n.billing.administrativeArea
169
+ administrativeArea: ii
162
170
  },
163
171
  billingAddressId: h?.id || n.billingAddressId,
164
- sameBillingAsShippingAddress: O(h?.id) && O(l?.id) ? h?.id === l?.id : n.sameBillingAsShippingAddress
172
+ sameBillingAsShippingAddress: D(h?.id) && D(l?.id) ? h?.id === l?.id : n.sameBillingAsShippingAddress
165
173
  };
166
174
  },
167
175
  isComplete: (S, a) => {
168
176
  const { step: v } = a || {};
169
177
  return v.validationSchema(a).isValidSync(S);
170
178
  },
171
- onEvent: async (S, a, v, D) => {
179
+ onEvent: async (S, a, v, O) => {
172
180
  const { step: y, stepIndex: s } = v || {}, {
173
181
  activeStep: f,
174
182
  addCustomer: g,
@@ -176,7 +184,7 @@ const si = {
176
184
  formatCountryAsOption: B,
177
185
  getCountryByCode: N,
178
186
  settings: U
179
- } = D || {}, { isB2bExcluded: $, isB2cExcluded: n } = U || {}, z = C.current?.formProps?.data || [], e = f === s ? C.current?.getValues() : z[s] ?? {}, m = typeof y.defaultValues == "function" ? y.defaultValues(D) : y.defaultValues;
187
+ } = O || {}, { isB2bExcluded: $, isB2cExcluded: n } = U || {}, M = C.current?.formProps?.data || [], e = f === s ? C.current?.getValues() : M[s] ?? {}, m = typeof y.defaultValues == "function" ? y.defaultValues(O) : y.defaultValues;
180
188
  if (S === "signedIn") {
181
189
  const { user: b, account: i } = a || {};
182
190
  let o = e?.contact;
@@ -193,7 +201,7 @@ const si = {
193
201
  id: _,
194
202
  isValid: w,
195
203
  ...L
196
- } = c || {}, k = L?.countryCode ? B(N(L.countryCode)) : e?.defaultCountry, T = !$ && r?.id || n, l = T && r?.administration?.email || i?.email, M = {
204
+ } = c || {}, k = L?.countryCode ? B(N(L.countryCode)) : e?.defaultCountry, T = !$ && r?.id || n, l = T && r?.administration?.email || i?.email, J = {
197
205
  ...e,
198
206
  ...m || {},
199
207
  contact: o,
@@ -253,14 +261,14 @@ const si = {
253
261
  country: e.defaultCountry
254
262
  },
255
263
  shippingAddressId: x || "",
256
- sameBillingAsShippingAddress: O(_) || O(_) && _ === x
264
+ sameBillingAsShippingAddress: D(_) || D(_) && _ === x
257
265
  };
258
266
  i && (f === s && C.current?.reset({
259
267
  ...e,
260
- ...M
268
+ ...J
261
269
  }), C.current?.formProps?.setData((F) => (F.splice(s, 1, {
262
270
  ...F[s],
263
- ...M
271
+ ...J
264
272
  }), F)));
265
273
  }
266
274
  if (S === "clearSession") {
@@ -353,7 +361,7 @@ const si = {
353
361
  country: e.defaultCountry
354
362
  },
355
363
  shippingAddressId: p || "",
356
- sameBillingAsShippingAddress: !O(c) || O(c) && c === p
364
+ sameBillingAsShippingAddress: !D(c) || D(c) && c === p
357
365
  };
358
366
  f === s && C.current?.reset({
359
367
  ...e,
@@ -445,7 +453,7 @@ const si = {
445
453
  country: e.defaultCountry
446
454
  },
447
455
  shippingAddressId: p || "",
448
- sameBillingAsShippingAddress: !O(d) || O(d) && d === p
456
+ sameBillingAsShippingAddress: !D(d) || D(d) && d === p
449
457
  }), C.current?.formProps?.setData((L) => (L.splice(s, 1, {
450
458
  ...L[s],
451
459
  ...w
@@ -454,7 +462,7 @@ const si = {
454
462
  },
455
463
  submit: async (S, a, v) => {
456
464
  const {
457
- activeStep: D,
465
+ activeStep: O,
458
466
  addInformation: y,
459
467
  currentOrganisation: s,
460
468
  formRef: f,
@@ -465,15 +473,15 @@ const si = {
465
473
  setErrorMessage: U,
466
474
  signUp: $,
467
475
  translations: n = {},
468
- updateAccountInformation: z,
476
+ updateAccountInformation: M,
469
477
  updateOrganisationOnAccount: e
470
478
  } = v || {}, m = {
471
- ...si,
479
+ ...ai,
472
480
  ...n.feedback || {}
473
481
  }, { shouldCreateAccount: b } = S || {};
474
482
  try {
475
483
  U(null);
476
- const i = ni(S, {
484
+ const i = oi(S, {
477
485
  currentOrganisation: s,
478
486
  isSignedIn: B
479
487
  }), o = C();
@@ -490,10 +498,10 @@ const si = {
490
498
  },
491
499
  ...i?.phoneNumber ? { phoneNumber: i?.phoneNumber } : {}
492
500
  }).catch((x) => {
493
- const V = K(x);
501
+ const V = W(x);
494
502
  return U({
495
503
  title: m.feedback?.signUpFailedTitle,
496
- description: V ? Q(V) : m.feedback?.signUpFailedDescription,
504
+ description: V ? X(V) : m.feedback?.signUpFailedDescription,
497
505
  action: {
498
506
  label: m.feedback?.signUpFailedActionLabel,
499
507
  onClick: () => {
@@ -510,7 +518,7 @@ const si = {
510
518
  delete i.customer.contact, i.customer.contactId = p.id, f.current?.setValue("shouldCreateAccount", !1);
511
519
  }
512
520
  if (o && !o?.organisation?.id) {
513
- const p = Z(
521
+ const p = si(
514
522
  {
515
523
  billingAddress: i.billingAddress,
516
524
  billingAddressId: i.billingAddressId,
@@ -530,11 +538,11 @@ const si = {
530
538
  getCountryByCode: g
531
539
  }
532
540
  );
533
- p && await z(p).catch(() => {
541
+ p && await M(p).catch(() => {
534
542
  });
535
543
  }
536
544
  if (o?.organisation?.id && o?.organisation?.role?.toLowerCase() === "admin") {
537
- const p = ii(
545
+ const p = ri(
538
546
  {
539
547
  billingAddress: i.billingAddress,
540
548
  billingAddressId: i.billingAddressId,
@@ -565,8 +573,8 @@ const si = {
565
573
  phoneNumber: i.phoneNumber,
566
574
  shippingAddress: i.shippingAddress
567
575
  }), { customer: d, billing: r, delivery: A, phoneNumber: P } = t || {}, { organisation: E } = d || {};
568
- return f.current?.formProps?.setData((p) => (p.splice(D, 1, {
569
- ...p[D],
576
+ return f.current?.formProps?.setData((p) => (p.splice(O, 1, {
577
+ ...p[O],
570
578
  contact: d?.contact,
571
579
  billingAddressId: r?.address?.id,
572
580
  shippingAddressId: A?.address?.id,
@@ -574,10 +582,10 @@ const si = {
574
582
  phoneNumberIsDirty: !1
575
583
  }), p)), N(E), t;
576
584
  } catch (i) {
577
- const o = K(i);
585
+ const o = W(i);
578
586
  return U({
579
587
  title: m.feedback?.informationStepErrorTitle,
580
- description: o ? Q(o) : m.feedback?.informationStepErrorDescription
588
+ description: o ? X(o) : m.feedback?.informationStepErrorDescription
581
589
  }), Promise.reject(i);
582
590
  }
583
591
  },
@@ -585,12 +593,12 @@ const si = {
585
593
  const {
586
594
  billingAddressValidationSchema: a,
587
595
  shippingAddressValidationSchema: v,
588
- settings: D
596
+ settings: O
589
597
  } = S || {}, {
590
598
  isCocNumberRequired: y,
591
599
  isPhoneNumberRequired: s,
592
600
  isVatNumberRequired: f
593
- } = D || {};
601
+ } = O || {};
594
602
  return u.object().shape({
595
603
  type: u.string().oneOf(["business", "private"]).required(),
596
604
  contact: u.object().nullable(),
@@ -627,5 +635,5 @@ const si = {
627
635
  }
628
636
  };
629
637
  export {
630
- gi as informationStep
638
+ yi as informationStep
631
639
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afosto/checkout-ui",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Afosto react checkout ui components",
5
5
  "author": "Afosto",
6
6
  "license": "MIT",
@@ -29,7 +29,7 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@afosto/components": "^2.0.0-alpha.31",
32
+ "@afosto/components": "^2.0.0-alpha.32",
33
33
  "@afosto/graphql-client": "^3.0.0-alpha.7",
34
34
  "@afosto/hooks": "^3.0.0",
35
35
  "@afosto/storefront": "^3.2.0-beta.11",