@lookiero/checkout 0.2.52 → 0.3.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.
Files changed (32) hide show
  1. package/README.md +15 -0
  2. package/dist/domain/checkoutItem/model/checkoutItem.js +4 -4
  3. package/dist/infrastructure/delivery/mock/dataSourceCheckoutBookings.js +2 -3
  4. package/dist/infrastructure/delivery/mock/dataSourceCheckoutItems.js +2 -2
  5. package/dist/infrastructure/domain/checkoutBooking/react/useBookCheckouBookingForCheckoutItem.d.ts +0 -1
  6. package/dist/infrastructure/domain/checkoutBooking/react/useBookCheckouBookingForCheckoutItem.js +3 -3
  7. package/dist/infrastructure/domain/checkoutItem/model/httpCheckoutItems.js +1 -1
  8. package/dist/infrastructure/projection/bookedSizeChangeProductsVariants/react/useViewBookedSizeChangeProductsVariantsForCheckoutItem.js +3 -0
  9. package/dist/infrastructure/projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId.js +4 -1
  10. package/dist/infrastructure/ui/Root.d.ts +1 -0
  11. package/dist/infrastructure/ui/Root.js +2 -4
  12. package/dist/infrastructure/ui/components/organisms/returnQuestions/behaviors/useReturnQuestionFeedback.js +2 -1
  13. package/dist/infrastructure/ui/routing/CheckoutAccessibilityMiddleware.d.ts +1 -0
  14. package/dist/infrastructure/ui/routing/CheckoutAccessibilityMiddleware.js +6 -3
  15. package/dist/infrastructure/ui/routing/CheckoutMiddleware.d.ts +2 -0
  16. package/dist/infrastructure/ui/routing/CheckoutMiddleware.js +10 -10
  17. package/dist/infrastructure/ui/routing/Routing.d.ts +1 -0
  18. package/dist/infrastructure/ui/routing/Routing.js +24 -39
  19. package/dist/infrastructure/ui/routing/routes.d.ts +4 -4
  20. package/dist/infrastructure/ui/routing/routes.js +4 -4
  21. package/dist/infrastructure/ui/views/App.d.ts +4 -1
  22. package/dist/infrastructure/ui/views/App.js +2 -4
  23. package/dist/infrastructure/ui/views/item/Item.js +21 -13
  24. package/dist/infrastructure/ui/views/item/components/itemActions/ItemActions.d.ts +1 -2
  25. package/dist/infrastructure/ui/views/item/components/itemActions/ItemActions.js +1 -3
  26. package/dist/infrastructure/ui/views/item/components/returnQuestionsFeedback/ReturnQuestionsFeedback.d.ts +0 -2
  27. package/dist/infrastructure/ui/views/item/components/returnQuestionsFeedback/ReturnQuestionsFeedback.js +4 -6
  28. package/dist/infrastructure/ui/views/item/components/returnQuestionsForm/ReturnQuestionsForm.d.ts +0 -1
  29. package/dist/infrastructure/ui/views/item/components/returnQuestionsForm/ReturnQuestionsForm.js +10 -10
  30. package/dist/projection/bookedSizeChangeProductsVariants/bookedSizeChangeProductsVariants.d.ts +1 -4
  31. package/dist/projection/checkoutItem/checkoutItem.d.ts +1 -1
  32. package/package.json +2 -2
package/README.md CHANGED
@@ -33,3 +33,18 @@ Once we can replace the build of Jenkins for NPM one, we are going to be able to
33
33
  }
34
34
  }
35
35
  ```
36
+
37
+ We are hiding the node compatibility deprecation warnings in order to obtain a success message from
38
+ the terminal. Remove it once we drop Yarn compatibility.
39
+
40
+ ```json
41
+ {
42
+ (...)
43
+ "scripts": {
44
+ (...)
45
+ "build:app": "tsc -p ./tsconfig.build-app.json --noemit && ENTRY_POINT='./src/Expo.tsx' NODE_ENV=production expo export:web --clear 2> /dev/null"
46
+ (...)
47
+ }
48
+ (...)
49
+ }
50
+ ```
@@ -20,19 +20,19 @@ const keepCheckoutItemHandler = () => async ({ aggregateRoot, command }) => {
20
20
  };
21
21
  };
22
22
  const returnCheckoutItemHandler = () => async ({ aggregateRoot, command }) => {
23
- const { aggregateId } = command;
24
- invariant(aggregateRoot.status !== CheckoutItemStatus.RETURNED, "CheckoutItem is already returned");
23
+ const { aggregateId, feedbacks } = command;
25
24
  return {
26
25
  ...aggregateRoot,
26
+ feedbacks,
27
27
  status: CheckoutItemStatus.RETURNED,
28
28
  domainEvents: [checkoutItemReturned({ aggregateId })],
29
29
  };
30
30
  };
31
31
  const replaceCheckoutItemHandler = () => async ({ aggregateRoot, command }) => {
32
- const { aggregateId } = command;
33
- invariant(aggregateRoot.status !== CheckoutItemStatus.REPLACED, "CheckoutItem is already replaced");
32
+ const { aggregateId, replacedFor } = command;
34
33
  return {
35
34
  ...aggregateRoot,
35
+ replacedFor,
36
36
  status: CheckoutItemStatus.REPLACED,
37
37
  domainEvents: [checkoutItemReplaced({ aggregateId })],
38
38
  };
@@ -3,9 +3,8 @@ import { viewBookedSizeChangeProductsVariantsForCheckoutItem, } from "../../../p
3
3
  const toCheckoutBookingDomain = (checkoutBooking) => {
4
4
  invariant(checkoutBooking, "No checkoutBooking found!");
5
5
  return {
6
- aggregateId: checkoutBooking.id,
7
- checkoutId: checkoutBooking.checkoutId,
8
- checkoutItemIds: [checkoutBooking.checkoutItemId],
6
+ aggregateId: checkoutBooking.bookingId,
7
+ checkoutItemIds: checkoutBooking.productVariants.map((productVariant) => productVariant.id),
9
8
  domainEvents: [],
10
9
  };
11
10
  };
@@ -4,7 +4,7 @@ const toCheckoutItemProjection = (checkoutItem) => ({
4
4
  id: checkoutItem.aggregateId,
5
5
  status: checkoutItem.status,
6
6
  productVariant: {},
7
- feedback: {},
7
+ feedbacks: {},
8
8
  price: checkoutItem.price,
9
9
  });
10
10
  const toCheckoutItemDomain = (checkoutItem) => {
@@ -14,7 +14,7 @@ const toCheckoutItemDomain = (checkoutItem) => {
14
14
  id: checkoutItem.id,
15
15
  status: checkoutItem.status,
16
16
  price: checkoutItem.price,
17
- feedbacks: checkoutItem.feedback,
17
+ feedbacks: checkoutItem.feedbacks,
18
18
  domainEvents: [],
19
19
  };
20
20
  };
@@ -5,7 +5,6 @@ interface BookFunction {
5
5
  declare type UseBookCheckouBookingForCheckoutItem = [book: BookFunction, status: CommandStatus];
6
6
  interface UseBookCheckouBookingForCheckoutItemFunctionArgs {
7
7
  readonly checkoutItemId: string;
8
- readonly checkoutBookingId: string | undefined;
9
8
  }
10
9
  interface UseBookCheckouBookingForCheckoutItemFunction {
11
10
  (args: UseBookCheckouBookingForCheckoutItemFunctionArgs): UseBookCheckouBookingForCheckoutItem;
@@ -3,12 +3,12 @@ import { useCallback } from "react";
3
3
  import { v4 as uuid } from "uuid";
4
4
  import { bookCheckoutBookingForCheckoutItem } from "../../../../domain/checkoutBooking/command/bookCheckoutBookingForCheckoutItem";
5
5
  import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
6
- const useBookCheckouBookingForCheckoutItem = ({ checkoutItemId, checkoutBookingId, }) => {
6
+ const useBookCheckouBookingForCheckoutItem = ({ checkoutItemId }) => {
7
7
  const [commandBus, status] = useCommand({ contextId: MESSAGING_CONTEXT_ID });
8
8
  const book = useCallback(() => commandBus(bookCheckoutBookingForCheckoutItem({
9
- aggregateId: checkoutBookingId || uuid(),
9
+ aggregateId: uuid(),
10
10
  checkoutItemId,
11
- })), [checkoutBookingId, checkoutItemId, commandBus]);
11
+ })), [checkoutItemId, commandBus]);
12
12
  return [book, status];
13
13
  };
14
14
  export { useBookCheckouBookingForCheckoutItem };
@@ -9,7 +9,7 @@ const toDomain = (checkoutItem) => {
9
9
  id: checkoutItem.id,
10
10
  status: checkoutItem.status,
11
11
  price: checkoutItem.price,
12
- feedbacks: checkoutItem.feedback,
12
+ feedbacks: checkoutItem.feedbacks,
13
13
  replacedFor: checkoutItem.replacedFor,
14
14
  aggregateId: checkoutItem.id,
15
15
  domainEvents: [],
@@ -1,9 +1,12 @@
1
1
  import { useQuery } from "@lookiero/messaging-react";
2
+ import { CHECKOUT_BOOKING_BOOKED, } from "../../../../domain/checkoutBooking/model/checkoutBookingBooked";
2
3
  import { viewBookedSizeChangeProductsVariantsForCheckoutItem } from "../../../../projection/bookedSizeChangeProductsVariants/viewBookedSizeChangeProductVariantsForCheckoutItem";
3
4
  import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
5
+ const isCheckoutBookingBooked = (event) => event.name === CHECKOUT_BOOKING_BOOKED;
4
6
  const useViewBookedSizeChangeProductsVariantsForCheckoutItem = ({ checkoutItemId }) => useQuery({
5
7
  query: viewBookedSizeChangeProductsVariantsForCheckoutItem({ checkoutItemId }),
6
8
  contextId: MESSAGING_CONTEXT_ID,
9
+ invalidation: isCheckoutBookingBooked,
7
10
  options: { staleTime: Infinity, retry: false, refetchOnWindowFocus: false },
8
11
  });
9
12
  export { useViewBookedSizeChangeProductsVariantsForCheckoutItem };
@@ -1,14 +1,17 @@
1
1
  import { useQuery } from "@lookiero/messaging-react";
2
2
  import { CHECKOUT_ITEM_KEPT } from "../../../../domain/checkoutItem/model/checkoutItemKept";
3
+ import { CHECKOUT_ITEM_REPLACED, } from "../../../../domain/checkoutItem/model/checkoutItemReplaced";
3
4
  import { CHECKOUT_ITEM_RETURNED, } from "../../../../domain/checkoutItem/model/checkoutItemReturned";
4
5
  import { viewFirstAvailableCheckoutByCustomerId } from "../../../../projection/checkout/viewFirstAvailableCheckoutByCustomerId";
5
6
  import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
6
7
  const isCheckoutItemKept = (event) => event.name === CHECKOUT_ITEM_KEPT;
7
8
  const isCheckoutItemReturned = (event) => event.name === CHECKOUT_ITEM_RETURNED;
9
+ const isCheckoutItemReplaced = (event) => event.name === CHECKOUT_ITEM_REPLACED;
10
+ const shouldInvalidate = (event) => isCheckoutItemKept(event) || isCheckoutItemReplaced(event) || isCheckoutItemReturned(event);
8
11
  const useViewFirstAvailableCheckoutByCustomerId = ({ customerId }) => useQuery({
9
12
  query: viewFirstAvailableCheckoutByCustomerId({ customerId }),
10
13
  contextId: MESSAGING_CONTEXT_ID,
11
- invalidation: isCheckoutItemKept || isCheckoutItemReturned,
14
+ invalidation: shouldInvalidate,
12
15
  options: { staleTime: Infinity, retry: false, refetchOnWindowFocus: false },
13
16
  });
14
17
  export { useViewFirstAvailableCheckoutByCustomerId };
@@ -10,6 +10,7 @@ interface RootFunction {
10
10
  (args: RootFunctionArgs): FC<RootProps>;
11
11
  }
12
12
  interface RootProps {
13
+ readonly basePath: string;
13
14
  readonly locale?: string;
14
15
  readonly customerId: string | undefined;
15
16
  readonly onNotAccessible: () => void;
@@ -1,13 +1,11 @@
1
1
  import React, { useCallback } from "react";
2
2
  import { Platform } from "react-native";
3
3
  import { Routing } from "./routing/Routing";
4
- import { Router } from "./routing/router/Router";
5
4
  const root = ({ Messaging, I18n, development }) =>
6
5
  // eslint-disable-next-line react/display-name, react/prop-types
7
- ({ locale = "en", customerId, onNotAccessible }) => {
6
+ ({ basePath, locale = "en", customerId, onNotAccessible }) => {
8
7
  const handleOnI18nError = useCallback(() => void 0, []);
9
8
  return (React.createElement(Messaging, { includeReactQueryDevTools: Platform.OS === "web" },
10
- React.createElement(Router, null,
11
- React.createElement(Routing, { I18n: I18n, customerId: customerId, locale: locale, onI18nError: development ? undefined : handleOnI18nError, onNotAccessible: onNotAccessible }))));
9
+ React.createElement(Routing, { I18n: I18n, basePath: basePath, customerId: customerId, locale: locale, onI18nError: development ? undefined : handleOnI18nError, onNotAccessible: onNotAccessible })));
12
10
  };
13
11
  export { root };
@@ -1,4 +1,4 @@
1
- import React, { createContext, useCallback, useContext, useMemo, useState } from "react";
1
+ import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
2
2
  import invariant from "tiny-invariant";
3
3
  const ReturnQuestionFeedbackContext = createContext(null);
4
4
  const ReturnQuestionFeedbackProvider = ({ feedback = {}, children, }) => {
@@ -6,6 +6,7 @@ const ReturnQuestionFeedbackProvider = ({ feedback = {}, children, }) => {
6
6
  const onChange = useCallback(({ returnQuestionId, returnQuestionFeedback }) => setContextFeedback((feedback) => returnQuestionFeedback
7
7
  ? { ...feedback, [returnQuestionId]: returnQuestionFeedback }
8
8
  : Object.entries(feedback).reduce((acc, [id, feedback]) => (id !== returnQuestionId ? { ...acc, [id]: feedback } : acc), {})), []);
9
+ useEffect(() => setContextFeedback(feedback), [feedback]);
9
10
  const value = useMemo(() => ({
10
11
  feedback: contextFeedback,
11
12
  onChange,
@@ -3,6 +3,7 @@ interface CheckoutAccessibilityMiddlewareProps {
3
3
  readonly customerId: string | undefined;
4
4
  readonly onNotAccessible: () => void;
5
5
  readonly loader?: JSX.Element;
6
+ readonly children: JSX.Element;
6
7
  }
7
8
  declare const CheckoutAccessibilityMiddleware: FC<CheckoutAccessibilityMiddlewareProps>;
8
9
  export { CheckoutAccessibilityMiddleware };
@@ -1,9 +1,8 @@
1
1
  import { QueryStatus } from "@lookiero/messaging-react";
2
2
  import React, { useEffect, useRef } from "react";
3
- import { Outlet } from "react-router-native";
4
3
  import { useViewIsCheckoutAccessibleByCustomerId } from "../../projection/checkout/react/useViewIsCheckoutAccessibleByCustomerId";
5
4
  import { Spinner } from "../shared/components/atoms/spinner/Spinner";
6
- const CheckoutAccessibilityMiddleware = ({ customerId, onNotAccessible, loader = React.createElement(Spinner, null), }) => {
5
+ const CheckoutAccessibilityMiddleware = ({ customerId, onNotAccessible, loader = React.createElement(Spinner, null), children, }) => {
7
6
  const [accessible, status] = useViewIsCheckoutAccessibleByCustomerId({ customerId });
8
7
  const onNotAccessibleRef = useRef(onNotAccessible);
9
8
  onNotAccessibleRef.current = onNotAccessible;
@@ -13,6 +12,10 @@ const CheckoutAccessibilityMiddleware = ({ customerId, onNotAccessible, loader =
13
12
  onNotAccessibleRef.current();
14
13
  }
15
14
  }, [notAccessible, onNotAccessible]);
16
- return accessible === undefined && [QueryStatus.IDLE, QueryStatus.LOADING].includes(status) ? (loader) : accessible ? (React.createElement(Outlet, null)) : null;
15
+ return accessible === undefined && [QueryStatus.IDLE, QueryStatus.LOADING].includes(status)
16
+ ? loader
17
+ : accessible
18
+ ? children
19
+ : null;
17
20
  };
18
21
  export { CheckoutAccessibilityMiddleware };
@@ -1,7 +1,9 @@
1
1
  import { FC } from "react";
2
2
  interface CheckoutMiddlewareProps {
3
+ readonly basePath: string;
3
4
  readonly customerId: string;
4
5
  readonly loader?: JSX.Element;
6
+ readonly children: JSX.Element;
5
7
  }
6
8
  declare const CheckoutMiddleware: FC<CheckoutMiddlewareProps>;
7
9
  export { CheckoutMiddleware };
@@ -1,19 +1,19 @@
1
1
  import { QueryStatus } from "@lookiero/messaging-react";
2
2
  import React, { useRef } from "react";
3
- import { generatePath, Navigate, Outlet, useMatch } from "react-router-native";
3
+ import { generatePath, Navigate, useMatch } from "react-router-native";
4
4
  import { CheckoutItemStatus } from "../../../domain/checkoutItem/model/checkoutItem";
5
5
  import { useViewFirstAvailableCheckoutByCustomerId } from "../../projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId";
6
6
  import { useShouldIntroBeShown } from "../../projection/uiSetting/react/useShouldIntroBeShown";
7
7
  import { Spinner } from "../shared/components/atoms/spinner/Spinner";
8
8
  import { Routes } from "./routes";
9
- const CheckoutMiddleware = ({ customerId, loader = React.createElement(Spinner, null) }) => {
9
+ const CheckoutMiddleware = ({ basePath, customerId, loader = React.createElement(Spinner, null), children }) => {
10
10
  const introShown = useRef(false);
11
11
  const [shouldIntroBeShown, shouldIntroBeShownStatus] = useShouldIntroBeShown();
12
12
  const [checkout, checkoutStatus] = useViewFirstAvailableCheckoutByCustomerId({ customerId });
13
13
  const firstItemWithoutCustomerDecision = checkout?.items.find((item) => [CheckoutItemStatus.EXPIRED, CheckoutItemStatus.INITIAL].includes(item.status));
14
- const introRouteMatch = useMatch(Routes.INTRO);
15
- const itemRouteMatch = useMatch(Routes.ITEM);
16
- const summaryRouteMatch = useMatch(Routes.SUMMARY);
14
+ const introRouteMatch = useMatch(`${basePath}/${Routes.INTRO}`);
15
+ const itemRouteMatch = useMatch(`${basePath}/${Routes.ITEM}`);
16
+ const summaryRouteMatch = useMatch(`${basePath}/${Routes.SUMMARY}`);
17
17
  const dependenciesLoadedStatuses = [QueryStatus.ERROR, QueryStatus.SUCCESS];
18
18
  const dependenciesLoaded = dependenciesLoadedStatuses.includes(shouldIntroBeShownStatus) &&
19
19
  dependenciesLoadedStatuses.includes(checkoutStatus);
@@ -25,23 +25,23 @@ const CheckoutMiddleware = ({ customerId, loader = React.createElement(Spinner,
25
25
  introShown.current = true;
26
26
  }
27
27
  else {
28
- return React.createElement(Navigate, { to: Routes.INTRO, replace: true });
28
+ return React.createElement(Navigate, { to: `${basePath}/${Routes.INTRO}`, replace: true });
29
29
  }
30
30
  }
31
31
  else {
32
32
  if (itemRouteMatch) {
33
33
  const checkoutItem = checkout?.items.find((item) => item.id === itemRouteMatch.params.id);
34
34
  if (!checkoutItem) {
35
- return React.createElement(Navigate, { to: Routes.CHECKOUT, replace: true });
35
+ return React.createElement(Navigate, { to: `${basePath}/${Routes.HOME}`, replace: true });
36
36
  }
37
37
  }
38
38
  if (firstItemWithoutCustomerDecision && !itemRouteMatch) {
39
- return React.createElement(Navigate, { to: generatePath(Routes.ITEM, { id: firstItemWithoutCustomerDecision.id }), replace: true });
39
+ return (React.createElement(Navigate, { to: generatePath(`${basePath}/${Routes.ITEM}`, { id: firstItemWithoutCustomerDecision.id }), replace: true }));
40
40
  }
41
41
  if (firstItemWithoutCustomerDecision === undefined && !summaryRouteMatch) {
42
- return React.createElement(Navigate, { to: Routes.SUMMARY, replace: true });
42
+ return React.createElement(Navigate, { to: `${basePath}/${Routes.SUMMARY}`, replace: true });
43
43
  }
44
44
  }
45
- return React.createElement(Outlet, null);
45
+ return children;
46
46
  };
47
47
  export { CheckoutMiddleware };
@@ -5,6 +5,7 @@ interface RoutingProps {
5
5
  readonly customerId: string | undefined;
6
6
  readonly locale: string;
7
7
  readonly I18n: I18n;
8
+ readonly basePath?: string;
8
9
  readonly onI18nError?: (err: Error) => void;
9
10
  }
10
11
  declare const Routing: FC<RoutingProps>;
@@ -8,52 +8,37 @@ import { Routes } from "./routes";
8
8
  const Intro = lazy(() => import("../views/intro/Intro").then((module) => ({ default: module.Intro })));
9
9
  const Item = lazy(() => import("../views/item/Item").then((module) => ({ default: module.Item })));
10
10
  const Summary = lazy(() => import("../views/summary/Summary").then((module) => ({ default: module.Summary })));
11
- const Routing = ({ onNotAccessible, customerId, locale, I18n, onI18nError }) => {
11
+ const Routing = ({ basePath = "", onNotAccessible, customerId, locale, I18n, onI18nError }) => {
12
12
  const routes = useRoutes([
13
13
  {
14
- path: Routes.CHECKOUT,
15
- element: React.createElement(CheckoutAccessibilityMiddleware, { customerId: customerId, onNotAccessible: onNotAccessible }),
14
+ path: "",
15
+ element: (React.createElement(CheckoutAccessibilityMiddleware, { customerId: customerId, onNotAccessible: onNotAccessible },
16
+ React.createElement(I18n, { loader: React.createElement(Spinner, null), locale: locale, onError: onI18nError },
17
+ React.createElement(CheckoutMiddleware, { basePath: basePath, customerId: customerId },
18
+ React.createElement(App, null,
19
+ React.createElement(Outlet, null)))))),
16
20
  children: [
17
21
  {
18
- path: "",
19
- element: (React.createElement(I18n, { loader: React.createElement(Spinner, null), locale: locale, onError: onI18nError },
20
- React.createElement(Outlet, null))),
21
- children: [
22
- {
23
- path: "",
24
- element: React.createElement(CheckoutMiddleware, { customerId: customerId }),
25
- children: [
26
- {
27
- path: "",
28
- element: React.createElement(App, null),
29
- children: [
30
- {
31
- path: Routes.INTRO,
32
- element: (React.createElement(Suspense, { fallback: React.createElement(Spinner, null) },
33
- React.createElement(Intro, { customerId: customerId }))),
34
- },
35
- {
36
- path: Routes.ITEM,
37
- element: (React.createElement(Suspense, { fallback: React.createElement(Spinner, null) },
38
- React.createElement(Item, { customerId: customerId }))),
39
- },
40
- {
41
- path: Routes.SUMMARY,
42
- element: (React.createElement(Suspense, { fallback: React.createElement(Spinner, null) },
43
- React.createElement(Summary, { customerId: customerId }))),
44
- },
45
- ],
46
- },
47
- ],
48
- },
49
- ],
22
+ path: Routes.INTRO,
23
+ element: (React.createElement(Suspense, { fallback: React.createElement(Spinner, null) },
24
+ React.createElement(Intro, { customerId: customerId }))),
25
+ },
26
+ {
27
+ path: Routes.ITEM,
28
+ element: (React.createElement(Suspense, { fallback: React.createElement(Spinner, null) },
29
+ React.createElement(Item, { customerId: customerId }))),
30
+ },
31
+ {
32
+ path: Routes.SUMMARY,
33
+ element: (React.createElement(Suspense, { fallback: React.createElement(Spinner, null) },
34
+ React.createElement(Summary, { customerId: customerId }))),
35
+ },
36
+ {
37
+ path: "*",
38
+ element: React.createElement(Navigate, { to: `${Routes.HOME}`, replace: true }),
50
39
  },
51
40
  ],
52
41
  },
53
- {
54
- path: "*",
55
- element: React.createElement(Navigate, { to: Routes.CHECKOUT, replace: true }),
56
- },
57
42
  ]);
58
43
  return routes;
59
44
  };
@@ -1,6 +1,6 @@
1
1
  export declare enum Routes {
2
- CHECKOUT = "/checkout",
3
- INTRO = "/checkout/intro",
4
- ITEM = "/checkout/item/:id",
5
- SUMMARY = "/checkout/summary"
2
+ HOME = "",
3
+ INTRO = "intro",
4
+ ITEM = "item/:id",
5
+ SUMMARY = "summary"
6
6
  }
@@ -1,7 +1,7 @@
1
1
  export var Routes;
2
2
  (function (Routes) {
3
- Routes["CHECKOUT"] = "/checkout";
4
- Routes["INTRO"] = "/checkout/intro";
5
- Routes["ITEM"] = "/checkout/item/:id";
6
- Routes["SUMMARY"] = "/checkout/summary";
3
+ Routes["HOME"] = "";
4
+ Routes["INTRO"] = "intro";
5
+ Routes["ITEM"] = "item/:id";
6
+ Routes["SUMMARY"] = "summary";
7
7
  })(Routes || (Routes = {}));
@@ -1,3 +1,6 @@
1
1
  import { FC } from "react";
2
- declare const App: FC;
2
+ interface AppProps {
3
+ readonly children: JSX.Element;
4
+ }
5
+ declare const App: FC<AppProps>;
3
6
  export { App };
@@ -1,8 +1,6 @@
1
1
  import { PortalProvider } from "@gorhom/portal";
2
2
  import React from "react";
3
3
  import { SafeAreaProvider } from "react-native-safe-area-context";
4
- import { Outlet } from "react-router-native";
5
- const App = () => (React.createElement(SafeAreaProvider, null,
6
- React.createElement(PortalProvider, null,
7
- React.createElement(Outlet, null))));
4
+ const App = ({ children }) => (React.createElement(SafeAreaProvider, null,
5
+ React.createElement(PortalProvider, null, children)));
8
6
  export { App };
@@ -1,5 +1,5 @@
1
1
  import { CommandStatus, QueryStatus } from "@lookiero/messaging-react";
2
- import React, { useCallback, useEffect, useState } from "react";
2
+ import React, { useCallback, useEffect, useMemo, useState } from "react";
3
3
  import { View } from "react-native";
4
4
  import { useParams } from "react-router-native";
5
5
  import { CheckoutItemStatus } from "../../../../domain/checkoutItem/model/checkoutItem";
@@ -12,6 +12,7 @@ import { useViewBookedSizeChangeProductsVariantsForCheckoutItem } from "../../..
12
12
  import { useViewFirstAvailableCheckoutByCustomerId } from "../../../projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId";
13
13
  import { useListReturnQuestionsByCheckoutItemId } from "../../../projection/returnQuestion/react/useListReturnQuestionsByCheckoutItemId";
14
14
  import { Body } from "../../components/layouts/body/Body";
15
+ import { ReturnQuestionFeedbackProvider } from "../../components/organisms/returnQuestions/behaviors/useReturnQuestionFeedback";
15
16
  import { SafeAreaScrollView } from "../../components/templates/SafeAreaScrollView";
16
17
  import { Spinner } from "../../shared/components/atoms/spinner/Spinner";
17
18
  import { style } from "./Item.style";
@@ -39,7 +40,6 @@ const Item = ({ customerId }) => {
39
40
  checkoutItemId: checkoutItem.id,
40
41
  });
41
42
  const [bookCheckouBooking] = useBookCheckouBookingForCheckoutItem({
42
- checkoutBookingId: bookedSizeChangeProductsVariants?.id,
43
43
  checkoutItemId: checkoutItem.id,
44
44
  });
45
45
  const [returnQuestions, returnQuestionsStatus] = useListReturnQuestionsByCheckoutItemId({
@@ -55,21 +55,29 @@ const Item = ({ customerId }) => {
55
55
  const [stickyHeight, setStickyHeight] = useState(0);
56
56
  const handleOnStickyLayout = useCallback(({ height }) => setStickyHeight(height), []);
57
57
  useEffect(() => {
58
- checkout?.bookingId === undefined && bookCheckouBooking();
59
- }, [bookCheckouBooking, checkout?.bookingId]);
58
+ bookedSizeChangeProductsVariants === null && bookCheckouBooking();
59
+ }, [bookCheckouBooking, bookedSizeChangeProductsVariants, bookedSizeChangeProductsVariants?.bookingId]);
60
60
  const [returnQuestionsVisible, setReturnQuestionsVisible] = useState(false);
61
61
  const handleOnShowReturnQuestions = useCallback(() => setReturnQuestionsVisible(true), []);
62
62
  const handleOnHideReturnQuestions = useCallback(() => setReturnQuestionsVisible(false), []);
63
63
  const handleOnEditFeedback = useCallback(() => handleOnShowReturnQuestions(), [handleOnShowReturnQuestions]);
64
- const handleOnSubmit = useCallback((feedback) => {
64
+ const handleOnSubmit = useCallback((feedbacks) => {
65
65
  handleOnHideReturnQuestions();
66
- returnCheckoutItem({ feedbacks: feedback });
66
+ returnCheckoutItem({ feedbacks });
67
67
  }, [handleOnHideReturnQuestions, returnCheckoutItem]);
68
68
  const handleOnReplace = useCallback((replacedFor) => {
69
69
  handleOnShowSizeChangeModal();
70
70
  replaceCheckoutItem({ replacedFor });
71
71
  }, [handleOnShowSizeChangeModal, replaceCheckoutItem]);
72
72
  const handleOnReturn = useCallback(() => handleOnShowReturnQuestions(), [handleOnShowReturnQuestions]);
73
+ const productVariantSelected = useMemo(() => checkoutItem.replacedFor
74
+ ? bookedSizeChangeProductsVariants?.productVariants.find((productVariant) => productVariant.id === checkoutItem.replacedFor)
75
+ : { id: checkoutItem.productVariant.id, size: checkoutItem.productVariant.size }, [
76
+ bookedSizeChangeProductsVariants?.productVariants,
77
+ checkoutItem.productVariant.id,
78
+ checkoutItem.productVariant.size,
79
+ checkoutItem.replacedFor,
80
+ ]);
73
81
  const dependenciesLoadedStatuses = [QueryStatus.ERROR, QueryStatus.SUCCESS];
74
82
  const dependenciesLoaded = dependenciesLoadedStatuses.includes(returnQuestionsStatus) &&
75
83
  dependenciesLoadedStatuses.includes(checkoutStatus) &&
@@ -77,8 +85,8 @@ const Item = ({ customerId }) => {
77
85
  if (!dependenciesLoaded)
78
86
  return React.createElement(Spinner, null);
79
87
  const { price } = checkoutItem;
80
- const { media, brand, name, size, color } = checkoutItem.productVariant;
81
- return (React.createElement(React.Fragment, null,
88
+ const { media, brand, name, color } = checkoutItem.productVariant;
89
+ return (React.createElement(ReturnQuestionFeedbackProvider, { feedback: checkoutItem.feedbacks || {} },
82
90
  React.createElement(SizeWithoutStockModal, { visible: sizeWithoutStockModalVisible, onDismiss: handleOnHideSizeWithoutStockModal }),
83
91
  React.createElement(SizeChangeModal, { visible: sizeChangeModalVisible, onDismiss: handleOnHideSizeChangeModal }),
84
92
  React.createElement(SafeAreaScrollView, null,
@@ -87,10 +95,10 @@ const Item = ({ customerId }) => {
87
95
  React.createElement(View, { style: [style.container, { paddingBottom: stickyHeight }] },
88
96
  React.createElement(View, { style: style.sliderContainer },
89
97
  React.createElement(ProductVariantSlider, { producVariantMedia: media })),
90
- React.createElement(ProductVariantDescription, { brand: brand, color: color, name: name, price: price, size: size }),
91
- checkoutItem.feedback && (React.createElement(View, { style: style.feedbackContainer },
92
- React.createElement(ReturnQuestionsFeedback, { feedback: checkoutItem.feedback || {}, returnQuestions: returnQuestions || [], onEditFeedback: handleOnEditFeedback })))))),
93
- customerDecissionMade && (React.createElement(ItemActions, { keepButtonLoading: keepCheckoutItemStatus === CommandStatus.LOADING, productVariantSelected: checkoutItem.productVariant, productVariants: bookedSizeChangeProductsVariants?.productVariants || [], returnButtonLoading: returnCheckoutItemStatus === CommandStatus.LOADING, sizeSelectorDisabled: replaceCheckoutItemStatus === CommandStatus.LOADING, onKeep: keepCheckoutItem, onLayout: handleOnStickyLayout, onReplace: handleOnReplace, onReturn: handleOnReturn, onSizeSelectorPress: handleOnShowSizeWithoutStockModal })),
94
- React.createElement(ReturnQuestionsForm, { checkoutItemPrice: checkoutItem.price, feedback: checkoutItem.feedback || {}, productVariant: checkoutItem.productVariant, returnQuestions: returnQuestions || [], visible: returnQuestionsVisible, onClose: handleOnHideReturnQuestions, onSubmit: handleOnSubmit })));
98
+ React.createElement(ProductVariantDescription, { brand: brand, color: color, name: name, price: price, size: productVariantSelected.size }),
99
+ checkoutItem.status === CheckoutItemStatus.RETURNED && (React.createElement(View, { style: style.feedbackContainer },
100
+ React.createElement(ReturnQuestionsFeedback, { returnQuestions: returnQuestions || [], onEditFeedback: handleOnEditFeedback })))))),
101
+ customerDecissionMade && (React.createElement(ItemActions, { keepButtonLoading: keepCheckoutItemStatus === CommandStatus.LOADING, productVariantSelected: productVariantSelected, productVariants: bookedSizeChangeProductsVariants?.productVariants || [], returnButtonLoading: returnCheckoutItemStatus === CommandStatus.LOADING, sizeSelectorDisabled: replaceCheckoutItemStatus === CommandStatus.LOADING, onKeep: keepCheckoutItem, onLayout: handleOnStickyLayout, onReplace: handleOnReplace, onReturn: handleOnReturn, onSizeSelectorPress: handleOnShowSizeWithoutStockModal })),
102
+ React.createElement(ReturnQuestionsForm, { checkoutItemPrice: checkoutItem.price, productVariant: checkoutItem.productVariant, returnQuestions: returnQuestions || [], visible: returnQuestionsVisible, onClose: handleOnHideReturnQuestions, onSubmit: handleOnSubmit })));
95
103
  };
96
104
  export { Item };
@@ -1,10 +1,9 @@
1
1
  import { FC } from "react";
2
2
  import { ProductVariantProjection } from "../../../../../../projection/bookedSizeChangeProductsVariants/bookedSizeChangeProductsVariants";
3
- import { CheckoutItemProductVariantProjection } from "../../../../../../projection/checkoutItem/checkoutItem";
4
3
  import { Layout } from "../../../../shared/components/layouts/sticky/Sticky";
5
4
  interface ItemActionsProps {
6
5
  readonly productVariants: ProductVariantProjection[];
7
- readonly productVariantSelected: CheckoutItemProductVariantProjection;
6
+ readonly productVariantSelected: ProductVariantProjection;
8
7
  readonly keepButtonLoading?: boolean;
9
8
  readonly returnButtonLoading?: boolean;
10
9
  readonly sizeSelectorDisabled?: boolean;
@@ -12,9 +12,7 @@ const ItemActions = ({ productVariants, productVariantSelected, keepButtonLoadin
12
12
  const sizeSelectorLabelText = useI18nMessage({ id: I18nMessages.ITEM_SIZES_LABEL });
13
13
  const keepButtonText = useI18nMessage({ id: I18nMessages.ITEM_KEEP_BUTTON });
14
14
  const returnButtonText = useI18nMessage({ id: I18nMessages.ITEM_RETURN_BUTTON });
15
- const sizeSelectorOptions = useMemo(() => productVariants
16
- .map((productVariant) => ({ label: productVariant.size.lookiero, value: productVariant.id }))
17
- .concat({ label: productVariantSelected.size.lookiero, value: productVariantSelected.id }), [productVariantSelected.id, productVariantSelected.size.lookiero, productVariants]);
15
+ const sizeSelectorOptions = useMemo(() => productVariants.map((productVariant) => ({ label: productVariant.size.lookiero, value: productVariant.id })), [productVariants]);
18
16
  const disabledSizeSelector = useMemo(() => sizeSelectorOptions.length === 1 && sizeSelectorOptions[0]?.value === productVariantSelected.id, [sizeSelectorOptions, productVariantSelected.id]);
19
17
  const handleOnPressSizeSelector = useCallback(() => onSizeSelectorPress(), [onSizeSelectorPress]);
20
18
  return (React.createElement(Sticky, { onLayout: onLayout },
@@ -1,8 +1,6 @@
1
1
  import { FC } from "react";
2
- import { FeedbackProjection } from "../../../../../../projection/feedback/feedback";
3
2
  import { ReturnQuestionProjection } from "../../../../../../projection/returnQuestion/returnQuestion";
4
3
  interface ReturnQuestionsFeedbackProps {
5
- readonly feedback: FeedbackProjection;
6
4
  readonly returnQuestions: ReturnQuestionProjection[];
7
5
  readonly onEditFeedback: () => void;
8
6
  }
@@ -4,7 +4,6 @@ import React from "react";
4
4
  import { View } from "react-native";
5
5
  import { ReturnQuestionType, } from "../../../../../../projection/returnQuestion/returnQuestion";
6
6
  import { ReturnQuestions } from "../../../../components/organisms/returnQuestions/ReturnQuestions";
7
- import { ReturnQuestionFeedbackProvider } from "../../../../components/organisms/returnQuestions/behaviors/useReturnQuestionFeedback";
8
7
  import { ReturnQuestionItemProvider, } from "../../../../components/organisms/returnQuestions/behaviors/useReturnQuestionItem";
9
8
  import { HostDefaultReturnQuestionFeedbackItem } from "../../../../components/organisms/returnQuestions/components/hostDefaultReturnQuestionFeedbackItem/HostDefaultReturnQuestionFeedbackItem";
10
9
  import { ReturnQuestionFeedbackItem } from "../../../../components/organisms/returnQuestions/components/returnQuestionFeedbackItem/ReturnQuestionFeedbackItem";
@@ -13,20 +12,19 @@ import { ButtonIcon } from "../../../../shared/components/molecules/buttonIcon/B
13
12
  import { style } from "./ReturnQuestionsFeedback.style";
14
13
  const returnQuestionItems = {
15
14
  [ReturnQuestionType.HOST_DEFAULT]: HostDefaultReturnQuestionFeedbackItem,
16
- [ReturnQuestionType.HOST_TEXTAREA]: HostDefaultReturnQuestionFeedbackItem,
15
+ [ReturnQuestionType.HOST_TEXTAREA]: ReturnQuestionFeedbackItem,
17
16
  [ReturnQuestionType.HOST_SELECT]: ReturnQuestionFeedbackItem,
18
17
  [ReturnQuestionType.HOST_STACK]: ReturnQuestionFeedbackItem,
19
18
  [ReturnQuestionType.TEXTAREA]: ReturnQuestionFeedbackItem,
20
19
  [ReturnQuestionType.OPTION]: ReturnQuestionFeedbackItem,
21
20
  };
22
- const ReturnQuestionsFeedback = ({ feedback, returnQuestions, onEditFeedback }) => {
21
+ const ReturnQuestionsFeedback = ({ returnQuestions, onEditFeedback }) => {
23
22
  const titleText = useI18nMessage({ id: I18nMessages.FEEDBACK_TITLE, prefix: RETURN_QUESTIONS_FEEDBACK_PREFIX });
24
23
  return (React.createElement(View, null,
25
24
  React.createElement(View, { style: style.titleContainer },
26
25
  React.createElement(Text, { level: 2, style: style.title }, titleText),
27
26
  React.createElement(ButtonIcon, { name: "pencil", onPress: onEditFeedback })),
28
- React.createElement(ReturnQuestionFeedbackProvider, { feedback: feedback },
29
- React.createElement(ReturnQuestionItemProvider, { returnQuestionItems: returnQuestionItems },
30
- React.createElement(ReturnQuestions, { returnQuestions: returnQuestions })))));
27
+ React.createElement(ReturnQuestionItemProvider, { returnQuestionItems: returnQuestionItems },
28
+ React.createElement(ReturnQuestions, { returnQuestions: returnQuestions }))));
31
29
  };
32
30
  export { ReturnQuestionsFeedback };
@@ -5,7 +5,6 @@ import { ReturnQuestionProjection } from "../../../../../../projection/returnQue
5
5
  import { PriceProjection } from "../../../../../../projection/shared/price";
6
6
  interface ReturnQuestionsFormProps {
7
7
  readonly visible: boolean;
8
- readonly feedback: FeedbackProjection;
9
8
  readonly returnQuestions: ReturnQuestionProjection[];
10
9
  readonly checkoutItemPrice: PriceProjection;
11
10
  readonly productVariant: CheckoutItemProductVariantProjection;
@@ -6,7 +6,7 @@ import React, { useCallback } from "react";
6
6
  import { View } from "react-native";
7
7
  import { ReturnQuestionType, } from "../../../../../../projection/returnQuestion/returnQuestion";
8
8
  import { ReturnQuestions } from "../../../../components/organisms/returnQuestions/ReturnQuestions";
9
- import { ReturnQuestionFeedbackProvider } from "../../../../components/organisms/returnQuestions/behaviors/useReturnQuestionFeedback";
9
+ import { useReturnQuestionFeedback } from "../../../../components/organisms/returnQuestions/behaviors/useReturnQuestionFeedback";
10
10
  import { ReturnQuestionItemProvider, } from "../../../../components/organisms/returnQuestions/behaviors/useReturnQuestionItem";
11
11
  import { HostDefaultReturnQuestionItem } from "../../../../components/organisms/returnQuestions/components/hostDefaultReturnQuestionItem/HostDefaultReturnQuestionItem";
12
12
  import { HostSelectReturnQuestionItem } from "../../../../components/organisms/returnQuestions/components/hostSelectReturnQuestionItem/HostSelectReturnQuestionItem";
@@ -26,21 +26,21 @@ const returnQuestionItems = {
26
26
  [ReturnQuestionType.TEXTAREA]: TextareaReturnQuestionItem,
27
27
  [ReturnQuestionType.OPTION]: OptionReturnQuestionItem,
28
28
  };
29
- const ReturnQuestionsForm = ({ feedback, returnQuestions, checkoutItemPrice, productVariant, visible, onSubmit, onClose, }) => {
29
+ const ReturnQuestionsForm = ({ returnQuestions, checkoutItemPrice, productVariant, visible, onSubmit, onClose, }) => {
30
30
  const titleText = useI18nMessage({ id: I18nMessages.RETURN_QUESTIONS_TITLE, prefix: RETURN_QUESTIONS_PREFIX });
31
31
  const submitButtonText = useI18nMessage({
32
32
  id: I18nMessages.RETURN_QUESTIONS_SUBMIT_BUTTON,
33
33
  prefix: RETURN_QUESTIONS_PREFIX,
34
34
  });
35
35
  const { media, brand, name, size, color } = productVariant;
36
+ const feedback = useReturnQuestionFeedback();
36
37
  const handleOnSubmit = useCallback(() => onSubmit(feedback), [feedback, onSubmit]);
37
- return (React.createElement(ReturnQuestionFeedbackProvider, { feedback: feedback },
38
- React.createElement(ReturnQuestionItemProvider, { returnQuestionItems: returnQuestionItems },
39
- React.createElement(PortalHost, { name: RETURN_QUESTION_FORM_PORTAL_HOST_NAME }),
40
- React.createElement(Modal, { footer: React.createElement(Button, { onPress: handleOnSubmit }, submitButtonText), portalHostName: RETURN_QUESTION_FORM_PORTAL_HOST_NAME, visible: visible, scroll: true, showCloseButton: true, onClose: onClose },
41
- React.createElement(View, { style: style.returnQuestionsContainer },
42
- React.createElement(Text, { level: 2, style: style.title }, titleText),
43
- React.createElement(ProductVariant, { brand: brand, color: color, media: media, name: name, price: checkoutItemPrice, size: size }),
44
- React.createElement(ReturnQuestions, { portalHostName: RETURN_QUESTION_FORM_PORTAL_HOST_NAME, returnQuestions: returnQuestions }))))));
38
+ return (React.createElement(ReturnQuestionItemProvider, { returnQuestionItems: returnQuestionItems },
39
+ React.createElement(PortalHost, { name: RETURN_QUESTION_FORM_PORTAL_HOST_NAME }),
40
+ React.createElement(Modal, { footer: React.createElement(Button, { onPress: handleOnSubmit }, submitButtonText), portalHostName: RETURN_QUESTION_FORM_PORTAL_HOST_NAME, visible: visible, scroll: true, showCloseButton: true, onClose: onClose },
41
+ React.createElement(View, { style: style.returnQuestionsContainer },
42
+ React.createElement(Text, { level: 2, style: style.title }, titleText),
43
+ React.createElement(ProductVariant, { brand: brand, color: color, media: media, name: name, price: checkoutItemPrice, size: size }),
44
+ React.createElement(ReturnQuestions, { portalHostName: RETURN_QUESTION_FORM_PORTAL_HOST_NAME, returnQuestions: returnQuestions })))));
45
45
  };
46
46
  export { ReturnQuestionsForm };
@@ -4,10 +4,7 @@ interface ProductVariantProjection {
4
4
  readonly size: SizeProjection;
5
5
  }
6
6
  interface BookedSizeChangeProductsVariantsProjection {
7
- readonly id: string;
8
- readonly checkoutId: string;
9
- readonly checkoutItemId: string;
10
- readonly booking: string | null;
7
+ readonly bookingId: string;
11
8
  readonly productVariants: ProductVariantProjection[];
12
9
  }
13
10
  export type { BookedSizeChangeProductsVariantsProjection, ProductVariantProjection };
@@ -39,7 +39,7 @@ interface CheckoutItemProjection {
39
39
  readonly price: PriceProjection;
40
40
  readonly replacedFor?: string;
41
41
  readonly productVariant: CheckoutItemProductVariantProjection;
42
- readonly feedback: FeedbackProjection;
42
+ readonly feedbacks: FeedbackProjection;
43
43
  }
44
44
  export type { CheckoutItemProjection, CheckoutItemProductVariantProjection, ColorProjection, MediaProjection };
45
45
  export { MediaPerspective };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lookiero/checkout",
3
- "version": "0.2.52",
3
+ "version": "0.3.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -16,7 +16,7 @@
16
16
  "web": "expo start --web",
17
17
  "export-analyze-web": "BUNDLE_ANALYZE=true NODE_ENV=production expo export:web",
18
18
  "build": "tsc -b tsconfig.build.json",
19
- "build:app": "tsc -p ./tsconfig.build-app.json --noemit && ENTRY_POINT='./src/Expo.tsx' NODE_ENV=production expo export:web --clear",
19
+ "build:app": "tsc -p ./tsconfig.build-app.json --noemit && ENTRY_POINT='./src/Expo.tsx' NODE_ENV=production expo export:web --clear 2> /dev/null",
20
20
  "lint": "eslint --fix --cache --cache-location ./node_modules/.cache/.eslintcache --ext ts,tsx .",
21
21
  "format": "prettier --write \"**/*.+(json|css|ts|tsx|md)\"",
22
22
  "test": "tsc -p ./tsconfig.test.json --noemit && jest",