@lookiero/checkout 4.0.0-beta.0 → 4.0.0-beta.1

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,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 useViewPricingByCheckoutId = ({ checkoutId }) => useQuery({
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: "always",
20
+ refetchOnMount: queryOptions.refetchOnMount,
18
21
  staleTime: Infinity,
19
22
  retry: false,
20
23
  refetchOnWindowFocus: false,
@@ -22,7 +22,10 @@ const CheckoutPaymentModal = ({ customerId, country, isFirstOrder, orderNumber,
22
22
  checkoutId: checkout?.id,
23
23
  });
24
24
  const [sizeChangeEnabled] = useViewIsSizeChangeEnabledByCheckoutId({ checkoutId: checkout?.id });
25
- const [pricing, pricingStatus] = useViewPricingByCheckoutId({ checkoutId: checkout?.id });
25
+ const [pricing] = useViewPricingByCheckoutId({
26
+ checkoutId: checkout?.id,
27
+ queryOptions: { refetchOnMount: true },
28
+ });
26
29
  const [authToken, setAuthToken] = useState();
27
30
  useEffect(() => {
28
31
  const loadAuthToken = async () => setAuthToken(await getAuthToken());
@@ -49,7 +52,7 @@ const CheckoutPaymentModal = ({ customerId, country, isFirstOrder, orderNumber,
49
52
  trackCheckout({
50
53
  checkoutItems,
51
54
  checkoutItemId,
52
- checkoutValue: Number(checkoutValue),
55
+ checkoutValue,
53
56
  isFirstOrder,
54
57
  orderNumber,
55
58
  productVariantId,
@@ -76,14 +79,12 @@ const CheckoutPaymentModal = ({ customerId, country, isFirstOrder, orderNumber,
76
79
  logger,
77
80
  });
78
81
  useEffect(() => {
79
- if (paymentFlowPayload && sizeChangeEnabled !== undefined) {
82
+ if (paymentFlowPayload && sizeChangeEnabled !== undefined && pricing !== undefined) {
80
83
  submitCheckout({ paymentFlowPayload, sizeChangeEnabled });
81
84
  }
82
- }, [paymentFlowPayload, sizeChangeEnabled, submitCheckout]);
85
+ }, [paymentFlowPayload, pricing, sizeChangeEnabled, submitCheckout]);
83
86
  const dependenciesLoadedStatuses = [QueryStatus.ERROR, QueryStatus.SUCCESS];
84
- const dependenciesLoaded = (dependenciesLoadedStatuses.includes(checkoutStatus) || checkout) &&
85
- dependenciesLoadedStatuses.includes(pricingStatus) &&
86
- authToken;
87
+ const dependenciesLoaded = (dependenciesLoadedStatuses.includes(checkoutStatus) || checkout) && authToken;
87
88
  if (!dependenciesLoaded)
88
89
  return null;
89
90
  return React.createElement(PaymentFlow, { ref: paymentFlowRef, token: authToken });
@@ -6,7 +6,7 @@ interface TrackCheckoutFunctionArgs {
6
6
  readonly checkoutItems: number;
7
7
  readonly productVariantId: string[];
8
8
  readonly checkoutItemId: string[];
9
- readonly checkoutValue: number;
9
+ readonly checkoutValue: string;
10
10
  readonly sizeChange: string[];
11
11
  readonly isFirstOrder: boolean;
12
12
  }
@@ -90,7 +90,7 @@ interface CheckoutTrackingEvent extends BaseTrackingEvent {
90
90
  readonly checkoutItems: number;
91
91
  readonly productVariantId: string[];
92
92
  readonly checkoutItemId: string[];
93
- readonly checkoutValue: number;
93
+ readonly checkoutValue: string;
94
94
  readonly sizeChange: string[];
95
95
  readonly isFirstOrder: boolean;
96
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lookiero/checkout",
3
- "version": "4.0.0-beta.0",
3
+ "version": "4.0.0-beta.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [