@lookiero/checkout 0.8.7-beta.1 → 0.8.7-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.
|
@@ -1,25 +1,61 @@
|
|
|
1
|
+
import { Text } from "@lookiero/aurora-next/build/components/primitives/Text/Text";
|
|
2
|
+
import { useI18nMessage } from "@lookiero/i18n-react";
|
|
1
3
|
import { QueryStatus } from "@lookiero/messaging-react";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { Platform } from "react-native";
|
|
4
|
+
import React, { useCallback, useMemo, useState } from "react";
|
|
5
|
+
import { Platform, View } from "react-native";
|
|
6
|
+
import { generatePath, useNavigate } from "react-router-native";
|
|
7
|
+
import { CheckoutItemStatus } from "../../../../domain/checkoutItem/model/checkoutItem";
|
|
4
8
|
import { usePageView } from "../../../../shared/tracking/infrastructure/usePageView";
|
|
5
9
|
import { Spinner } from "../../../../shared/ui/components/atoms/spinner/Spinner";
|
|
6
10
|
import { useViewFirstAvailableCheckoutByCustomerId } from "../../../projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId";
|
|
11
|
+
import { useViewFiveItemsDiscountByCustomerId } from "../../../projection/checkout/react/useViewFiveItemsDiscountByCustomerId";
|
|
12
|
+
import { useViewPricingByCheckoutId } from "../../../projection/pricing/react/useViewPricingByCheckoutId";
|
|
7
13
|
import { TrackingPage } from "../../../tracking/tracking";
|
|
14
|
+
import { Body } from "../../components/layouts/body/Body";
|
|
8
15
|
import { SafeAreaScrollView } from "../../components/templates/SafeAreaScrollView";
|
|
9
|
-
import {
|
|
16
|
+
import { I18nMessages } from "../../i18n/i18n";
|
|
17
|
+
import { Routes } from "../../routing/routes";
|
|
18
|
+
import { useBasePath } from "../../routing/useBasePath";
|
|
19
|
+
import { theme } from "../../theme/theme";
|
|
10
20
|
import { HEADER_HEIGHT } from "../navigation/components/header/Header.style";
|
|
21
|
+
import { style } from "./Summary.style";
|
|
22
|
+
import { CheckoutItemsTabs } from "./components/checkoutItemsTabs/CheckoutItemsTabs";
|
|
23
|
+
import { FiveItemsDiscountBanner } from "./components/fiveItemsDiscountBanner/FiveItemsDiscountBanner";
|
|
24
|
+
import { StickyPricing } from "./components/stickyPricing/StickyPricing";
|
|
25
|
+
const { spaceXL } = theme();
|
|
11
26
|
const Summary = ({ customerId, country }) => {
|
|
27
|
+
const titleText = useI18nMessage({ id: I18nMessages.SUMMARY_TITLE });
|
|
28
|
+
const descriptionText = useI18nMessage({ id: I18nMessages.SUMMARY_DESCRIPTION });
|
|
29
|
+
const [pricingHeight, setPricingHeight] = useState(0);
|
|
30
|
+
const handleOnPricingLayout = useCallback(({ height }) => setPricingHeight(height), []);
|
|
12
31
|
const [checkout, checkoutStatus] = useViewFirstAvailableCheckoutByCustomerId({ customerId });
|
|
32
|
+
const [pricing, pricingStatus] = useViewPricingByCheckoutId({ checkoutId: checkout?.id });
|
|
33
|
+
const [fiveItemsDiscount = 0, fiveItemsDiscountStatus] = useViewFiveItemsDiscountByCustomerId({ customerId });
|
|
13
34
|
usePageView({
|
|
14
35
|
page: TrackingPage.SUMMARY,
|
|
15
36
|
country,
|
|
16
37
|
checkoutId: checkout?.id,
|
|
17
38
|
});
|
|
39
|
+
const navigate = useNavigate();
|
|
40
|
+
const basePath = useBasePath();
|
|
41
|
+
const [pricingCollapsed, setPricingCollapsed] = useState(true);
|
|
42
|
+
const handleOnPressPricing = useCallback(() => setPricingCollapsed(!pricingCollapsed), [pricingCollapsed]);
|
|
43
|
+
const handleOnSubmit = useCallback(() => navigate(`${basePath}/${Routes.CHECKOUT}`), [basePath, navigate]);
|
|
44
|
+
const handleOnPressItem = useCallback((checkoutItemId) => navigate(`${basePath}/${generatePath(Routes.ITEM_DETAIL, { id: checkoutItemId })}`), [basePath, navigate]);
|
|
45
|
+
const checkoutItemsKept = useMemo(() => checkout?.items.filter((checkoutItem) => checkoutItem.status === CheckoutItemStatus.KEPT || checkoutItem.status === CheckoutItemStatus.REPLACED), [checkout?.items]);
|
|
46
|
+
const checkoutItemsReturned = useMemo(() => checkout?.items.filter((checkoutItem) => checkoutItem.status === CheckoutItemStatus.RETURNED || checkoutItem.status === CheckoutItemStatus.REPLACED), [checkout?.items]);
|
|
18
47
|
const dependenciesLoadedStatuses = [QueryStatus.ERROR, QueryStatus.SUCCESS];
|
|
19
|
-
const dependenciesLoaded = dependenciesLoadedStatuses.includes(checkoutStatus)
|
|
48
|
+
const dependenciesLoaded = dependenciesLoadedStatuses.includes(checkoutStatus) &&
|
|
49
|
+
dependenciesLoadedStatuses.includes(pricingStatus) &&
|
|
50
|
+
dependenciesLoadedStatuses.includes(fiveItemsDiscountStatus);
|
|
20
51
|
if (!dependenciesLoaded)
|
|
21
52
|
return React.createElement(Spinner, null);
|
|
22
|
-
return (React.createElement(SafeAreaScrollView, { scrollerPaddingTop: Platform.OS === "web" || Platform.OS === "android" ? HEADER_HEIGHT : 0 },
|
|
23
|
-
React.createElement(
|
|
53
|
+
return (React.createElement(SafeAreaScrollView, { scrollerPaddingTop: Platform.OS === "web" || Platform.OS === "android" ? HEADER_HEIGHT : 0, footer: pricing && (React.createElement(StickyPricing, { collapsed: pricingCollapsed, pricing: pricing, totalCheckoutItemsKept: checkoutItemsKept?.length || 0, onLayout: Platform.OS !== "web" ? handleOnPricingLayout : undefined, onPress: handleOnPressPricing, onSubmit: handleOnSubmit })) },
|
|
54
|
+
React.createElement(Body, { style: { row: { paddingBottom: pricingHeight || spaceXL } } },
|
|
55
|
+
fiveItemsDiscount !== 0 && React.createElement(FiveItemsDiscountBanner, { fiveItemsDiscount: fiveItemsDiscount }),
|
|
56
|
+
React.createElement(View, { style: style.content },
|
|
57
|
+
React.createElement(Text, { level: 3, style: style.title, heading: true }, titleText),
|
|
58
|
+
React.createElement(Text, { level: 3, style: style.description, body: true }, descriptionText)),
|
|
59
|
+
React.createElement(CheckoutItemsTabs, { checkoutItemsKept: checkoutItemsKept || [], checkoutItemsReturned: checkoutItemsReturned || [], country: country, onPressItem: handleOnPressItem }))));
|
|
24
60
|
};
|
|
25
61
|
export { Summary };
|