@afosto/checkout-ui 0.0.18 → 0.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.
@@ -1 +1 @@
1
- {"version":3,"file":"CheckoutAgreementOptionCondition.d.ts","sourceRoot":"","sources":["../../src/CheckoutAgreementOptionCondition/CheckoutAgreementOptionCondition.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,oCAAoC,EACpC,WAAW,EACZ,MAAM,UAAU,CAAC;AAOlB,QAAA,MAAM,mBAAmB;;;;CAIxB,CAAC;AAEF,MAAM,WAAW,qCAAqC;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,oCAAoC,CAAC;IAChD,YAAY,CAAC,EAAE,WAAW,CAAC,OAAO,mBAAmB,CAAC,CAAC;CACxD;AAED,eAAO,MAAM,gCAAgC,GAC3C,OAAO,qCAAqC,qDA2E7C,CAAC"}
1
+ {"version":3,"file":"CheckoutAgreementOptionCondition.d.ts","sourceRoot":"","sources":["../../src/CheckoutAgreementOptionCondition/CheckoutAgreementOptionCondition.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,oCAAoC,EACpC,WAAW,EACZ,MAAM,UAAU,CAAC;AAOlB,QAAA,MAAM,mBAAmB;;;;CAIxB,CAAC;AAEF,MAAM,WAAW,qCAAqC;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,oCAAoC,CAAC;IAChD,YAAY,CAAC,EAAE,WAAW,CAAC,OAAO,mBAAmB,CAAC,CAAC;CACxD;AAED,eAAO,MAAM,gCAAgC,GAC3C,OAAO,qCAAqC,qDA+E7C,CAAC"}
@@ -1,28 +1,32 @@
1
1
  import { jsxs as s, jsx as i } from "react/jsx-runtime";
2
2
  import { Box as m, Typography as c } from "@afosto/components";
3
- import { TurnDownRightSolid as g } from "../icons/TurnDownRightSolid.js";
4
- import { CheckoutCurrency as C } from "../CheckoutCurrency/CheckoutCurrency.js";
5
- import { camelize as D } from "@afosto/utils";
6
- import { useCheckout as x } from "../CheckoutStateProvider/CheckoutStateProvider.js";
7
- import { formatCurrency as v } from "../utils/formatCurrency.js";
8
- const w = {
3
+ import { TurnDownRightSolid as C } from "../icons/TurnDownRightSolid.js";
4
+ import { CheckoutCurrency as D } from "../CheckoutCurrency/CheckoutCurrency.js";
5
+ import { camelize as x } from "@afosto/utils";
6
+ import { useCheckout as v } from "../CheckoutStateProvider/CheckoutStateProvider.js";
7
+ import { formatCurrency as w } from "../utils/formatCurrency.js";
8
+ const I = {
9
9
  payImmediately: "Pay immediately",
10
10
  remainingAmountDueBeforeDelivery: "Remaining amount due before delivery",
11
11
  withinDaysOfTheInvoiceDate: "Within {days} days of the invoice date"
12
- }, b = (l) => {
12
+ }, j = (l) => {
13
13
  const {
14
14
  condition: e,
15
- currency: a,
16
- locale: r,
15
+ currency: r,
16
+ locale: a,
17
17
  translations: y = {}
18
- } = l, { settings: u, translations: p } = x(), { currency: d } = u || {}, n = {
19
- ...w,
20
- ...p.agreementOptionConditions || {},
18
+ } = l, {
19
+ settings: u,
20
+ summary: p,
21
+ translations: d
22
+ } = v(), f = p?.currency || u?.currency, n = {
23
+ ...I,
24
+ ...d.agreementOptionConditions || {},
21
25
  ...y || {}
22
- }, o = D(e.type?.toLowerCase() || ""), f = e.outcome?.amount || 0;
26
+ }, o = x(e.type?.toLowerCase() || ""), h = e.outcome?.amount || 0;
23
27
  let t = e.type;
24
- return o === "downPayment" && e.isPercentage && (t = `${n.payImmediately}${e.amount > 0 && e.amount < 100 ? ` (${e.amount}%)` : ""}`), o === "downPayment" && !e.isPercentage && (t = `${n.payImmediately}${e.amount > 0 ? ` (${v(e.amount / 100, r, {
25
- currency: a || d
28
+ return o === "downPayment" && e.isPercentage && (t = `${n.payImmediately}${e.amount > 0 && e.amount < 100 ? ` (${e.amount}%)` : ""}`), o === "downPayment" && !e.isPercentage && (t = `${n.payImmediately}${e.amount > 0 ? ` (${w(e.amount / 100, a, {
29
+ currency: r || f
26
30
  })})` : ""}`), o === "postPaid" && (t = n.withinDaysOfTheInvoiceDate.replace(
27
31
  "{days}",
28
32
  e.pastDueAfter.toString()
@@ -38,19 +42,19 @@ const w = {
38
42
  children: [
39
43
  /* @__PURE__ */ s(m, { sx: { display: "flex", alignItems: "center", gap: 2.5 }, children: [
40
44
  /* @__PURE__ */ i(
41
- g,
45
+ C,
42
46
  {
43
- sx: { color: (h) => h.palette.gray[400], fontSize: 16 }
47
+ sx: { color: (g) => g.palette.gray[400], fontSize: 16 }
44
48
  }
45
49
  ),
46
50
  /* @__PURE__ */ i(c, { children: t })
47
51
  ] }),
48
52
  /* @__PURE__ */ i(c, { fontWeight: 500, children: /* @__PURE__ */ i(
49
- C,
53
+ D,
50
54
  {
51
- currency: a,
52
- locale: r,
53
- value: f / 100
55
+ currency: r,
56
+ locale: a,
57
+ value: h / 100
54
58
  }
55
59
  ) })
56
60
  ]
@@ -58,5 +62,5 @@ const w = {
58
62
  );
59
63
  };
60
64
  export {
61
- b as CheckoutAgreementOptionCondition
65
+ j as CheckoutAgreementOptionCondition
62
66
  };
@@ -1 +1 @@
1
- {"version":3,"file":"CheckoutCurrency.d.ts","sourceRoot":"","sources":["../../src/CheckoutCurrency/CheckoutCurrency.tsx"],"names":[],"mappings":"AAIA,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC;CACpC;AAED,eAAO,MAAM,gBAAgB,GAAI,OAAO,qBAAqB,WAoB5D,CAAC"}
1
+ {"version":3,"file":"CheckoutCurrency.d.ts","sourceRoot":"","sources":["../../src/CheckoutCurrency/CheckoutCurrency.tsx"],"names":[],"mappings":"AAIA,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC;CACpC;AAED,eAAO,MAAM,gBAAgB,GAAI,OAAO,qBAAqB,WAqB5D,CAAC"}
@@ -1,18 +1,18 @@
1
- import { useCheckout as y } from "../CheckoutStateProvider/CheckoutStateProvider.js";
2
- const m = (c) => {
1
+ import { useCheckout as m } from "../CheckoutStateProvider/CheckoutStateProvider.js";
2
+ const p = (e) => {
3
3
  const {
4
- currency: e,
5
- value: o,
6
- locale: r,
4
+ currency: c,
5
+ value: r,
6
+ locale: o,
7
7
  options: t
8
- } = c, { locale: n, settings: u } = y(), { currency: l } = u || {}, s = {
8
+ } = e, { locale: n, settings: u, summary: s } = m(), { currency: l } = u || {}, a = {
9
9
  style: "currency",
10
- currency: e || l || "EUR"
11
- }, a = r || n;
12
- return new Intl.NumberFormat(a, t || s).format(
13
- o
10
+ currency: c || s?.currency || l || "EUR"
11
+ }, y = o || n;
12
+ return new Intl.NumberFormat(y, t || a).format(
13
+ r
14
14
  );
15
15
  };
16
16
  export {
17
- m as CheckoutCurrency
17
+ p as CheckoutCurrency
18
18
  };
@@ -9,22 +9,22 @@ const P = {
9
9
  const {
10
10
  agreementTemplate: n,
11
11
  agreements: s,
12
- currency: t,
12
+ currency: r,
13
13
  disablePadding: u = !0,
14
14
  divider: c = !1,
15
15
  hideDefaultAgreementOption: i = !0,
16
- locale: r,
16
+ locale: o,
17
17
  translations: l = {},
18
18
  ...p
19
19
  } = m, {
20
- settings: d,
21
- summary: o,
22
- translations: y
23
- } = v(), { currency: f } = d || {}, h = {
20
+ settings: y,
21
+ summary: t,
22
+ translations: d
23
+ } = v(), f = t?.currency || y?.currency, h = {
24
24
  ...P,
25
- ...y?.summary || {},
25
+ ...d?.summary || {},
26
26
  ...l || {}
27
- }, g = n ?? o?.agreementTemplate, k = s || o?.agreements || [];
27
+ }, g = n ?? t?.agreementTemplate, k = s || t?.agreements || [];
28
28
  return i && g?.type?.toLowerCase() === "default" ? null : /* @__PURE__ */ a(
29
29
  C,
30
30
  {
@@ -34,10 +34,10 @@ const P = {
34
34
  children: k.map((e) => /* @__PURE__ */ a(
35
35
  T,
36
36
  {
37
- currency: t,
38
- locale: r,
39
- description: `${h.payImmediately} (${e.isPercentage ? `${e.amount}%` : A(e.amount / 100, r, {
40
- currency: t || f
37
+ currency: r,
38
+ locale: o,
39
+ description: `${h.payImmediately} (${e.isPercentage ? `${e.amount}%` : A(e.amount / 100, o, {
40
+ currency: r || f
41
41
  })})`,
42
42
  value: e.outcome?.amount || 0
43
43
  },
@@ -1 +1 @@
1
- {"version":3,"file":"useCheckoutShippingMethods.d.ts","sourceRoot":"","sources":["../../src/hooks/useCheckoutShippingMethods.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,WAAW,EAKjB,MAAM,OAAO,CAAC;AAIf,OAAO,KAAK,EACV,gCAAgC,EAChC,iCAAiC,EAClC,MAAM,UAAU,CAAC;AAGlB,eAAO,MAAM,0BAA0B,GAAI,6BAGxC;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;;;;yDA0FqB,gCAAgC;;;;;CAkIrD,CAAC"}
1
+ {"version":3,"file":"useCheckoutShippingMethods.d.ts","sourceRoot":"","sources":["../../src/hooks/useCheckoutShippingMethods.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,WAAW,EAMjB,MAAM,OAAO,CAAC;AAIf,OAAO,KAAK,EACV,gCAAgC,EAChC,iCAAiC,EAClC,MAAM,UAAU,CAAC;AAGlB,eAAO,MAAM,0BAA0B,GAAI,6BAGxC;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;;;;yDA2GqB,gCAAgC;;;;;CA8JrD,CAAC"}
@@ -1,138 +1,159 @@
1
- import { useState as p, useRef as O, useCallback as w, useEffect as Q } from "react";
2
- import { useCheckout as T } from "../CheckoutStateProvider/CheckoutStateProvider.js";
3
- import { useGetLatest as z, useAsyncDebounce as W } from "@afosto/hooks";
4
- import { isDefined as x } from "@afosto/utils";
5
- import { useCheckoutFormContext as X } from "./useCheckoutFormContext.js";
6
- const et = ({
7
- countryCode: o,
8
- postalCode: u
1
+ import { useState as h, useRef as L, useMemo as et, useCallback as B, useEffect as it } from "react";
2
+ import { useCheckout as st } from "../CheckoutStateProvider/CheckoutStateProvider.js";
3
+ import { useGetLatest as A, useAsyncDebounce as ot } from "@afosto/hooks";
4
+ import { isDefined as V } from "@afosto/utils";
5
+ import { useCheckoutFormContext as nt } from "./useCheckoutFormContext.js";
6
+ const dt = ({
7
+ countryCode: i,
8
+ postalCode: p
9
9
  }) => {
10
- const [B, f] = p(!1), [L, k] = p(!0), [R, a] = p(!1), [V, n] = p([]), [q, C] = p([]), S = O(0), {
11
- activeStep: y,
12
- addShippingMethod: A,
13
- getPickupPoints: E,
14
- getShippingMethods: G,
15
- setSubmitButtonDisabled: F
16
- } = T(), h = z({
17
- activeStep: y,
18
- addShippingMethod: A,
19
- getPickupPoints: E,
20
- getShippingMethods: G,
21
- setSubmitButtonDisabled: F
22
- }), H = X(), r = z(H), M = w(
10
+ const [C, m] = h(!1), [E, M] = h(!0), [G, d] = h(!1), [F, u] = h([]), [$, y] = h([]), b = L(0), D = L(0), w = L(null), {
11
+ activeStep: H,
12
+ addShippingMethod: J,
13
+ getPickupPoints: K,
14
+ getShippingMethods: N,
15
+ setSubmitButtonDisabled: O,
16
+ summary: s
17
+ } = st(), U = et(
18
+ () => JSON.stringify([
19
+ s?.subtotal,
20
+ (s?.items ?? []).map(({ sku: t, quantity: e, total: o }) => [
21
+ t,
22
+ e,
23
+ o
24
+ ]),
25
+ (s?.coupons ?? []).map(({ code: t }) => t)
26
+ ]),
27
+ [s?.coupons, s?.items, s?.subtotal]
28
+ ), l = A({
29
+ activeStep: H,
30
+ addShippingMethod: J,
31
+ getPickupPoints: K,
32
+ getShippingMethods: N,
33
+ setSubmitButtonDisabled: O
34
+ }), j = nt(), a = A(j), I = B(
23
35
  async ({
24
- searchValue: e,
25
- clearUnavailablePickupPoint: i = !1
36
+ searchValue: t,
37
+ clearUnavailablePickupPoint: e = !1
26
38
  } = {}) => {
27
- const b = ++S.current, d = () => b === S.current;
39
+ const o = ++b.current, v = () => o === b.current;
28
40
  try {
29
- f(!1), a(!0);
30
- const { getPickupPoints: P } = h(), g = await P({
31
- countryCode: o,
32
- postalCode: x(e) ? e : u ?? ""
33
- }), { pickupPoints: l } = g || {};
34
- if (!d())
41
+ m(!1), d(!0);
42
+ const { getPickupPoints: f } = l(), q = await f({
43
+ countryCode: i,
44
+ postalCode: V(t) ? t : p ?? ""
45
+ }), { pickupPoints: P } = q || {};
46
+ if (!v())
35
47
  return;
36
- if (i) {
37
- const { getValues: s, setValue: c } = r() || {}, { pickupPointId: t } = s() || {};
38
- x(t) && !(l ?? []).some(
39
- (I) => I.id === t
40
- ) && c("pickupPointId", "");
48
+ if (e) {
49
+ const { getValues: r, setValue: g } = a() || {}, { pickupPointId: S } = r() || {};
50
+ V(S) && !(P ?? []).some(
51
+ (n) => n.id === S
52
+ ) && g("pickupPointId", "");
41
53
  }
42
- n(l ?? []), a(!1);
54
+ u(P ?? []), d(!1);
43
55
  } catch {
44
- if (!d())
56
+ if (!v())
45
57
  return;
46
- f(!0), n([]), a(!1);
58
+ m(!0), u([]), d(!1);
47
59
  }
48
60
  },
49
- [o, h, r, u]
50
- ), m = w(
51
- (e) => {
52
- if (n([]), e?.isPickupPoint) {
53
- M();
61
+ [i, l, a, p]
62
+ ), R = B(
63
+ (t) => {
64
+ if (u([]), t?.isPickupPoint) {
65
+ I();
54
66
  return;
55
67
  }
56
- S.current++, f(!1), a(!1);
68
+ b.current++, m(!1), d(!1);
57
69
  },
58
- [M]
70
+ [I]
59
71
  );
60
- Q(() => {
61
- o && (async () => {
72
+ it(() => {
73
+ const t = ++D.current, e = () => t === D.current, o = `${i}|${p ?? ""}`;
74
+ i && (async () => {
62
75
  const {
63
- activeStep: i,
64
- addShippingMethod: b,
65
- getShippingMethods: d,
66
- setSubmitButtonDisabled: P
67
- } = h();
76
+ activeStep: f,
77
+ addShippingMethod: q,
78
+ getShippingMethods: P,
79
+ setSubmitButtonDisabled: r
80
+ } = l();
68
81
  try {
69
- const g = await d({
70
- countryCode: o,
71
- postalCode: u ?? ""
82
+ const g = await P({
83
+ countryCode: i,
84
+ postalCode: p ?? ""
72
85
  }), {
73
- currentShippingMethod: l,
74
- shippingMethods: s
86
+ currentShippingMethod: S,
87
+ shippingMethods: n
75
88
  } = g || {};
76
- if (C(s), !s.length) {
77
- P(!0), k(!1);
89
+ if (!e())
90
+ return;
91
+ if (y(n), !n.length) {
92
+ r(!0), M(!1);
78
93
  return;
79
94
  }
80
- let c = s.find(
81
- (t) => t.id === l?.id
95
+ let k = n.find(
96
+ (c) => c.id === S?.id
82
97
  );
83
- if (!x(c)) {
84
- const [t] = s;
98
+ if (!V(k)) {
99
+ const [c] = n;
85
100
  try {
86
- const I = r(), { formProps: j, getValues: J, reset: K } = I || {}, { setData: N } = j || {};
87
- await b({ methodId: t.id }), c = t;
88
- const D = {
89
- methodId: t.id,
90
- isPickupPoint: t.isPickupPoint,
101
+ const X = a(), { formProps: Y, getValues: Z, reset: _ } = X || {}, { setData: tt } = Y || {};
102
+ await q({ methodId: c.id }), k = c;
103
+ const z = {
104
+ methodId: c.id,
105
+ isPickupPoint: c.isPickupPoint,
91
106
  pickupPointId: ""
92
107
  };
93
- K({
94
- ...J(),
95
- ...D
96
- }), N?.((v) => (v.splice(i, 1, {
97
- ...v[i],
98
- ...D
99
- }), v));
108
+ _({
109
+ ...Z(),
110
+ ...z
111
+ }), tt?.((x) => (x.splice(f, 1, {
112
+ ...x[f],
113
+ ...z
114
+ }), x));
100
115
  } catch {
101
116
  }
102
117
  }
103
- m(c), k(!1);
118
+ if (!e())
119
+ return;
120
+ const { getValues: T } = a() || {}, { methodId: W } = T?.() || {};
121
+ w.current === o && k?.id === W || R(k), w.current = o, r(!1), M(!1);
104
122
  } catch {
105
- P(!0), n([]), C([]), k(!1);
123
+ if (!e())
124
+ return;
125
+ r(!0), u([]), y([]), M(!1);
106
126
  }
107
127
  })();
108
128
  }, [
109
- o,
110
- h,
111
- r,
112
- m,
113
- u
129
+ U,
130
+ i,
131
+ l,
132
+ a,
133
+ R,
134
+ p
114
135
  ]);
115
- const U = W(
116
- async (e) => {
117
- const { value: i } = e?.target || {};
118
- await M({
119
- searchValue: i,
136
+ const Q = ot(
137
+ async (t) => {
138
+ const { value: e } = t?.target || {};
139
+ await I({
140
+ searchValue: e,
120
141
  clearUnavailablePickupPoint: !0
121
142
  });
122
143
  },
123
144
  250
124
145
  );
125
146
  return {
126
- hasSearchPickupPointsError: B,
127
- isInitializingShippingMethods: L,
128
- isSearchingPickupPoints: R,
129
- loadPickupPointsForShippingMethod: m,
130
- pickupPoints: V,
131
- searchPickupPoints: U,
132
- setPickupPoints: n,
133
- shippingMethods: q
147
+ hasSearchPickupPointsError: C,
148
+ isInitializingShippingMethods: E,
149
+ isSearchingPickupPoints: G,
150
+ loadPickupPointsForShippingMethod: R,
151
+ pickupPoints: F,
152
+ searchPickupPoints: Q,
153
+ setPickupPoints: u,
154
+ shippingMethods: $
134
155
  };
135
156
  };
136
157
  export {
137
- et as useCheckoutShippingMethods
158
+ dt as useCheckoutShippingMethods
138
159
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afosto/checkout-ui",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "Afosto react checkout ui components",
5
5
  "author": "Afosto",
6
6
  "license": "MIT",