@lookiero/checkout 0.3.9 → 0.3.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lookiero/checkout",
3
- "version": "0.3.9",
3
+ "version": "0.3.10",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -89,7 +89,7 @@
89
89
  "eslint-plugin-react": "^7.31.8",
90
90
  "eslint-plugin-react-hooks": "^4.6.0",
91
91
  "eslint-plugin-react-native": "^4.0.0",
92
- "expo": "~47.0.8",
92
+ "expo": "~46.0.8",
93
93
  "expo-status-bar": "~1.4.0",
94
94
  "graphql": "14.5.8",
95
95
  "graphql-tag": "2.12.6",
@@ -15,7 +15,7 @@ import { root } from "./infrastructure/ui/Root";
15
15
  import { Router } from "./infrastructure/ui/routing/router/Router";
16
16
  import { notificationsRoot } from "./shared/notifications";
17
17
  const apiUrl = Platform.OS !== "web" ? "https://web2.ps.dev.aws.lookiero.es/checkout/api" : __DEV__ ? "/local-to-dev" : "/api";
18
- const authToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjIwOTUxNjAsImV4cCI6MTY2OTM5MTY3MCwiZGlzcGxheU5hbWUiOiJBbGV4YW5kZXIiLCJjb3VudHJ5X2NvZGUiOiJFUyIsImFjY2Vzc1ZpYSI6ImVtYWlsIiwic3Vic2NyaXB0aW9uU3RhcnRpbmdEYXRlIjoiMjAyMC0wOS0wMSIsImltcGVyc29uYXRlZCI6ZmFsc2UsInV1aWQiOiJjZjdjNjQxZi0wZTVjLTQ4NTAtYWUwNy0yNzY3NDdlZGZkMGIiLCJpYXQiOjE2NjY3MTMyNzB9.KaEZc8M5N9TWg6flwUMx7O14DW-u4oTWFzYm23RaL9c";
18
+ const authToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjIwOTUxNjAsImV4cCI6MTY3MjI5OTg4MSwiZGlzcGxheU5hbWUiOiJBbGV4YW5kZXIiLCJjb3VudHJ5X2NvZGUiOiJFUyIsImFjY2Vzc1ZpYSI6ImVtYWlsIiwic3Vic2NyaXB0aW9uU3RhcnRpbmdEYXRlIjoiMjAyMC0wOS0wMSIsImltcGVyc29uYXRlZCI6ZmFsc2UsInV1aWQiOiJjZjdjNjQxZi0wZTVjLTQ4NTAtYWUwNy0yNzY3NDdlZGZkMGIiLCJpYXQiOjE2Njk3MDc4ODF9.-nGGMNmMlsq-PsupefyjxH0Z3td7ybM9TpnUV_VIYSg";
19
19
  const translationsUrl = Platform.OS !== "web" ? "https://web2.ps.dev.aws.lookiero.es/checkout/i18n" : __DEV__ ? "/local-to-i18n" : "/i18n";
20
20
  const translationsApiKey = "f2AfMGaPCZGVbAFWz_OV4GWhBDG_NbZJ";
21
21
  const translations = (locale) => `${translationsUrl}/${locale}?key=${translationsApiKey}&no-folding=true`;
@@ -1,6 +1,5 @@
1
1
  import { FC } from "react";
2
2
  interface CheckoutMiddlewareProps {
3
- readonly basePath: string;
4
3
  readonly customerId: string;
5
4
  readonly loader?: JSX.Element;
6
5
  readonly children: JSX.Element;
@@ -6,7 +6,9 @@ import { Spinner } from "../../../shared/ui/components/atoms/spinner/Spinner";
6
6
  import { useViewFirstAvailableCheckoutByCustomerId } from "../../projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId";
7
7
  import { useShouldIntroBeShown } from "../../projection/uiSetting/react/useShouldIntroBeShown";
8
8
  import { Routes } from "./routes";
9
- const CheckoutMiddleware = ({ basePath, customerId, loader = React.createElement(Spinner, null), children }) => {
9
+ import { useBasePath } from "./useBasePath";
10
+ const CheckoutMiddleware = ({ customerId, loader = React.createElement(Spinner, null), children }) => {
11
+ const basePath = useBasePath();
10
12
  const introShown = useRef(false);
11
13
  const [shouldIntroBeShown, shouldIntroBeShownStatus] = useShouldIntroBeShown();
12
14
  const [checkout, checkoutStatus] = useViewFirstAvailableCheckoutByCustomerId({ customerId });
@@ -5,6 +5,7 @@ import { App } from "../views/App";
5
5
  import { CheckoutAccessibilityMiddleware } from "./CheckoutAccessibilityMiddleware";
6
6
  import { CheckoutMiddleware } from "./CheckoutMiddleware";
7
7
  import { Routes } from "./routes";
8
+ import { BasePathProvider } from "./useBasePath";
8
9
  const Intro = lazy(() => import("../views/intro/Intro").then((module) => ({ default: module.Intro })));
9
10
  const Item = lazy(() => import("../views/item/Item").then((module) => ({ default: module.Item })));
10
11
  const Summary = lazy(() => import("../views/summary/Summary").then((module) => ({ default: module.Summary })));
@@ -13,11 +14,12 @@ const Routing = ({ basePath = "", customerId, locale, I18n, authToken, onI18nErr
13
14
  const routes = useRoutes([
14
15
  {
15
16
  path: "",
16
- element: (React.createElement(CheckoutAccessibilityMiddleware, { customerId: customerId, onNotAccessible: onNotAccessible },
17
- React.createElement(I18n, { loader: React.createElement(Spinner, null), locale: locale, onError: onI18nError },
18
- React.createElement(CheckoutMiddleware, { basePath: basePath, customerId: customerId },
19
- React.createElement(App, null,
20
- React.createElement(Outlet, null)))))),
17
+ element: (React.createElement(BasePathProvider, { basePath: basePath },
18
+ React.createElement(CheckoutAccessibilityMiddleware, { customerId: customerId, onNotAccessible: onNotAccessible },
19
+ React.createElement(I18n, { loader: React.createElement(Spinner, null), locale: locale, onError: onI18nError },
20
+ React.createElement(CheckoutMiddleware, { customerId: customerId },
21
+ React.createElement(App, null,
22
+ React.createElement(Outlet, null))))))),
21
23
  children: [
22
24
  {
23
25
  path: Routes.INTRO,
@@ -0,0 +1,8 @@
1
+ import { FC } from "react";
2
+ interface BasePathProviderProps {
3
+ readonly children: JSX.Element;
4
+ readonly basePath: string;
5
+ }
6
+ export declare const BasePathProvider: FC<BasePathProviderProps>;
7
+ export declare const useBasePath: () => string;
8
+ export {};
@@ -0,0 +1,9 @@
1
+ import { invariant } from "@remix-run/router";
2
+ import React, { createContext, useContext } from "react";
3
+ const BasePathContext = createContext(null);
4
+ export const BasePathProvider = ({ basePath, children }) => (React.createElement(BasePathContext.Provider, { value: basePath }, children));
5
+ export const useBasePath = () => {
6
+ const basePath = useContext(BasePathContext);
7
+ invariant(basePath, "Your are trying to use the useBasePath hook without wrapping your app with the <BasePathProvider>.");
8
+ return basePath;
9
+ };
@@ -3,9 +3,10 @@ import { Text } from "@lookiero/aurora-next/build/components/primitives/Text/Tex
3
3
  import { useI18nMessage } from "@lookiero/i18n-react";
4
4
  import { CommandStatus, QueryStatus } from "@lookiero/messaging-react";
5
5
  import { CheckoutStatus, PaymentFlow } from "@lookiero/payments-front";
6
- import React, { useCallback, useRef, useState } from "react";
6
+ import React, { useCallback, useMemo, useRef, useState } from "react";
7
7
  import { View } from "react-native";
8
8
  import { useNavigate } from "react-router-native";
9
+ import { CheckoutItemStatus } from "../../../../domain/checkoutItem/model/checkoutItem";
9
10
  import { useCreateNotification } from "../../../../shared/notifications";
10
11
  import { NotificationLevel } from "../../../../shared/notifications/domain/notification/model/notification";
11
12
  import { Spinner } from "../../../../shared/ui/components/atoms/spinner/Spinner";
@@ -16,6 +17,8 @@ import { Body } from "../../components/layouts/body/Body";
16
17
  import { SafeAreaScrollView } from "../../components/templates/SafeAreaScrollView";
17
18
  import { I18nMessages } from "../../i18n/i18n";
18
19
  import { Routes } from "../../routing/routes";
20
+ import { useBasePath } from "../../routing/useBasePath";
21
+ import { ProductVariant } from "../item/components/productVariant/ProductVariant";
19
22
  import { style } from "./Checkout.style";
20
23
  import { CheckoutSuccessModal } from "./components/CheckoutSuccessModal";
21
24
  const Checkout = ({ customerId, authToken }) => {
@@ -30,6 +33,7 @@ const Checkout = ({ customerId, authToken }) => {
30
33
  const [createNotification] = useCreateNotification();
31
34
  const [processingCheckout, setProcessingCheckout] = useState(false);
32
35
  const navigate = useNavigate();
36
+ const basePath = useBasePath();
33
37
  const onSubmitCheckout = useCallback(() => {
34
38
  if (!paymentFlowRef.current) {
35
39
  return;
@@ -57,22 +61,20 @@ const Checkout = ({ customerId, authToken }) => {
57
61
  }
58
62
  });
59
63
  }, [createNotification, markAsPaid, paymentFlowPayload]);
60
- const handleOnSuccessModalDismiss = useCallback(() => navigate(Routes.FEEDBACK), [navigate]);
64
+ const handleOnSuccessModalDismiss = useCallback(() => navigate(`${basePath}/${Routes.FEEDBACK}`), [basePath, navigate]);
65
+ const checkoutItemsKept = useMemo(() => checkout?.items.filter((checkoutItem) => checkoutItem.status === CheckoutItemStatus.KEPT || checkoutItem.status === CheckoutItemStatus.REPLACED), [checkout?.items]);
61
66
  const dependenciesLoadedStatuses = [QueryStatus.ERROR, QueryStatus.SUCCESS];
62
67
  const dependenciesLoaded = dependenciesLoadedStatuses.includes(checkoutStatus);
63
68
  if (!dependenciesLoaded)
64
69
  return React.createElement(Spinner, null);
65
70
  return (React.createElement(React.Fragment, null,
71
+ React.createElement(CheckoutSuccessModal, { visible: markAsPaidStatus === CommandStatus.SUCCESS, onDismiss: handleOnSuccessModalDismiss }),
66
72
  React.createElement(SafeAreaScrollView, null,
67
73
  React.createElement(Body, { style: { column: style.bodyColumn } },
68
- React.createElement(View, { style: style.container },
69
- React.createElement(View, { style: style.content },
70
- React.createElement(Text, { level: 3, style: style.title, heading: true }, titleText),
71
- React.createElement(Button, { busy: processingCheckout || markAsPaidStatus === CommandStatus.LOADING,
72
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
73
- // @ts-ignore
74
- testID: "submit-checkout-button", onPress: onSubmitCheckout }, payButtonText),
75
- React.createElement(CheckoutSuccessModal, { visible: markAsPaidStatus === CommandStatus.SUCCESS, onDismiss: handleOnSuccessModalDismiss }))))),
74
+ React.createElement(Text, { level: 3, style: style.title, heading: true }, titleText),
75
+ checkoutItemsKept?.map((checkoutItem) => (React.createElement(View, { key: checkoutItem.id, style: style.checkoutItemKept, testID: "checkout-items-kept" },
76
+ React.createElement(ProductVariant, { brand: checkoutItem.productVariant.brand, color: checkoutItem.productVariant.color, media: checkoutItem.productVariant.media, name: checkoutItem.productVariant.name, price: checkoutItem.price, size: checkoutItem.productVariant.size, status: checkoutItem.status })))),
77
+ React.createElement(Button, { busy: processingCheckout || markAsPaidStatus === CommandStatus.LOADING, onPress: onSubmitCheckout }, payButtonText))),
76
78
  React.createElement(PaymentFlow, { ref: paymentFlowRef, token: authToken })));
77
79
  };
78
80
  export { Checkout };
@@ -2,17 +2,8 @@ declare const style: {
2
2
  bodyColumn: {
3
3
  paddingHorizontal: number;
4
4
  };
5
- bullet: {
6
- alignItems: "center";
7
- flexDirection: "row";
8
- marginVertical: number;
9
- };
10
- container: {
11
- flex: number;
12
- justifyContent: "space-between";
13
- };
14
- content: {
15
- alignItems: "center";
5
+ checkoutItemKept: {
6
+ paddingVertical: number;
16
7
  };
17
8
  title: {
18
9
  marginBottom: number;
@@ -1,21 +1,12 @@
1
1
  import { StyleSheet } from "react-native";
2
2
  import { theme } from "../../theme/theme";
3
- const { spaceS, spaceM, spaceXL } = theme();
3
+ const { spaceM, spaceXL } = theme();
4
4
  const style = StyleSheet.create({
5
5
  bodyColumn: {
6
6
  paddingHorizontal: spaceXL,
7
7
  },
8
- bullet: {
9
- alignItems: "center",
10
- flexDirection: "row",
11
- marginVertical: spaceS,
12
- },
13
- container: {
14
- flex: 1,
15
- justifyContent: "space-between",
16
- },
17
- content: {
18
- alignItems: "center",
8
+ checkoutItemKept: {
9
+ paddingVertical: spaceM,
19
10
  },
20
11
  title: {
21
12
  marginBottom: spaceM,
@@ -14,7 +14,7 @@ const ProductVariant = ({ media, brand, name, price, size, color, status, discar
14
14
  const colorLabel = useI18nMessage({ id: color.label, prefix: COLOR_I18N_PREFIX });
15
15
  const sizeChangeText = useI18nMessage({ id: I18nMessages.PRODUCT_VARIANT_SIZE_CHANGE });
16
16
  const cdnImageUrl = useMediaImage();
17
- return (React.createElement(Pressable, { style: style.container, testID: "product-variant", onPress: onPress },
17
+ return (React.createElement(Pressable, { pointerEvents: onPress ? "auto" : "none", style: style.container, testID: "product-variant", onPress: onPress },
18
18
  React.createElement(View, { style: style.row },
19
19
  React.createElement(View, null,
20
20
  React.createElement(Image, { resizeMode: "contain", style: [style.media, customStyle?.image], testID: "product-variant-media", source: {
@@ -13,6 +13,7 @@ import { Body } from "../../components/layouts/body/Body";
13
13
  import { SafeAreaScrollView } from "../../components/templates/SafeAreaScrollView";
14
14
  import { I18nMessages } from "../../i18n/i18n";
15
15
  import { Routes } from "../../routing/routes";
16
+ import { useBasePath } from "../../routing/useBasePath";
16
17
  import { style } from "./Summary.style";
17
18
  import { CheckoutItemsTabs } from "./components/checkoutItemsTabs/CheckoutItemsTabs";
18
19
  import { FiveItemsDiscountBanner } from "./components/fiveItemsDiscountBanner/FiveItemsDiscountBanner";
@@ -23,11 +24,12 @@ const Summary = ({ customerId }) => {
23
24
  const [checkout, checkoutStatus] = useViewFirstAvailableCheckoutByCustomerId({ customerId });
24
25
  const [pricing, pricingStatus] = useViewPricingByCheckoutId({ checkoutId: checkout?.id });
25
26
  const [fiveItemsDiscount = 0, fiveItemsDiscountStatus] = useViewFiveItemsDiscountByCustomerId({ customerId });
27
+ const navigate = useNavigate();
28
+ const basePath = useBasePath();
26
29
  const [pricingCollapsed, setPricingCollapsed] = useState(true);
27
30
  const handleOnPressPricing = useCallback(() => setPricingCollapsed(!pricingCollapsed), [pricingCollapsed]);
28
- const handleOnSubmit = useCallback(() => void 0, []);
29
- const navigate = useNavigate();
30
- const handleOnPressItem = useCallback((checkoutItemId) => navigate(generatePath(Routes.ITEM_DETAIL, { id: checkoutItemId })), [navigate]);
31
+ const handleOnSubmit = useCallback(() => navigate(`${basePath}/${Routes.CHECKOUT}`), [basePath, navigate]);
32
+ const handleOnPressItem = useCallback((checkoutItemId) => navigate(`${basePath}/${generatePath(Routes.ITEM_DETAIL, { id: checkoutItemId })}`), [basePath, navigate]);
31
33
  const checkoutItemsKept = useMemo(() => checkout?.items.filter((checkoutItem) => checkoutItem.status === CheckoutItemStatus.KEPT || checkoutItem.status === CheckoutItemStatus.REPLACED), [checkout?.items]);
32
34
  const checkoutItemsReturned = useMemo(() => checkout?.items.filter((checkoutItem) => checkoutItem.status === CheckoutItemStatus.RETURNED || checkoutItem.status === CheckoutItemStatus.REPLACED), [checkout?.items]);
33
35
  const dependenciesLoadedStatuses = [QueryStatus.ERROR, QueryStatus.SUCCESS];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lookiero/checkout",
3
- "version": "0.3.9",
3
+ "version": "0.3.10",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -89,7 +89,7 @@
89
89
  "eslint-plugin-react": "^7.31.8",
90
90
  "eslint-plugin-react-hooks": "^4.6.0",
91
91
  "eslint-plugin-react-native": "^4.0.0",
92
- "expo": "~47.0.8",
92
+ "expo": "~46.0.8",
93
93
  "expo-status-bar": "~1.4.0",
94
94
  "graphql": "14.5.8",
95
95
  "graphql-tag": "2.12.6",