@lookiero/checkout 0.2.0 → 0.2.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,5 +1,4 @@
1
- import { AggregateRoot } from "@lookiero/messaging";
2
- import { CommandHandlerFunction } from "@lookiero/messaging/domain/model";
1
+ import { AggregateRoot, CommandHandlerFunction } from "@lookiero/messaging";
3
2
  import { UpdateUiSetting } from "../command/updateUiSetting";
4
3
  interface UiSetting extends AggregateRoot {
5
4
  readonly key: string;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { EndpointFunction } from "@lookiero/i18n";
1
2
  import { FC } from "react";
2
3
  import { RootProps } from "./infrastructure/ui/Root";
3
4
  import { IsCheckoutAccessibleByCustomerIdProjection } from "./projection/checkout/viewIsCheckoutAccessibleByCustomerId";
@@ -10,6 +11,7 @@ interface IsCheckoutAccessibleFunction {
10
11
  interface BootstrapFunctionArgs {
11
12
  readonly getAuthToken: () => string;
12
13
  readonly apiUrl: string;
14
+ readonly translations: EndpointFunction;
13
15
  }
14
16
  interface BootstrapFunctionReturn {
15
17
  readonly Root: FC<RootProps>;
package/dist/index.js CHANGED
@@ -1,9 +1,15 @@
1
+ import { fetchFetchTranslation } from "@lookiero/i18n";
2
+ import { i18n } from "@lookiero/i18n-react";
1
3
  import { bootstrap as checkoutBootstrap } from "./infrastructure/delivery/bootstrap";
2
4
  import { root } from "./infrastructure/ui/Root";
3
5
  import { viewIsCheckoutAccessibleByCustomerId, } from "./projection/checkout/viewIsCheckoutAccessibleByCustomerId";
4
- const bootstrap = ({ apiUrl, getAuthToken }) => {
6
+ const bootstrap = ({ apiUrl, getAuthToken, translations }) => {
5
7
  const { Component: Messaging, queryBus } = checkoutBootstrap({ apiUrl, getAuthToken });
6
- const Root = root({ Messaging });
8
+ const I18n = i18n({
9
+ fetchTranslation: fetchFetchTranslation({ endpoint: translations }),
10
+ contextId: "CheckoutI18n",
11
+ });
12
+ const Root = root({ Messaging, I18n });
7
13
  const isCheckoutAccessible = ({ customerId }) => queryBus(viewIsCheckoutAccessibleByCustomerId({ customerId }));
8
14
  return {
9
15
  Root,
@@ -1,9 +1,15 @@
1
1
  import { bootstrap as messagingBootstrap } from "@lookiero/messaging-react";
2
+ import { UPDATE_UI_SETTING } from "../../../domain/uiSetting/command/updateUiSetting";
3
+ import { updateUiSettingHandler } from "../../../domain/uiSetting/model/uiSetting";
2
4
  import { CheckoutItemStatus, viewFirstAvailableCheckoutByCustomerIdHandler, VIEW_FIRST_AVAILABLE_CHECKOUT_BY_CUSTOMER_ID, } from "../../../projection/checkout/viewFirstAvailableCheckoutByCustomerId";
3
5
  import { viewIsCheckoutAccessibleByCustomerIdHandler, VIEW_IS_CHECKOUT_ACCESSIBLE_BY_CUSTOMER_ID, } from "../../../projection/checkout/viewIsCheckoutAccessibleByCustomerId";
4
6
  import { viewIsCheckoutEnabledByCustomerIdHandler, VIEW_IS_CHECKOUT_ENABLED_BY_CUSTOMER_ID, } from "../../../projection/checkout/viewIsCheckoutEnabledByCustomerId";
5
7
  import { CHECKOUT_MESSAGING_REACT_ID } from "../bootstrap";
8
+ import { viewUiSettingByKeyHandler, VIEW_UI_SETTING_BY_KEY } from "../../../projection/uiSetting/viewUiSettingByKey";
9
+ import { getUiSetting, saveUiSetting } from "../../domain/uiSetting/model/storageUiSettings";
10
+ import { storageUiSettingByKeyView } from "../../projection/storageUiSettingByKeyView";
6
11
  import { startedCheckoutWithItems } from "./checkout.mock";
12
+ import { read, write } from "../../persistence/asyncStorageStorage";
7
13
  const firstAvailableCheckoutByCustomerIdView = async () => startedCheckoutWithItems({ status: [CheckoutItemStatus.KEPT, CheckoutItemStatus.INITIAL] });
8
14
  const isCheckoutEnabledByCustomerIdView = async () => true;
9
15
  const bootstrap = () => messagingBootstrap({ id: CHECKOUT_MESSAGING_REACT_ID })
@@ -14,5 +20,12 @@ const bootstrap = () => messagingBootstrap({ id: CHECKOUT_MESSAGING_REACT_ID })
14
20
  view: isCheckoutEnabledByCustomerIdView,
15
21
  })
16
22
  .query(VIEW_IS_CHECKOUT_ACCESSIBLE_BY_CUSTOMER_ID, viewIsCheckoutAccessibleByCustomerIdHandler, {})
23
+ .query(VIEW_UI_SETTING_BY_KEY, viewUiSettingByKeyHandler, {
24
+ view: storageUiSettingByKeyView({ read }),
25
+ })
26
+ .command(UPDATE_UI_SETTING, updateUiSettingHandler, {
27
+ get: getUiSetting({ read }),
28
+ save: saveUiSetting({ write }),
29
+ })
17
30
  .build();
18
31
  export { bootstrap };
@@ -1,9 +1,15 @@
1
1
  import { bootstrap as messagingBootstrap } from "@lookiero/messaging-react";
2
+ import { UPDATE_UI_SETTING } from "../../domain/uiSetting/command/updateUiSetting";
3
+ import { updateUiSettingHandler } from "../../domain/uiSetting/model/uiSetting";
2
4
  import { viewFirstAvailableCheckoutByCustomerIdHandler, VIEW_FIRST_AVAILABLE_CHECKOUT_BY_CUSTOMER_ID, } from "../../projection/checkout/viewFirstAvailableCheckoutByCustomerId";
3
5
  import { viewIsCheckoutAccessibleByCustomerIdHandler, VIEW_IS_CHECKOUT_ACCESSIBLE_BY_CUSTOMER_ID, } from "../../projection/checkout/viewIsCheckoutAccessibleByCustomerId";
4
6
  import { viewIsCheckoutEnabledByCustomerIdHandler, VIEW_IS_CHECKOUT_ENABLED_BY_CUSTOMER_ID, } from "../../projection/checkout/viewIsCheckoutEnabledByCustomerId";
7
+ import { viewUiSettingByKeyHandler, VIEW_UI_SETTING_BY_KEY } from "../../projection/uiSetting/viewUiSettingByKey";
8
+ import { getUiSetting, saveUiSetting } from "../domain/uiSetting/model/storageUiSettings";
9
+ import { read, write } from "../persistence/asyncStorageStorage";
5
10
  import { httpFirstAvailableCheckoutByCustomerIdView } from "../projection/httpFirstAvailableCheckoutByCustomerIdView";
6
11
  import { httpIsCheckoutEnabledByCustomerIdView } from "../projection/httpIsCheckoutEnabledByCustomerIdView";
12
+ import { storageUiSettingByKeyView } from "../projection/storageUiSettingByKeyView";
7
13
  import { fetchHttpGet, fetchHttpPost } from "./http/fetchHttpClient";
8
14
  const CHECKOUT_MESSAGING_REACT_ID = "Checkout";
9
15
  const bootstrap = ({ apiUrl, getAuthToken }) => {
@@ -17,6 +23,13 @@ const bootstrap = ({ apiUrl, getAuthToken }) => {
17
23
  view: httpIsCheckoutEnabledByCustomerIdView({ httpGet }),
18
24
  })
19
25
  .query(VIEW_IS_CHECKOUT_ACCESSIBLE_BY_CUSTOMER_ID, viewIsCheckoutAccessibleByCustomerIdHandler, {})
26
+ .query(VIEW_UI_SETTING_BY_KEY, viewUiSettingByKeyHandler, {
27
+ view: storageUiSettingByKeyView({ read }),
28
+ })
29
+ .command(UPDATE_UI_SETTING, updateUiSettingHandler, {
30
+ get: getUiSetting({ read }),
31
+ save: saveUiSetting({ write }),
32
+ })
20
33
  .build();
21
34
  };
22
35
  export { bootstrap, CHECKOUT_MESSAGING_REACT_ID };
@@ -2,8 +2,9 @@ import { useCommand } from "@lookiero/messaging-react";
2
2
  import { useCallback } from "react";
3
3
  import { v4 as uuid } from "uuid";
4
4
  import { updateUiSetting } from "../../../domain/uiSetting/command/updateUiSetting";
5
+ import { CHECKOUT_MESSAGING_REACT_ID } from "../../delivery/bootstrap";
5
6
  const useUpdateUiSetting = () => {
6
- const [commandBus, status] = useCommand();
7
+ const [commandBus, status] = useCommand({ contextId: CHECKOUT_MESSAGING_REACT_ID });
7
8
  const update = useCallback(async ({ key, value }) => await commandBus(updateUiSetting({
8
9
  aggregateId: uuid(),
9
10
  key,
@@ -7,6 +7,6 @@ const useViewUiSettingByKey = ({ key }) => useQuery({
7
7
  query: viewUiSettingByKey({ key }),
8
8
  contextId: CHECKOUT_MESSAGING_REACT_ID,
9
9
  invalidation: isUiSettingUpdated,
10
- options: { staleTime: Infinity, retry: false },
10
+ options: { staleTime: Infinity, retry: false, refetchOnWindowFocus: false },
11
11
  });
12
12
  export { useViewUiSettingByKey };
@@ -1,7 +1,9 @@
1
+ import { I18n } from "@lookiero/i18n-react";
1
2
  import { MessagingRoot } from "@lookiero/messaging-react/bootstrap";
2
3
  import { FC } from "react";
3
4
  interface RootFunctionArgs {
4
5
  readonly Messaging: MessagingRoot;
6
+ readonly I18n: I18n;
5
7
  }
6
8
  interface RootFunction {
7
9
  (args: RootFunctionArgs): FC<RootProps>;
@@ -1,17 +1,9 @@
1
- import { inMemoryFetchTranslation } from "@lookiero/i18n";
2
- import { i18n } from "@lookiero/i18n-react";
3
1
  import React, { useCallback } from "react";
4
2
  import { Platform } from "react-native";
5
3
  import { Spinner } from "./components/atoms/spinner/Spinner";
6
4
  import { Router } from "./routing/router/Router";
7
5
  import { Routing } from "./routing/Routing";
8
- const translationData = {
9
- en: { intro: "Intro view's title" },
10
- es: { intro: "Título de la vista Intro" },
11
- };
12
- const fetchTranslation = inMemoryFetchTranslation({ translationData });
13
- const I18n = i18n({ fetchTranslation, contextId: "CheckoutI18n" });
14
- const root = ({ Messaging }) =>
6
+ const root = ({ Messaging, I18n }) =>
15
7
  // eslint-disable-next-line react/display-name, react/prop-types
16
8
  ({ locale = "en", customerId, onNotAccessible }) => {
17
9
  const handleOnI18nError = useCallback(() => void 0, []);
@@ -0,0 +1,6 @@
1
+ import { FC, ReactNode } from "react";
2
+ interface BodyProps {
3
+ readonly children: ReactNode;
4
+ }
5
+ declare const Body: FC<BodyProps>;
6
+ export { Body };
@@ -0,0 +1,10 @@
1
+ import { Box } from "@lookiero/aurora-next/build/components/atoms/Box/Box";
2
+ import { Layout } from "@lookiero/aurora-next/build/components/atoms/Layout/Layout";
3
+ import React from "react";
4
+ import { style } from "./Body.style";
5
+ const Body = ({ children }) => (
6
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
7
+ // @ts-ignore
8
+ React.createElement(Layout, { style: style.layout },
9
+ React.createElement(Box, { size: { M: "2/3", L: "1/3" }, style: style.box }, children)));
10
+ export { Body };
@@ -0,0 +1,13 @@
1
+ declare const style: {
2
+ layout: {
3
+ flex: number;
4
+ justifyContent: "center";
5
+ padding: number;
6
+ textAlign: "center";
7
+ };
8
+ box: {
9
+ height: string;
10
+ justifyContent: "space-between";
11
+ };
12
+ };
13
+ export { style };
@@ -0,0 +1,16 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { theme } from "../../../theme/theme";
3
+ const { spaceXL } = theme();
4
+ const style = StyleSheet.create({
5
+ layout: {
6
+ flex: 1,
7
+ justifyContent: "center",
8
+ padding: spaceXL,
9
+ textAlign: "center",
10
+ },
11
+ box: {
12
+ height: "100%",
13
+ justifyContent: "space-between",
14
+ },
15
+ });
16
+ export { style };
@@ -0,0 +1,10 @@
1
+ declare enum I18nMessages {
2
+ INTRO_TITLE = "intro.title",
3
+ INTRO_SUBTITLE = "intro.subtitle",
4
+ INTRO_DISCOUNT = "intro.discount",
5
+ INTRO_BULLET_ONE = "intro.bullet_one",
6
+ INTRO_BULLET_TWO = "intro.bullet_two",
7
+ INTRO_BULLET_THREE = "intro.bullet_three",
8
+ INTRO_BUTTON = "intro.button"
9
+ }
10
+ export { I18nMessages };
@@ -0,0 +1,11 @@
1
+ var I18nMessages;
2
+ (function (I18nMessages) {
3
+ I18nMessages["INTRO_TITLE"] = "intro.title";
4
+ I18nMessages["INTRO_SUBTITLE"] = "intro.subtitle";
5
+ I18nMessages["INTRO_DISCOUNT"] = "intro.discount";
6
+ I18nMessages["INTRO_BULLET_ONE"] = "intro.bullet_one";
7
+ I18nMessages["INTRO_BULLET_TWO"] = "intro.bullet_two";
8
+ I18nMessages["INTRO_BULLET_THREE"] = "intro.bullet_three";
9
+ I18nMessages["INTRO_BUTTON"] = "intro.button";
10
+ })(I18nMessages || (I18nMessages = {}));
11
+ export { I18nMessages };
@@ -0,0 +1,10 @@
1
+ import { DefaultTheme } from "@lookiero/aurora-next/build/theming/theme.default";
2
+ declare type Remove$PrefixFromKeys<T> = {
3
+ [K in keyof T as K extends `$${infer F}` ? F : K]: T[K];
4
+ };
5
+ declare type AuroraTheme = Remove$PrefixFromKeys<typeof DefaultTheme>;
6
+ interface ThemeFunction {
7
+ (): AuroraTheme;
8
+ }
9
+ declare const theme: ThemeFunction;
10
+ export { theme };
@@ -0,0 +1,5 @@
1
+ import { Theme } from "@lookiero/aurora-next/build/theming/Theme";
2
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
+ // @ts-ignore
4
+ const theme = () => Theme.get();
5
+ export { theme };
@@ -1,18 +1,40 @@
1
+ import { Button } from "@lookiero/aurora-next/build/components/atoms/Button/Button";
2
+ import { Icon } from "@lookiero/aurora-next/build/components/primitives/Icon/Icon";
1
3
  import { Text } from "@lookiero/aurora-next/build/components/primitives/Text/Text";
2
4
  import { useI18nMessage } from "@lookiero/i18n-react";
3
- import React from "react";
4
- import { StyleSheet, View } from "react-native";
5
+ import { CommandStatus } from "@lookiero/messaging-react";
6
+ import React, { useCallback } from "react";
7
+ import { View } from "react-native";
8
+ import { useSetCheckoutIntroShown } from "../../../domain/react/useSetCheckoutIntroShown";
9
+ import { Body } from "../../components/layouts/body/Body";
10
+ import { I18nMessages } from "../../i18n/i18n";
11
+ import { styles } from "./Intro.style";
12
+ const Bullet = ({ text }) => (React.createElement(View, { style: styles.bullet },
13
+ React.createElement(Icon, { name: "rounded-tick", style: styles.tickIcon }),
14
+ React.createElement(Text, { detail: true, level: 2 }, text)));
5
15
  const Intro = () => {
6
- const introText = useI18nMessage({ id: "intro" });
7
- return (React.createElement(View, { style: styles.container },
8
- React.createElement(Text, { heading: true, level: 3 }, introText)));
16
+ const titleText = useI18nMessage({ id: I18nMessages.INTRO_TITLE });
17
+ const subTitleText = useI18nMessage({ id: I18nMessages.INTRO_SUBTITLE });
18
+ const discountText = useI18nMessage({ id: I18nMessages.INTRO_DISCOUNT });
19
+ const bulletOneText = useI18nMessage({ id: I18nMessages.INTRO_BULLET_ONE });
20
+ const bulletTwoText = useI18nMessage({ id: I18nMessages.INTRO_BULLET_TWO });
21
+ const bulletThreeText = useI18nMessage({ id: I18nMessages.INTRO_BULLET_THREE });
22
+ const buttonText = useI18nMessage({ id: I18nMessages.INTRO_BUTTON });
23
+ const { setCheckoutIntroShown, status: setCheckoutIntroShownStatus } = useSetCheckoutIntroShown();
24
+ const handleOnPress = useCallback(() => setCheckoutIntroShown(), [setCheckoutIntroShown]);
25
+ return (React.createElement(Body, null,
26
+ React.createElement(View, null,
27
+ React.createElement(Text, { heading: true, level: 3, style: styles.title }, titleText),
28
+ React.createElement(Text, { body: true, level: 3 }, subTitleText),
29
+ React.createElement(View, { style: styles.discountContainer },
30
+ React.createElement(View, { style: styles.discount },
31
+ React.createElement(Text, { heading: true, level: 2 }, "- 25"),
32
+ React.createElement(Text, { heading: true, level: 3, style: styles.percentage }, "%")),
33
+ React.createElement(Text, { body: true, level: 3 }, discountText)),
34
+ React.createElement(View, { style: styles.description },
35
+ React.createElement(Bullet, { text: bulletOneText }),
36
+ React.createElement(Bullet, { text: bulletTwoText }),
37
+ React.createElement(Bullet, { text: bulletThreeText }))),
38
+ React.createElement(Button, { disabled: setCheckoutIntroShownStatus === CommandStatus.LOADING, onPress: handleOnPress }, buttonText)));
9
39
  };
10
- const styles = StyleSheet.create({
11
- container: {
12
- flex: 1,
13
- backgroundColor: "#fff",
14
- alignItems: "center",
15
- justifyContent: "center",
16
- },
17
- });
18
40
  export { Intro };
@@ -0,0 +1,34 @@
1
+ declare const styles: {
2
+ title: {
3
+ marginBottom: number;
4
+ };
5
+ discountContainer: {
6
+ backgroundColor: string;
7
+ marginVertical: number;
8
+ padding: number;
9
+ width: string;
10
+ };
11
+ discount: {
12
+ alignItems: "flex-end";
13
+ flexDirection: "row";
14
+ justifyContent: "center";
15
+ marginBottom: number;
16
+ };
17
+ percentage: {
18
+ marginLeft: number;
19
+ };
20
+ description: {
21
+ borderWidth: number;
22
+ marginBottom: number;
23
+ padding: number;
24
+ width: string;
25
+ };
26
+ bullet: {
27
+ flexDirection: "row";
28
+ marginVertical: number;
29
+ };
30
+ tickIcon: {
31
+ marginRight: number;
32
+ };
33
+ };
34
+ export { styles };
@@ -0,0 +1,37 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { theme } from "../../theme/theme";
3
+ const { borderSize, colorAccent, spaceXS, spaceS, spaceM, spaceL, spaceXL } = theme();
4
+ const styles = StyleSheet.create({
5
+ title: {
6
+ marginBottom: spaceM,
7
+ },
8
+ discountContainer: {
9
+ backgroundColor: colorAccent,
10
+ marginVertical: spaceL,
11
+ padding: spaceM,
12
+ width: "100%",
13
+ },
14
+ discount: {
15
+ alignItems: "flex-end",
16
+ flexDirection: "row",
17
+ justifyContent: "center",
18
+ marginBottom: spaceS,
19
+ },
20
+ percentage: {
21
+ marginLeft: spaceXS,
22
+ },
23
+ description: {
24
+ borderWidth: borderSize,
25
+ marginBottom: spaceXL,
26
+ padding: spaceM,
27
+ width: "100%",
28
+ },
29
+ bullet: {
30
+ flexDirection: "row",
31
+ marginVertical: spaceS,
32
+ },
33
+ tickIcon: {
34
+ marginRight: spaceS,
35
+ },
36
+ });
37
+ export { styles };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lookiero/checkout",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -18,12 +18,11 @@
18
18
  "lint": "eslint --fix --cache --cache-location ./node_modules/.cache/.eslintcache --ext ts,tsx .",
19
19
  "format": "prettier --write \"**/*.+(json|css|ts|tsx|md)\"",
20
20
  "test": "jest",
21
- "test:coverage": "jest --coverage --coverageReporters=text --detectOpenHandles --forceExit --silent",
22
- "publish": "npm publish"
21
+ "test:coverage": "jest --coverage --coverageReporters=text --detectOpenHandles --forceExit --silent"
23
22
  },
24
23
  "dependencies": {
25
- "@lookiero/i18n": "^0.7.0",
26
- "@lookiero/i18n-react": "^0.7.0",
24
+ "@lookiero/i18n": "^0.7.2",
25
+ "@lookiero/i18n-react": "^0.7.2",
27
26
  "@lookiero/messaging": "^6.2.1",
28
27
  "@lookiero/messaging-react": "^6.2.1",
29
28
  "react-router-dom": "^6.3.0",