@afosto/checkout-ui 0.0.19 → 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":"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.19",
3
+ "version": "0.0.20",
4
4
  "description": "Afosto react checkout ui components",
5
5
  "author": "Afosto",
6
6
  "license": "MIT",