@lookiero/checkout 0.8.7-beta.0 → 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,12 +1,13 @@
|
|
|
1
1
|
import { PortalProvider } from "@gorhom/portal";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { StatusBar } from "react-native";
|
|
4
|
+
import { SafeAreaProvider } from "react-native-safe-area-context";
|
|
4
5
|
import { Notifications } from "../../../shared/notifications/infrastructure/ui/views/Notifications";
|
|
5
6
|
import { MESSAGING_CONTEXT_ID } from "../../delivery/baseBootstrap";
|
|
6
7
|
import { theme } from "../theme/theme";
|
|
7
8
|
import { Navigation } from "./navigation/Navigation";
|
|
8
9
|
const { colorBase } = theme();
|
|
9
|
-
const App = ({ customerId, menu, tabBar, children }) => (React.createElement(
|
|
10
|
+
const App = ({ customerId, menu, tabBar, children }) => (React.createElement(SafeAreaProvider, null,
|
|
10
11
|
React.createElement(StatusBar, { backgroundColor: colorBase, barStyle: "dark-content", translucent: true }),
|
|
11
12
|
React.createElement(Notifications, { contextId: MESSAGING_CONTEXT_ID }),
|
|
12
13
|
React.createElement(Navigation, { customerId: customerId, menu: menu, tabBar: tabBar },
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { usePortal } from "@lookiero/aurora-next/build/contexts/Portal/Portal";
|
|
2
|
-
import React, {
|
|
2
|
+
import React, { useState } from "react";
|
|
3
3
|
import { Platform } from "react-native";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const Navigation = ({ customerId, menu, tabBar: TabBar, children }) => {
|
|
7
|
-
const [menuVisible, setMenuVisible] = useState(false);
|
|
8
|
-
const handleOnOpenMenu = useCallback(() => setMenuVisible(true), []);
|
|
9
|
-
const handleOnCloseMenu = useCallback(() => setMenuVisible(false), []);
|
|
4
|
+
const Navigation = ({ tabBar: TabBar, children }) => {
|
|
5
|
+
const [menuVisible] = useState(false);
|
|
10
6
|
const { busy } = usePortal();
|
|
11
7
|
return (React.createElement(React.Fragment, null,
|
|
12
|
-
React.createElement(Header, { customerId: customerId, menu: menu, menuVisible: menuVisible, style: style.header, onCloseMenu: handleOnCloseMenu, onOpenMenu: handleOnOpenMenu }),
|
|
13
8
|
children,
|
|
14
9
|
Platform.OS !== "web" && React.createElement(TabBar, { isPortalBusy: busy, panel: menuVisible })));
|
|
15
10
|
};
|
|
@@ -1,21 +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";
|
|
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";
|
|
3
8
|
import { usePageView } from "../../../../shared/tracking/infrastructure/usePageView";
|
|
4
9
|
import { Spinner } from "../../../../shared/ui/components/atoms/spinner/Spinner";
|
|
5
10
|
import { useViewFirstAvailableCheckoutByCustomerId } from "../../../projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId";
|
|
11
|
+
import { useViewFiveItemsDiscountByCustomerId } from "../../../projection/checkout/react/useViewFiveItemsDiscountByCustomerId";
|
|
12
|
+
import { useViewPricingByCheckoutId } from "../../../projection/pricing/react/useViewPricingByCheckoutId";
|
|
6
13
|
import { TrackingPage } from "../../../tracking/tracking";
|
|
7
|
-
import {
|
|
14
|
+
import { Body } from "../../components/layouts/body/Body";
|
|
15
|
+
import { SafeAreaScrollView } from "../../components/templates/SafeAreaScrollView";
|
|
16
|
+
import { I18nMessages } from "../../i18n/i18n";
|
|
17
|
+
import { Routes } from "../../routing/routes";
|
|
18
|
+
import { useBasePath } from "../../routing/useBasePath";
|
|
19
|
+
import { theme } from "../../theme/theme";
|
|
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();
|
|
8
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), []);
|
|
9
31
|
const [checkout, checkoutStatus] = useViewFirstAvailableCheckoutByCustomerId({ customerId });
|
|
32
|
+
const [pricing, pricingStatus] = useViewPricingByCheckoutId({ checkoutId: checkout?.id });
|
|
33
|
+
const [fiveItemsDiscount = 0, fiveItemsDiscountStatus] = useViewFiveItemsDiscountByCustomerId({ customerId });
|
|
10
34
|
usePageView({
|
|
11
35
|
page: TrackingPage.SUMMARY,
|
|
12
36
|
country,
|
|
13
37
|
checkoutId: checkout?.id,
|
|
14
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]);
|
|
15
47
|
const dependenciesLoadedStatuses = [QueryStatus.ERROR, QueryStatus.SUCCESS];
|
|
16
|
-
const dependenciesLoaded = dependenciesLoadedStatuses.includes(checkoutStatus)
|
|
48
|
+
const dependenciesLoaded = dependenciesLoadedStatuses.includes(checkoutStatus) &&
|
|
49
|
+
dependenciesLoadedStatuses.includes(pricingStatus) &&
|
|
50
|
+
dependenciesLoadedStatuses.includes(fiveItemsDiscountStatus);
|
|
17
51
|
if (!dependenciesLoaded)
|
|
18
52
|
return React.createElement(Spinner, null);
|
|
19
|
-
return 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 }))));
|
|
20
60
|
};
|
|
21
61
|
export { Summary };
|