@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,
|
|
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
|
|
2
|
-
import { useCheckout as
|
|
3
|
-
import { useGetLatest as
|
|
4
|
-
import { isDefined as
|
|
5
|
-
import { useCheckoutFormContext as
|
|
6
|
-
const
|
|
7
|
-
countryCode:
|
|
8
|
-
postalCode:
|
|
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 [
|
|
11
|
-
activeStep:
|
|
12
|
-
addShippingMethod:
|
|
13
|
-
getPickupPoints:
|
|
14
|
-
getShippingMethods:
|
|
15
|
-
setSubmitButtonDisabled:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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:
|
|
25
|
-
clearUnavailablePickupPoint:
|
|
36
|
+
searchValue: t,
|
|
37
|
+
clearUnavailablePickupPoint: e = !1
|
|
26
38
|
} = {}) => {
|
|
27
|
-
const
|
|
39
|
+
const o = ++b.current, v = () => o === b.current;
|
|
28
40
|
try {
|
|
29
|
-
|
|
30
|
-
const { getPickupPoints:
|
|
31
|
-
countryCode:
|
|
32
|
-
postalCode:
|
|
33
|
-
}), { pickupPoints:
|
|
34
|
-
if (!
|
|
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 (
|
|
37
|
-
const { getValues:
|
|
38
|
-
|
|
39
|
-
(
|
|
40
|
-
) &&
|
|
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
|
-
|
|
54
|
+
u(P ?? []), d(!1);
|
|
43
55
|
} catch {
|
|
44
|
-
if (!
|
|
56
|
+
if (!v())
|
|
45
57
|
return;
|
|
46
|
-
|
|
58
|
+
m(!0), u([]), d(!1);
|
|
47
59
|
}
|
|
48
60
|
},
|
|
49
|
-
[
|
|
50
|
-
),
|
|
51
|
-
(
|
|
52
|
-
if (
|
|
53
|
-
|
|
61
|
+
[i, l, a, p]
|
|
62
|
+
), R = B(
|
|
63
|
+
(t) => {
|
|
64
|
+
if (u([]), t?.isPickupPoint) {
|
|
65
|
+
I();
|
|
54
66
|
return;
|
|
55
67
|
}
|
|
56
|
-
|
|
68
|
+
b.current++, m(!1), d(!1);
|
|
57
69
|
},
|
|
58
|
-
[
|
|
70
|
+
[I]
|
|
59
71
|
);
|
|
60
|
-
|
|
61
|
-
|
|
72
|
+
it(() => {
|
|
73
|
+
const t = ++D.current, e = () => t === D.current, o = `${i}|${p ?? ""}`;
|
|
74
|
+
i && (async () => {
|
|
62
75
|
const {
|
|
63
|
-
activeStep:
|
|
64
|
-
addShippingMethod:
|
|
65
|
-
getShippingMethods:
|
|
66
|
-
setSubmitButtonDisabled:
|
|
67
|
-
} =
|
|
76
|
+
activeStep: f,
|
|
77
|
+
addShippingMethod: q,
|
|
78
|
+
getShippingMethods: P,
|
|
79
|
+
setSubmitButtonDisabled: r
|
|
80
|
+
} = l();
|
|
68
81
|
try {
|
|
69
|
-
const g = await
|
|
70
|
-
countryCode:
|
|
71
|
-
postalCode:
|
|
82
|
+
const g = await P({
|
|
83
|
+
countryCode: i,
|
|
84
|
+
postalCode: p ?? ""
|
|
72
85
|
}), {
|
|
73
|
-
currentShippingMethod:
|
|
74
|
-
shippingMethods:
|
|
86
|
+
currentShippingMethod: S,
|
|
87
|
+
shippingMethods: n
|
|
75
88
|
} = g || {};
|
|
76
|
-
if (
|
|
77
|
-
|
|
89
|
+
if (!e())
|
|
90
|
+
return;
|
|
91
|
+
if (y(n), !n.length) {
|
|
92
|
+
r(!0), M(!1);
|
|
78
93
|
return;
|
|
79
94
|
}
|
|
80
|
-
let
|
|
81
|
-
(
|
|
95
|
+
let k = n.find(
|
|
96
|
+
(c) => c.id === S?.id
|
|
82
97
|
);
|
|
83
|
-
if (!
|
|
84
|
-
const [
|
|
98
|
+
if (!V(k)) {
|
|
99
|
+
const [c] = n;
|
|
85
100
|
try {
|
|
86
|
-
const
|
|
87
|
-
await
|
|
88
|
-
const
|
|
89
|
-
methodId:
|
|
90
|
-
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
|
-
|
|
94
|
-
...
|
|
95
|
-
...
|
|
96
|
-
}),
|
|
97
|
-
...
|
|
98
|
-
...
|
|
99
|
-
}),
|
|
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
|
-
|
|
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
|
-
|
|
123
|
+
if (!e())
|
|
124
|
+
return;
|
|
125
|
+
r(!0), u([]), y([]), M(!1);
|
|
106
126
|
}
|
|
107
127
|
})();
|
|
108
128
|
}, [
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
129
|
+
U,
|
|
130
|
+
i,
|
|
131
|
+
l,
|
|
132
|
+
a,
|
|
133
|
+
R,
|
|
134
|
+
p
|
|
114
135
|
]);
|
|
115
|
-
const
|
|
116
|
-
async (
|
|
117
|
-
const { value:
|
|
118
|
-
await
|
|
119
|
-
searchValue:
|
|
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:
|
|
127
|
-
isInitializingShippingMethods:
|
|
128
|
-
isSearchingPickupPoints:
|
|
129
|
-
loadPickupPointsForShippingMethod:
|
|
130
|
-
pickupPoints:
|
|
131
|
-
searchPickupPoints:
|
|
132
|
-
setPickupPoints:
|
|
133
|
-
shippingMethods:
|
|
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
|
-
|
|
158
|
+
dt as useCheckoutShippingMethods
|
|
138
159
|
};
|