@lookiero/checkout 4.0.0-beta.0 → 4.0.0-beta.2
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.
- package/dist/infrastructure/projection/pricing/react/useViewPricingByCheckoutId.d.ts +4 -0
- package/dist/infrastructure/projection/pricing/react/useViewPricingByCheckoutId.js +5 -2
- package/dist/infrastructure/ui/views/checkout/components/checkoutPaymentModal/CheckoutPaymentModal.js +9 -13
- package/package.json +1 -1
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { UseQueryFunctionResult } from "@lookiero/messaging-react";
|
|
2
2
|
import { PricingProjection } from "../../../../projection/pricing/pricing";
|
|
3
|
+
interface QueryOptions {
|
|
4
|
+
readonly refetchOnMount?: boolean | "always";
|
|
5
|
+
}
|
|
3
6
|
interface UseViewPricingByCheckoutIdFunctionArgs {
|
|
4
7
|
readonly checkoutId: string;
|
|
8
|
+
readonly queryOptions?: QueryOptions;
|
|
5
9
|
}
|
|
6
10
|
interface UseViewPricingByCheckoutIdFunction {
|
|
7
11
|
(args: UseViewPricingByCheckoutIdFunctionArgs): UseQueryFunctionResult<PricingProjection>;
|
|
@@ -9,12 +9,15 @@ const shouldInvalidate = (event) => isCheckoutItemKept(event) ||
|
|
|
9
9
|
isCheckoutItemReplaced(event) ||
|
|
10
10
|
isCheckoutItemReturned(event) ||
|
|
11
11
|
isCheckoutItemReset(event);
|
|
12
|
-
const
|
|
12
|
+
const DEFAULT_QUERY_OPTIONS = {
|
|
13
|
+
refetchOnMount: "always",
|
|
14
|
+
};
|
|
15
|
+
const useViewPricingByCheckoutId = ({ checkoutId, queryOptions = DEFAULT_QUERY_OPTIONS, }) => useQuery({
|
|
13
16
|
query: viewPricingByCheckoutId({ checkoutId }),
|
|
14
17
|
contextId: MESSAGING_CONTEXT_ID,
|
|
15
18
|
invalidation: shouldInvalidate,
|
|
16
19
|
options: {
|
|
17
|
-
refetchOnMount:
|
|
20
|
+
refetchOnMount: queryOptions.refetchOnMount,
|
|
18
21
|
staleTime: Infinity,
|
|
19
22
|
retry: false,
|
|
20
23
|
refetchOnWindowFocus: false,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { useIntl } from "@lookiero/i18n-react";
|
|
2
1
|
import { QueryStatus } from "@lookiero/messaging-react";
|
|
3
2
|
import { PaymentFlow } from "@lookiero/payments-front";
|
|
4
3
|
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
@@ -22,7 +21,10 @@ const CheckoutPaymentModal = ({ customerId, country, isFirstOrder, orderNumber,
|
|
|
22
21
|
checkoutId: checkout?.id,
|
|
23
22
|
});
|
|
24
23
|
const [sizeChangeEnabled] = useViewIsSizeChangeEnabledByCheckoutId({ checkoutId: checkout?.id });
|
|
25
|
-
const [pricing
|
|
24
|
+
const [pricing] = useViewPricingByCheckoutId({
|
|
25
|
+
checkoutId: checkout?.id,
|
|
26
|
+
queryOptions: { refetchOnMount: true },
|
|
27
|
+
});
|
|
26
28
|
const [authToken, setAuthToken] = useState();
|
|
27
29
|
useEffect(() => {
|
|
28
30
|
const loadAuthToken = async () => setAuthToken(await getAuthToken());
|
|
@@ -30,8 +32,6 @@ const CheckoutPaymentModal = ({ customerId, country, isFirstOrder, orderNumber,
|
|
|
30
32
|
}, [getAuthToken]);
|
|
31
33
|
const basePath = useBasePath();
|
|
32
34
|
const navigate = useNavigate();
|
|
33
|
-
const intl = useIntl();
|
|
34
|
-
const translateNumber = useCallback((value) => intl.formatNumber(value.amount / 100, { style: "currency", currency: value.currency }), [intl]);
|
|
35
35
|
const trackCheckout = useTrackCheckout({
|
|
36
36
|
checkoutId: checkout?.id,
|
|
37
37
|
country,
|
|
@@ -42,14 +42,13 @@ const CheckoutPaymentModal = ({ customerId, country, isFirstOrder, orderNumber,
|
|
|
42
42
|
const checkoutItemsKept = checkout?.items.filter((checkoutItem) => checkoutItem.status === CheckoutItemStatus.KEPT || checkoutItem.status === CheckoutItemStatus.REPLACED);
|
|
43
43
|
const checkoutItems = checkoutItemsKept?.length || 0;
|
|
44
44
|
const checkoutItemId = checkout?.items.map((checkoutItem) => checkoutItem.id) || [];
|
|
45
|
-
const
|
|
46
|
-
const checkoutValue = translateNumber(pendingToPay);
|
|
45
|
+
const checkoutValue = pricing?.pendingToPay.amount / 100;
|
|
47
46
|
const productVariantId = checkoutItemsKept?.map(({ productVariant }) => productVariant.id) || [];
|
|
48
47
|
const sizeChange = checkoutItemsKept?.filter(({ replacedFor }) => Boolean(replacedFor)).map(({ id }) => id) || [];
|
|
49
48
|
trackCheckout({
|
|
50
49
|
checkoutItems,
|
|
51
50
|
checkoutItemId,
|
|
52
|
-
checkoutValue
|
|
51
|
+
checkoutValue,
|
|
53
52
|
isFirstOrder,
|
|
54
53
|
orderNumber,
|
|
55
54
|
productVariantId,
|
|
@@ -65,7 +64,6 @@ const CheckoutPaymentModal = ({ customerId, country, isFirstOrder, orderNumber,
|
|
|
65
64
|
orderNumber,
|
|
66
65
|
pricing?.pendingToPay,
|
|
67
66
|
trackCheckout,
|
|
68
|
-
translateNumber,
|
|
69
67
|
]);
|
|
70
68
|
const [submitCheckout] = useSubmitCheckout({
|
|
71
69
|
checkoutId: checkout?.id,
|
|
@@ -76,14 +74,12 @@ const CheckoutPaymentModal = ({ customerId, country, isFirstOrder, orderNumber,
|
|
|
76
74
|
logger,
|
|
77
75
|
});
|
|
78
76
|
useEffect(() => {
|
|
79
|
-
if (paymentFlowPayload && sizeChangeEnabled !== undefined) {
|
|
77
|
+
if (paymentFlowPayload && sizeChangeEnabled !== undefined && pricing !== undefined) {
|
|
80
78
|
submitCheckout({ paymentFlowPayload, sizeChangeEnabled });
|
|
81
79
|
}
|
|
82
|
-
}, [paymentFlowPayload, sizeChangeEnabled, submitCheckout]);
|
|
80
|
+
}, [paymentFlowPayload, pricing, sizeChangeEnabled, submitCheckout]);
|
|
83
81
|
const dependenciesLoadedStatuses = [QueryStatus.ERROR, QueryStatus.SUCCESS];
|
|
84
|
-
const dependenciesLoaded = (dependenciesLoadedStatuses.includes(checkoutStatus) || checkout) &&
|
|
85
|
-
dependenciesLoadedStatuses.includes(pricingStatus) &&
|
|
86
|
-
authToken;
|
|
82
|
+
const dependenciesLoaded = (dependenciesLoadedStatuses.includes(checkoutStatus) || checkout) && authToken;
|
|
87
83
|
if (!dependenciesLoaded)
|
|
88
84
|
return null;
|
|
89
85
|
return React.createElement(PaymentFlow, { ref: paymentFlowRef, token: authToken });
|