@lookiero/checkout 0.7.0 → 0.7.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,12 +1,5 @@
1
1
  declare const COLOR_I18N_PREFIX = "color.";
2
2
  declare enum I18nMessages {
3
- INTRO_TITLE = "intro.title",
4
- INTRO_SUBTITLE = "intro.subtitle",
5
- INTRO_DISCOUNT = "intro.discount",
6
- INTRO_BULLET_ONE = "intro.bullet_one",
7
- INTRO_BULLET_TWO = "intro.bullet_two",
8
- INTRO_BULLET_THREE = "intro.bullet_three",
9
- INTRO_BUTTON = "intro.button",
10
3
  ITEM_SIZE = "item.size",
11
4
  ITEM_COLOR = "item.color",
12
5
  ITEM_UNIQUE = "item.unique",
@@ -1,13 +1,6 @@
1
1
  const COLOR_I18N_PREFIX = "color.";
2
2
  var I18nMessages;
3
3
  (function (I18nMessages) {
4
- I18nMessages["INTRO_TITLE"] = "intro.title";
5
- I18nMessages["INTRO_SUBTITLE"] = "intro.subtitle";
6
- I18nMessages["INTRO_DISCOUNT"] = "intro.discount";
7
- I18nMessages["INTRO_BULLET_ONE"] = "intro.bullet_one";
8
- I18nMessages["INTRO_BULLET_TWO"] = "intro.bullet_two";
9
- I18nMessages["INTRO_BULLET_THREE"] = "intro.bullet_three";
10
- I18nMessages["INTRO_BUTTON"] = "intro.button";
11
4
  I18nMessages["ITEM_SIZE"] = "item.size";
12
5
  I18nMessages["ITEM_COLOR"] = "item.color";
13
6
  I18nMessages["ITEM_UNIQUE"] = "item.unique";
@@ -6,13 +6,10 @@ import { CheckoutItemStatus } from "../../../domain/checkoutItem/model/checkoutI
6
6
  import { Spinner } from "../../../shared/ui/components/atoms/spinner/Spinner";
7
7
  import { useStartCheckout } from "../../domain/checkout/react/useStartCheckout";
8
8
  import { useViewFirstAvailableCheckoutByCustomerId } from "../../projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId";
9
- import { useShouldIntroBeShown } from "../../projection/uiSetting/react/useShouldIntroBeShown";
10
9
  import { Routes } from "./routes";
11
10
  import { useBasePath } from "./useBasePath";
12
11
  const CheckoutMiddleware = ({ customerId, loader = React.createElement(Spinner, null), children }) => {
13
12
  const basePath = useBasePath();
14
- const introShown = useRef(false);
15
- const [shouldIntroBeShown, shouldIntroBeShownStatus] = useShouldIntroBeShown();
16
13
  const navigatedToFirstItemWithoutCustomerDecision = useRef(false);
17
14
  const [checkout, checkoutStatus] = useViewFirstAvailableCheckoutByCustomerId({ customerId });
18
15
  const firstItemWithoutCustomerDecision = checkout?.items.find((item) => item.status === CheckoutItemStatus.INITIAL);
@@ -22,7 +19,6 @@ const CheckoutMiddleware = ({ customerId, loader = React.createElement(Spinner,
22
19
  startCheckout();
23
20
  }
24
21
  }, [checkout?.id, startCheckout]);
25
- const introRouteMatch = useMatch(`${basePath}/${Routes.INTRO}`);
26
22
  const itemRouteMatch = useMatch(`${basePath}/${Routes.ITEM}`);
27
23
  const itemDetailRouteMatch = useMatch(`${basePath}/${Routes.ITEM_DETAIL}`);
28
24
  const summaryRouteMatch = useMatch(`${basePath}/${Routes.SUMMARY}`);
@@ -32,8 +28,7 @@ const CheckoutMiddleware = ({ customerId, loader = React.createElement(Spinner,
32
28
  const checkoutShown = useRef(false);
33
29
  checkoutShown.current = checkoutShown.current || (Boolean(checkoutRouteMatch) && !Boolean(checkoutPaymentRouteMatch));
34
30
  const dependenciesLoadedStatuses = [QueryStatus.ERROR, QueryStatus.SUCCESS];
35
- const dependenciesLoaded = dependenciesLoadedStatuses.includes(shouldIntroBeShownStatus) &&
36
- (dependenciesLoadedStatuses.includes(checkoutStatus) || checkout);
31
+ const dependenciesLoaded = dependenciesLoadedStatuses.includes(checkoutStatus) || checkout;
37
32
  if (!dependenciesLoaded) {
38
33
  return loader;
39
34
  }
@@ -54,31 +49,20 @@ const CheckoutMiddleware = ({ customerId, loader = React.createElement(Spinner,
54
49
  !(summaryRouteMatch || itemDetailRouteMatch || checkoutRouteMatch || checkoutPaymentRouteMatch)) {
55
50
  return React.createElement(Navigate, { to: `${basePath}/${Routes.SUMMARY}`, replace: true });
56
51
  }
57
- /* Navigate to the Intro if required */
58
- if (shouldIntroBeShown && !introShown.current && firstItemWithoutCustomerDecision !== undefined) {
59
- if (introRouteMatch) {
60
- introShown.current = true;
61
- }
62
- else {
63
- return React.createElement(Navigate, { to: `${basePath}/${Routes.INTRO}`, replace: true });
52
+ /* Item/ItemDetail 404 - Not found */
53
+ if (itemRouteMatch || itemDetailRouteMatch) {
54
+ const checkoutItem = checkout?.items.find((item) => item.id === itemRouteMatch?.params.id || itemDetailRouteMatch?.params.id);
55
+ if (!checkoutItem) {
56
+ return React.createElement(Navigate, { to: `${basePath}/${Routes.HOME}`, replace: true });
64
57
  }
65
58
  }
66
- else {
67
- /* Item/ItemDetail 404 - Not found */
68
- if (itemRouteMatch || itemDetailRouteMatch) {
69
- const checkoutItem = checkout?.items.find((item) => item.id === itemRouteMatch?.params.id || itemDetailRouteMatch?.params.id);
70
- if (!checkoutItem) {
71
- return React.createElement(Navigate, { to: `${basePath}/${Routes.HOME}`, replace: true });
72
- }
73
- }
74
- /* Navigate to the first item without customer's decission */
75
- navigatedToFirstItemWithoutCustomerDecision.current =
76
- navigatedToFirstItemWithoutCustomerDecision.current ||
77
- Boolean(itemRouteMatch && itemRouteMatch.params.id === firstItemWithoutCustomerDecision?.id);
78
- if (firstItemWithoutCustomerDecision && !navigatedToFirstItemWithoutCustomerDecision.current) {
79
- navigatedToFirstItemWithoutCustomerDecision.current = true;
80
- return (React.createElement(Navigate, { to: generatePath(`${basePath}/${Routes.ITEM}`, { id: firstItemWithoutCustomerDecision.id }), replace: true }));
81
- }
59
+ /* Navigate to the first item without customer's decission */
60
+ navigatedToFirstItemWithoutCustomerDecision.current =
61
+ navigatedToFirstItemWithoutCustomerDecision.current ||
62
+ Boolean(itemRouteMatch && itemRouteMatch.params.id === firstItemWithoutCustomerDecision?.id);
63
+ if (firstItemWithoutCustomerDecision && !navigatedToFirstItemWithoutCustomerDecision.current) {
64
+ navigatedToFirstItemWithoutCustomerDecision.current = true;
65
+ return (React.createElement(Navigate, { to: generatePath(`${basePath}/${Routes.ITEM}`, { id: firstItemWithoutCustomerDecision.id }), replace: true }));
82
66
  }
83
67
  return children;
84
68
  };
@@ -7,7 +7,6 @@ import { CheckoutAccessibilityMiddleware } from "./CheckoutAccessibilityMiddlewa
7
7
  import { CheckoutMiddleware } from "./CheckoutMiddleware";
8
8
  import { Routes } from "./routes";
9
9
  import { BasePathProvider } from "./useBasePath";
10
- const Intro = lazy(() => import("../views/intro/Intro").then((module) => ({ default: module.Intro })));
11
10
  const Item = lazy(() => import("../views/item/Item").then((module) => ({ default: module.Item })));
12
11
  const Summary = lazy(() => import("../views/summary/Summary").then((module) => ({ default: module.Summary })));
13
12
  const Checkout = lazy(() => import("../views/checkout/Checkout").then((module) => ({ default: module.Checkout })));
@@ -24,11 +23,6 @@ const Routing = ({ basePath = "", customer, locale, I18n, menu, tabBar, getAuthT
24
23
  React.createElement(App, { customerId: customer?.customerId, menu: menu, tabBar: tabBar },
25
24
  React.createElement(Outlet, null))))))),
26
25
  children: [
27
- {
28
- path: Routes.INTRO,
29
- element: (React.createElement(Suspense, { fallback: React.createElement(Spinner, null) },
30
- React.createElement(Intro, { customerId: customer?.customerId }))),
31
- },
32
26
  {
33
27
  path: Routes.ITEM,
34
28
  element: (React.createElement(Suspense, { fallback: React.createElement(Spinner, null) },
@@ -1,6 +1,5 @@
1
1
  export declare enum Routes {
2
2
  HOME = "",
3
- INTRO = "intro",
4
3
  ITEM_DETAIL = "item/:id/detail",
5
4
  ITEM = "item/:id",
6
5
  SUMMARY = "summary",
@@ -1,7 +1,6 @@
1
1
  export var Routes;
2
2
  (function (Routes) {
3
3
  Routes["HOME"] = "";
4
- Routes["INTRO"] = "intro";
5
4
  Routes["ITEM_DETAIL"] = "item/:id/detail";
6
5
  Routes["ITEM"] = "item/:id";
7
6
  Routes["SUMMARY"] = "summary";
@@ -1,4 +1,3 @@
1
1
  declare enum UISettings {
2
- INTRO_SHOWN_COUNT = "INTRO_SHOWN_COUNT"
3
2
  }
4
3
  export { UISettings };
@@ -1,5 +1,4 @@
1
1
  var UISettings;
2
2
  (function (UISettings) {
3
- UISettings["INTRO_SHOWN_COUNT"] = "INTRO_SHOWN_COUNT";
4
3
  })(UISettings || (UISettings = {}));
5
4
  export { UISettings };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lookiero/checkout",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -1,10 +0,0 @@
1
- import { CommandStatus } from "@lookiero/messaging-react";
2
- interface IncrementIntroShownCountFunction {
3
- (): Promise<void>;
4
- }
5
- type UseIncrementIntroShownCount = [incrementIntroShownCount: IncrementIntroShownCountFunction, status: CommandStatus];
6
- interface UseIncrementIntroShownCountFunction {
7
- (): UseIncrementIntroShownCount;
8
- }
9
- declare const useIncrementIntroShownCount: UseIncrementIntroShownCountFunction;
10
- export { useIncrementIntroShownCount };
@@ -1,11 +0,0 @@
1
- import { useCallback } from "react";
2
- import { useViewIntroShownCount } from "../../../projection/uiSetting/react/useViewIntroShownCount";
3
- import { UISettings } from "../../../ui/settings/UISettings";
4
- import { useUpdateUiSetting } from "./useUpdateUiSetting";
5
- const useIncrementIntroShownCount = () => {
6
- const [update, status] = useUpdateUiSetting();
7
- const [introShownCount] = useViewIntroShownCount();
8
- const incrementIntroShownCount = useCallback(() => update({ key: UISettings.INTRO_SHOWN_COUNT, value: introShownCount + 1 }), [introShownCount, update]);
9
- return [incrementIntroShownCount, status];
10
- };
11
- export { useIncrementIntroShownCount };
@@ -1,6 +0,0 @@
1
- import { QueryStatus } from "@lookiero/messaging-react";
2
- interface UseShouldIntroBeShownFunction {
3
- (): [boolean, QueryStatus];
4
- }
5
- declare const useShouldIntroBeShown: UseShouldIntroBeShownFunction;
6
- export { useShouldIntroBeShown };
@@ -1,7 +0,0 @@
1
- import { useViewIntroShownCount } from "./useViewIntroShownCount";
2
- const MAX_INTRO_SHOWN_COUNT = 2;
3
- const useShouldIntroBeShown = () => {
4
- const [introShownCount, introShownCountStatus] = useViewIntroShownCount();
5
- return [introShownCount < MAX_INTRO_SHOWN_COUNT, introShownCountStatus];
6
- };
7
- export { useShouldIntroBeShown };
@@ -1,6 +0,0 @@
1
- import { QueryStatus } from "@lookiero/messaging-react";
2
- interface UseViewIntroShownCountFunction {
3
- (): [number, QueryStatus];
4
- }
5
- declare const useViewIntroShownCount: UseViewIntroShownCountFunction;
6
- export { useViewIntroShownCount };
@@ -1,9 +0,0 @@
1
- import { UISettings } from "../../../ui/settings/UISettings";
2
- import { useViewUiSettingByKey } from "./useViewUiSettingByKey";
3
- const useViewIntroShownCount = () => {
4
- const [introShownCount, introShownCountStatus] = useViewUiSettingByKey({
5
- key: UISettings.INTRO_SHOWN_COUNT,
6
- });
7
- return [introShownCount?.value || 0, introShownCountStatus];
8
- };
9
- export { useViewIntroShownCount };
@@ -1,6 +0,0 @@
1
- import { FC } from "react";
2
- type IntroProps = {
3
- readonly customerId: string;
4
- };
5
- declare const Intro: FC<IntroProps>;
6
- export { Intro };
@@ -1,52 +0,0 @@
1
- import { Button } from "@lookiero/aurora-next/build/components/atoms/Button/Button";
2
- import { Icon } from "@lookiero/aurora-next/build/components/primitives/Icon/Icon";
3
- import { Text } from "@lookiero/aurora-next/build/components/primitives/Text/Text";
4
- import { useI18nMessage } from "@lookiero/i18n-react";
5
- import { CommandStatus, QueryStatus } from "@lookiero/messaging-react";
6
- import React from "react";
7
- import { Platform, View } from "react-native";
8
- import { Spinner } from "../../../../shared/ui/components/atoms/spinner/Spinner";
9
- import { useIncrementIntroShownCount } from "../../../domain/uiSetting/react/useIncrementIntroShownCount";
10
- import { useViewFiveItemsDiscountByCustomerId } from "../../../projection/checkout/react/useViewFiveItemsDiscountByCustomerId";
11
- import { Body } from "../../components/layouts/body/Body";
12
- import { SafeAreaScrollView } from "../../components/templates/SafeAreaScrollView";
13
- import { I18nMessages } from "../../i18n/i18n";
14
- import { HEADER_HEIGHT } from "../navigation/components/header/Header.style";
15
- import { style } from "./Intro.style";
16
- const Bullet = ({ text }) => (React.createElement(View, { style: style.bullet },
17
- React.createElement(Icon, { name: "rounded-tick", style: style.tickIcon }),
18
- React.createElement(Text, { level: 2, detail: true }, text)));
19
- const Intro = ({ customerId }) => {
20
- const titleText = useI18nMessage({ id: I18nMessages.INTRO_TITLE });
21
- const subTitleText = useI18nMessage({ id: I18nMessages.INTRO_SUBTITLE });
22
- const discountText = useI18nMessage({ id: I18nMessages.INTRO_DISCOUNT });
23
- const bulletOneText = useI18nMessage({ id: I18nMessages.INTRO_BULLET_ONE });
24
- const bulletTwoText = useI18nMessage({ id: I18nMessages.INTRO_BULLET_TWO });
25
- const bulletThreeText = useI18nMessage({ id: I18nMessages.INTRO_BULLET_THREE });
26
- const buttonText = useI18nMessage({ id: I18nMessages.INTRO_BUTTON });
27
- const [fiveItemsDiscount, fiveItemsDiscountStatus] = useViewFiveItemsDiscountByCustomerId({
28
- customerId,
29
- });
30
- const [incrementIntroShownCount, incrementIntroShownCountStatus] = useIncrementIntroShownCount();
31
- if (fiveItemsDiscountStatus === QueryStatus.LOADING)
32
- return React.createElement(Spinner, null);
33
- return (React.createElement(SafeAreaScrollView, { scrollerPaddingTop: Platform.OS === "web" || Platform.OS === "android" ? HEADER_HEIGHT : 0 },
34
- React.createElement(Body, { style: { column: style.bodyColumn } },
35
- React.createElement(View, { style: style.intro },
36
- React.createElement(View, { style: style.content },
37
- React.createElement(Text, { level: 3, style: style.title, heading: true }, titleText),
38
- React.createElement(Text, { level: 3, style: style.subtitle, body: true }, subTitleText),
39
- fiveItemsDiscount !== 0 && (React.createElement(View, { style: style.discountContainer },
40
- React.createElement(View, { style: style.discount },
41
- React.createElement(Text, { level: 2, heading: true },
42
- "- ",
43
- fiveItemsDiscount),
44
- React.createElement(Text, { level: 3, style: style.percentage, heading: true }, "%")),
45
- React.createElement(Text, { level: 3, body: true }, discountText))),
46
- React.createElement(View, { style: style.description },
47
- React.createElement(Bullet, { text: bulletOneText }),
48
- React.createElement(Bullet, { text: bulletTwoText }),
49
- React.createElement(Bullet, { text: bulletThreeText }))),
50
- React.createElement(Button, { disabled: incrementIntroShownCountStatus === CommandStatus.LOADING, onPress: incrementIntroShownCount }, buttonText)))));
51
- };
52
- export { Intro };
@@ -1,52 +0,0 @@
1
- declare const style: {
2
- bodyColumn: {
3
- paddingHorizontal: number;
4
- };
5
- bullet: {
6
- alignItems: "center";
7
- flexDirection: "row";
8
- marginVertical: number;
9
- };
10
- content: {
11
- alignItems: "center";
12
- };
13
- description: {
14
- borderWidth: number;
15
- marginBottom: number;
16
- padding: number;
17
- width: string;
18
- };
19
- discount: {
20
- alignItems: "flex-end";
21
- flexDirection: "row";
22
- justifyContent: "center";
23
- marginBottom: number;
24
- };
25
- discountContainer: {
26
- alignItems: "center";
27
- backgroundColor: string;
28
- marginBottom: number;
29
- padding: number;
30
- textAlign: "center";
31
- width: string;
32
- };
33
- intro: {
34
- flex: number;
35
- justifyContent: "space-between";
36
- };
37
- percentage: {
38
- marginLeft: number;
39
- };
40
- subtitle: {
41
- marginBottom: number;
42
- textAlign: "center";
43
- };
44
- tickIcon: {
45
- marginRight: number;
46
- };
47
- title: {
48
- marginBottom: number;
49
- textAlign: "center";
50
- };
51
- };
52
- export { style };
@@ -1,55 +0,0 @@
1
- import { StyleSheet } from "react-native";
2
- import { theme } from "../../theme/theme";
3
- const { borderSize, colorAccent, spaceXS, spaceS, spaceM, spaceL, spaceXL } = theme();
4
- const style = StyleSheet.create({
5
- bodyColumn: {
6
- paddingHorizontal: spaceXL,
7
- },
8
- bullet: {
9
- alignItems: "center",
10
- flexDirection: "row",
11
- marginVertical: spaceS,
12
- },
13
- content: {
14
- alignItems: "center",
15
- },
16
- description: {
17
- borderWidth: borderSize,
18
- marginBottom: spaceXL,
19
- padding: spaceM,
20
- width: "100%",
21
- },
22
- discount: {
23
- alignItems: "flex-end",
24
- flexDirection: "row",
25
- justifyContent: "center",
26
- marginBottom: spaceS,
27
- },
28
- discountContainer: {
29
- alignItems: "center",
30
- backgroundColor: colorAccent,
31
- marginBottom: spaceL,
32
- padding: spaceM,
33
- textAlign: "center",
34
- width: "100%",
35
- },
36
- intro: {
37
- flex: 1,
38
- justifyContent: "space-between",
39
- },
40
- percentage: {
41
- marginLeft: spaceXS,
42
- },
43
- subtitle: {
44
- marginBottom: spaceXL,
45
- textAlign: "center",
46
- },
47
- tickIcon: {
48
- marginRight: spaceS,
49
- },
50
- title: {
51
- marginBottom: spaceM,
52
- textAlign: "center",
53
- },
54
- });
55
- export { style };