@lookiero/checkout 0.3.24 → 0.3.26

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 (34) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/src/domain/checkout/model/checkout.d.ts +2 -1
  3. package/dist/src/domain/checkout/model/checkout.js +1 -0
  4. package/dist/src/domain/checkoutBooking/command/blockCheckoutBooking.d.ts +13 -0
  5. package/dist/src/domain/checkoutBooking/command/blockCheckoutBooking.js +4 -0
  6. package/dist/src/domain/checkoutBooking/model/checkoutBooking.d.ts +5 -1
  7. package/dist/src/domain/checkoutBooking/model/checkoutBooking.js +17 -1
  8. package/dist/src/domain/checkoutBooking/model/checkoutBookingBlocked.d.ts +13 -0
  9. package/dist/src/domain/checkoutBooking/model/checkoutBookingBlocked.js +4 -0
  10. package/dist/src/domain/checkoutBooking/model/checkoutBookingExpired.d.ts +13 -0
  11. package/dist/src/domain/checkoutBooking/model/checkoutBookingExpired.js +4 -0
  12. package/dist/src/domain/checkoutItem/command/replaceCheckoutItem.d.ts +1 -1
  13. package/dist/src/domain/checkoutItem/model/checkoutItem.d.ts +1 -1
  14. package/dist/src/domain/checkoutItem/model/checkoutItem.js +2 -2
  15. package/dist/src/infrastructure/delivery/baseBootstrap.js +3 -1
  16. package/dist/src/infrastructure/delivery/mock/dataSourceCheckoutBookings.js +3 -0
  17. package/dist/src/infrastructure/delivery/mock/dataSourceCheckoutItems.js +2 -0
  18. package/dist/src/infrastructure/domain/checkoutBooking/model/httpCheckoutBookings.js +9 -2
  19. package/dist/src/infrastructure/domain/checkoutBooking/model/httpCheckoutBookingsBlock.d.ts +5 -0
  20. package/dist/src/infrastructure/domain/checkoutBooking/model/httpCheckoutBookingsBlock.js +15 -0
  21. package/dist/src/infrastructure/domain/checkoutBooking/react/useBlockCheckoutBooking.d.ts +13 -0
  22. package/dist/src/infrastructure/domain/checkoutBooking/react/useBlockCheckoutBooking.js +12 -0
  23. package/dist/src/infrastructure/domain/checkoutBooking/react/useBookCheckoutBookingForCheckoutItem.d.ts +13 -0
  24. package/dist/src/infrastructure/domain/checkoutBooking/react/{useBookCheckouBookingForCheckoutItem.js → useBookCheckoutBookingForCheckoutItem.js} +2 -2
  25. package/dist/src/infrastructure/domain/checkoutItem/model/httpCheckoutItems.js +1 -1
  26. package/dist/src/infrastructure/domain/checkoutItem/model/httpCheckoutItemsReplace.js +2 -2
  27. package/dist/src/infrastructure/domain/checkoutItem/react/useReplaceCheckoutItem.d.ts +1 -1
  28. package/dist/src/infrastructure/domain/checkoutItem/react/useReplaceCheckoutItem.js +2 -2
  29. package/dist/src/infrastructure/ui/views/item/Item.js +6 -12
  30. package/dist/src/infrastructure/ui/views/summary/components/checkoutItemsTabs/CheckoutItemsTabs.js +7 -4
  31. package/dist/src/projection/checkoutBooking/checkoutBooking.d.ts +2 -0
  32. package/dist/src/projection/checkoutItem/checkoutItem.d.ts +1 -1
  33. package/package.json +1 -1
  34. package/dist/src/infrastructure/domain/checkoutBooking/react/useBookCheckouBookingForCheckoutItem.d.ts +0 -13
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lookiero/checkout",
3
- "version": "0.3.24",
3
+ "version": "0.3.26",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -6,7 +6,8 @@ declare enum CheckoutStatus {
6
6
  NOTIFIED = "NOTIFIED",
7
7
  STARTED = "STARTED",
8
8
  COMPLETED = "COMPLETED",
9
- PAID = "PAID"
9
+ PAID = "PAID",
10
+ EXPIRED = "EXPIRED"
10
11
  }
11
12
  interface Checkout extends AggregateRoot {
12
13
  readonly status: CheckoutStatus;
@@ -8,6 +8,7 @@ var CheckoutStatus;
8
8
  CheckoutStatus["STARTED"] = "STARTED";
9
9
  CheckoutStatus["COMPLETED"] = "COMPLETED";
10
10
  CheckoutStatus["PAID"] = "PAID";
11
+ CheckoutStatus["EXPIRED"] = "EXPIRED";
11
12
  })(CheckoutStatus || (CheckoutStatus = {}));
12
13
  const startCheckoutHandler = () => async ({ aggregateRoot, command }) => {
13
14
  const { aggregateId } = command;
@@ -0,0 +1,13 @@
1
+ import { Command } from "@lookiero/messaging";
2
+ declare const BLOCK_CHECKOUT_BOOKING = "block_checkout_booking";
3
+ interface BlockCheckoutBookingPayload {
4
+ readonly aggregateId: string;
5
+ }
6
+ interface BlockCheckoutBooking extends Command<typeof BLOCK_CHECKOUT_BOOKING>, BlockCheckoutBookingPayload {
7
+ }
8
+ interface BlockCheckoutBookingFunction {
9
+ (payload: BlockCheckoutBookingPayload): BlockCheckoutBooking;
10
+ }
11
+ declare const blockCheckoutBooking: BlockCheckoutBookingFunction;
12
+ export type { BlockCheckoutBooking };
13
+ export { BLOCK_CHECKOUT_BOOKING, blockCheckoutBooking };
@@ -0,0 +1,4 @@
1
+ import { command } from "@lookiero/messaging";
2
+ const BLOCK_CHECKOUT_BOOKING = "block_checkout_booking";
3
+ const blockCheckoutBooking = ({ aggregateId }) => command({ aggregateId, name: BLOCK_CHECKOUT_BOOKING });
4
+ export { BLOCK_CHECKOUT_BOOKING, blockCheckoutBooking };
@@ -1,8 +1,12 @@
1
1
  import { AggregateRoot, CommandHandlerFunction } from "@lookiero/messaging";
2
+ import { CheckoutStatus } from "../../checkout/model/checkout";
3
+ import { BlockCheckoutBooking } from "../command/blockCheckoutBooking";
2
4
  import { BookCheckoutBookingForCheckoutItem } from "../command/bookCheckoutBookingForCheckoutItem";
3
5
  interface CheckoutBooking extends AggregateRoot {
4
6
  readonly checkoutItemIds: string[];
7
+ readonly checkoutStatus: CheckoutStatus;
5
8
  }
6
9
  declare const bookCheckoutBookingForCheckoutItemHandler: CommandHandlerFunction<BookCheckoutBookingForCheckoutItem, CheckoutBooking>;
10
+ declare const blockCheckoutBookingHandler: CommandHandlerFunction<BlockCheckoutBooking, CheckoutBooking>;
7
11
  export type { CheckoutBooking };
8
- export { bookCheckoutBookingForCheckoutItemHandler };
12
+ export { bookCheckoutBookingForCheckoutItemHandler, blockCheckoutBookingHandler };
@@ -1,4 +1,7 @@
1
+ import { CheckoutStatus } from "../../checkout/model/checkout";
2
+ import { checkoutBookingBlocked } from "./checkoutBookingBlocked";
1
3
  import { checkoutBookingBooked } from "./checkoutBookingBooked";
4
+ import { checkoutBookingExpired } from "./checkoutBookingExpired";
2
5
  const bookCheckoutBookingForCheckoutItemHandler = () => async ({ aggregateRoot, command }) => {
3
6
  const { aggregateId, checkoutItemId } = command;
4
7
  return {
@@ -6,4 +9,17 @@ const bookCheckoutBookingForCheckoutItemHandler = () => async ({ aggregateRoot,
6
9
  domainEvents: [checkoutBookingBooked({ aggregateId, checkoutItemId })],
7
10
  };
8
11
  };
9
- export { bookCheckoutBookingForCheckoutItemHandler };
12
+ const blockCheckoutBookingHandler = () => async ({ aggregateRoot, command }) => {
13
+ const { aggregateId } = command;
14
+ if (aggregateRoot.checkoutStatus === CheckoutStatus.EXPIRED) {
15
+ return {
16
+ ...aggregateRoot,
17
+ domainEvents: [checkoutBookingExpired({ aggregateId })],
18
+ };
19
+ }
20
+ return {
21
+ ...aggregateRoot,
22
+ domainEvents: [checkoutBookingBlocked({ aggregateId })],
23
+ };
24
+ };
25
+ export { bookCheckoutBookingForCheckoutItemHandler, blockCheckoutBookingHandler };
@@ -0,0 +1,13 @@
1
+ import { DomainEvent } from "@lookiero/messaging";
2
+ declare const CHECKOUT_BOOKING_BLOCKED = "checkout_booking_blocked";
3
+ interface CheckoutBookingBlokedPaylcoad {
4
+ readonly aggregateId: string;
5
+ }
6
+ interface CheckoutBookingBlocked extends DomainEvent<typeof CHECKOUT_BOOKING_BLOCKED>, CheckoutBookingBlokedPaylcoad {
7
+ }
8
+ interface CheckoutBookingBlokedFunctcion {
9
+ (payload: CheckoutBookingBlokedPaylcoad): CheckoutBookingBlocked;
10
+ }
11
+ declare const checkoutBookingBlocked: CheckoutBookingBlokedFunctcion;
12
+ export type { CheckoutBookingBlocked };
13
+ export { CHECKOUT_BOOKING_BLOCKED, checkoutBookingBlocked };
@@ -0,0 +1,4 @@
1
+ import { domainEvent } from "@lookiero/messaging";
2
+ const CHECKOUT_BOOKING_BLOCKED = "checkout_booking_blocked";
3
+ const checkoutBookingBlocked = ({ aggregateId }) => domainEvent({ aggregateId, name: CHECKOUT_BOOKING_BLOCKED });
4
+ export { CHECKOUT_BOOKING_BLOCKED, checkoutBookingBlocked };
@@ -0,0 +1,13 @@
1
+ import { DomainEvent } from "@lookiero/messaging";
2
+ declare const CHECKOUT_BOOKING_EXPIRED = "checkout_booking_expired";
3
+ interface CheckoutBookingExpiredPayload {
4
+ readonly aggregateId: string;
5
+ }
6
+ interface CheckoutBookingExpired extends DomainEvent<typeof CHECKOUT_BOOKING_EXPIRED>, CheckoutBookingExpiredPayload {
7
+ }
8
+ interface CheckoutBookingExpiredFunction {
9
+ (payload: CheckoutBookingExpiredPayload): CheckoutBookingExpired;
10
+ }
11
+ declare const checkoutBookingExpired: CheckoutBookingExpiredFunction;
12
+ export type { CheckoutBookingExpired };
13
+ export { CHECKOUT_BOOKING_EXPIRED, checkoutBookingExpired };
@@ -0,0 +1,4 @@
1
+ import { domainEvent } from "@lookiero/messaging";
2
+ const CHECKOUT_BOOKING_EXPIRED = "checkout_booking_expired";
3
+ const checkoutBookingExpired = ({ aggregateId }) => domainEvent({ aggregateId, name: CHECKOUT_BOOKING_EXPIRED });
4
+ export { CHECKOUT_BOOKING_EXPIRED, checkoutBookingExpired };
@@ -2,7 +2,7 @@ import { Command } from "@lookiero/messaging";
2
2
  declare const REPLACE_CHECKOUT_ITEM = "replace_checkout_item";
3
3
  interface ReplaceCheckoutItemPayload {
4
4
  readonly aggregateId: string;
5
- readonly replacedFor: string;
5
+ readonly replacedForId: string;
6
6
  }
7
7
  interface ReplaceCheckoutItem extends Command<typeof REPLACE_CHECKOUT_ITEM>, ReplaceCheckoutItemPayload {
8
8
  }
@@ -15,7 +15,7 @@ interface CheckoutItem extends AggregateRoot {
15
15
  readonly status: CheckoutItemStatus;
16
16
  readonly price: Price;
17
17
  readonly feedbacks: Feedbacks;
18
- readonly replacedFor?: string;
18
+ readonly replacedForId?: string;
19
19
  }
20
20
  declare const keepCheckoutItemHandler: CommandHandlerFunction<KeepCheckoutItem, CheckoutItem>;
21
21
  declare const returnCheckoutItemHandler: CommandHandlerFunction<ReturnCheckoutItem, CheckoutItem>;
@@ -29,10 +29,10 @@ const returnCheckoutItemHandler = () => async ({ aggregateRoot, command }) => {
29
29
  };
30
30
  };
31
31
  const replaceCheckoutItemHandler = () => async ({ aggregateRoot, command }) => {
32
- const { aggregateId, replacedFor } = command;
32
+ const { aggregateId, replacedForId } = command;
33
33
  return {
34
34
  ...aggregateRoot,
35
- replacedFor,
35
+ replacedForId,
36
36
  status: CheckoutItemStatus.REPLACED,
37
37
  domainEvents: [checkoutItemReplaced({ aggregateId })],
38
38
  };
@@ -2,8 +2,9 @@ import { bootstrap as messagingBootstrap } from "@lookiero/messaging-react";
2
2
  import { MARK_CHECKOUT_AS_PAID } from "../../domain/checkout/command/markCheckoutAsPaid";
3
3
  import { START_CHECKOUT } from "../../domain/checkout/command/startCheckout";
4
4
  import { markCheckoutAsPaidHandler, startCheckoutHandler } from "../../domain/checkout/model/checkout";
5
+ import { BLOCK_CHECKOUT_BOOKING } from "../../domain/checkoutBooking/command/blockCheckoutBooking";
5
6
  import { BOOK_CHECKOUT_BOOKING_FOR_CHECKOUT_ITEM } from "../../domain/checkoutBooking/command/bookCheckoutBookingForCheckoutItem";
6
- import { bookCheckoutBookingForCheckoutItemHandler, } from "../../domain/checkoutBooking/model/checkoutBooking";
7
+ import { blockCheckoutBookingHandler, bookCheckoutBookingForCheckoutItemHandler, } from "../../domain/checkoutBooking/model/checkoutBooking";
7
8
  import { GIVE_CHECKOUT_FEEDBACK } from "../../domain/checkoutFeedback/command/giveCheckoutFeedback";
8
9
  import { giveCheckoutFeedbackHandler } from "../../domain/checkoutFeedback/model/checkoutFeedback";
9
10
  import { KEEP_CHECKOUT_ITEM } from "../../domain/checkoutItem/command/keepCheckoutItem";
@@ -67,6 +68,7 @@ const baseBootstrap = ({ checkoutByIdView, firstAvailableCheckoutByCustomerIdVie
67
68
  view: bookedSizeChangeProductsVariantsForCheckoutItemView,
68
69
  })
69
70
  .command(BOOK_CHECKOUT_BOOKING_FOR_CHECKOUT_ITEM, bookCheckoutBookingForCheckoutItemHandler)(getCheckoutBooking, saveCheckoutBooking, ...checkoutBookingsDependencies)
71
+ .command(BLOCK_CHECKOUT_BOOKING, blockCheckoutBookingHandler)(getCheckoutBooking, saveCheckoutBooking, ...checkoutBookingsDependencies)
70
72
  .command(GIVE_CHECKOUT_FEEDBACK, giveCheckoutFeedbackHandler)(getCheckoutFeedback, saveCheckoutFeedback, ...checkoutFeedbacksDependencies)
71
73
  .query(VIEW_UI_SETTING_BY_KEY, viewUiSettingByKeyHandler, {
72
74
  view: uiSettingByKeyView,
@@ -1,17 +1,20 @@
1
1
  import invariant from "tiny-invariant";
2
2
  import { v4 as uuid } from "uuid";
3
+ import { CheckoutStatus } from "../../../domain/checkout/model/checkout";
3
4
  import { viewBookedSizeChangeProductsVariantsForCheckoutItem, } from "../../../projection/bookedSizeChangeProductsVariants/viewBookedSizeChangeProductVariantsForCheckoutItem";
4
5
  const toCheckoutBookingDomain = (checkoutBooking) => {
5
6
  invariant(checkoutBooking, "No checkoutBooking found!");
6
7
  return {
7
8
  aggregateId: uuid(),
8
9
  checkoutItemIds: checkoutBooking.productVariants.map((productVariant) => productVariant.id),
10
+ checkoutStatus: CheckoutStatus.AVAILABLE,
9
11
  domainEvents: [],
10
12
  };
11
13
  };
12
14
  const toCheckoutBookingProjection = (checkoutBooking) => ({
13
15
  id: checkoutBooking.aggregateId,
14
16
  checkoutItemIds: checkoutBooking.checkoutItemIds,
17
+ checkoutStatus: checkoutBooking.checkoutStatus,
15
18
  });
16
19
  const getCheckoutBooking = ({ queryBus }) => async (aggregateId) => toCheckoutBookingDomain(await queryBus(viewBookedSizeChangeProductsVariantsForCheckoutItem({ checkoutItemId: aggregateId })));
17
20
  const saveCheckoutBooking = ({ dataSource }) => async (aggregateRoot) => {
@@ -5,6 +5,7 @@ const toCheckoutItemProjection = (checkoutItem) => ({
5
5
  status: checkoutItem.status,
6
6
  productVariant: {},
7
7
  feedbacks: {},
8
+ replacedFor: null,
8
9
  price: checkoutItem.price,
9
10
  });
10
11
  const toCheckoutItemDomain = (checkoutItem) => {
@@ -15,6 +16,7 @@ const toCheckoutItemDomain = (checkoutItem) => {
15
16
  status: checkoutItem.status,
16
17
  price: checkoutItem.price,
17
18
  feedbacks: checkoutItem.feedbacks,
19
+ replacedForId: checkoutItem.replacedFor?.id,
18
20
  domainEvents: [],
19
21
  };
20
22
  };
@@ -1,14 +1,21 @@
1
1
  import invariant from "tiny-invariant";
2
2
  import { viewCheckoutBookingById, } from "../../../../projection/checkoutBooking/viewCheckoutBookingById";
3
+ import { httpCheckoutBookingsBlock } from "./httpCheckoutBookingsBlock";
3
4
  import { httpCheckoutBookingsBook } from "./httpCheckoutBookingsBook";
4
5
  const toDomain = (checkoutBooking) => {
5
6
  invariant(checkoutBooking, "No checkout booking found!");
6
7
  return {
7
- checkoutItemIds: checkoutBooking.checkoutItemIds,
8
8
  aggregateId: checkoutBooking.id,
9
+ checkoutItemIds: checkoutBooking.checkoutItemIds,
10
+ checkoutStatus: checkoutBooking.checkoutStatus,
9
11
  domainEvents: [],
10
12
  };
11
13
  };
12
14
  const getCheckoutBooking = ({ queryBus }) => async (aggregateId) => toDomain(await queryBus(viewCheckoutBookingById({ checkoutBookingId: aggregateId })));
13
- const saveCheckoutBooking = ({ httpPost }) => async (aggregateRoot) => await httpCheckoutBookingsBook({ httpPost })(aggregateRoot);
15
+ const saveCheckoutBooking = ({ httpPost }) => async (aggregateRoot) => {
16
+ await Promise.all([
17
+ httpCheckoutBookingsBook({ httpPost })(aggregateRoot),
18
+ httpCheckoutBookingsBlock({ httpPost })(aggregateRoot),
19
+ ]);
20
+ };
14
21
  export { getCheckoutBooking, saveCheckoutBooking };
@@ -0,0 +1,5 @@
1
+ import { HttpCheckoutBookingsSaveFunction } from "./httpCheckoutBookings";
2
+ interface HttpCheckoutBookingsBlockFunction extends HttpCheckoutBookingsSaveFunction {
3
+ }
4
+ declare const httpCheckoutBookingsBlock: HttpCheckoutBookingsBlockFunction;
5
+ export { httpCheckoutBookingsBlock };
@@ -0,0 +1,15 @@
1
+ import { CHECKOUT_BOOKING_BLOCKED, } from "../../../../domain/checkoutBooking/model/checkoutBookingBlocked";
2
+ const isCheckoutBookingBlocked = (event) => event.name === CHECKOUT_BOOKING_BLOCKED;
3
+ const httpCheckoutBookingsBlock = ({ httpPost }) => async ({ aggregateId, domainEvents }) => {
4
+ const checkoutBookingBlocked = domainEvents.find(isCheckoutBookingBlocked);
5
+ if (!checkoutBookingBlocked) {
6
+ return;
7
+ }
8
+ await httpPost({
9
+ endpoint: "/block-checkout-booking",
10
+ body: {
11
+ checkoutBookingId: aggregateId,
12
+ },
13
+ });
14
+ };
15
+ export { httpCheckoutBookingsBlock };
@@ -0,0 +1,13 @@
1
+ import { CommandStatus } from "@lookiero/messaging-react";
2
+ interface BlockCheckoutBookingFunction {
3
+ (): Promise<void>;
4
+ }
5
+ type UseBlockCheckoutBooking = [blockCheckoutBooking: BlockCheckoutBookingFunction, status: CommandStatus];
6
+ interface UseBlockCheckoutBookingFunctionArgs {
7
+ readonly checkoutBookingId: string;
8
+ }
9
+ interface UseBlockCheckoutBookingFunction {
10
+ (args: UseBlockCheckoutBookingFunctionArgs): UseBlockCheckoutBooking;
11
+ }
12
+ declare const useBlockCheckoutBooking: UseBlockCheckoutBookingFunction;
13
+ export { useBlockCheckoutBooking };
@@ -0,0 +1,12 @@
1
+ import { useCommand } from "@lookiero/messaging-react";
2
+ import { useCallback } from "react";
3
+ import { blockCheckoutBooking as blockCheckoutBookingCommand } from "../../../../domain/checkoutBooking/command/blockCheckoutBooking";
4
+ import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
5
+ const useBlockCheckoutBooking = ({ checkoutBookingId }) => {
6
+ const [commandBus, status] = useCommand({ contextId: MESSAGING_CONTEXT_ID });
7
+ const blockCheckoutBooking = useCallback(() => commandBus(blockCheckoutBookingCommand({
8
+ aggregateId: checkoutBookingId,
9
+ })), [checkoutBookingId, commandBus]);
10
+ return [blockCheckoutBooking, status];
11
+ };
12
+ export { useBlockCheckoutBooking };
@@ -0,0 +1,13 @@
1
+ import { CommandStatus } from "@lookiero/messaging-react";
2
+ interface BookFunction {
3
+ (): Promise<void>;
4
+ }
5
+ type UseBookCheckoutBookingForCheckoutItem = [book: BookFunction, status: CommandStatus];
6
+ interface UseBookCheckoutBookingForCheckoutItemFunctionArgs {
7
+ readonly checkoutItemId: string;
8
+ }
9
+ interface UseBookCheckoutBookingForCheckoutItemFunction {
10
+ (args: UseBookCheckoutBookingForCheckoutItemFunctionArgs): UseBookCheckoutBookingForCheckoutItem;
11
+ }
12
+ declare const useBookCheckoutBookingForCheckoutItem: UseBookCheckoutBookingForCheckoutItemFunction;
13
+ export { useBookCheckoutBookingForCheckoutItem };
@@ -3,7 +3,7 @@ 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 }) => {
6
+ const useBookCheckoutBookingForCheckoutItem = ({ checkoutItemId }) => {
7
7
  const [commandBus, status] = useCommand({ contextId: MESSAGING_CONTEXT_ID });
8
8
  const book = useCallback(() => commandBus(bookCheckoutBookingForCheckoutItem({
9
9
  aggregateId: uuid(),
@@ -11,4 +11,4 @@ const useBookCheckouBookingForCheckoutItem = ({ checkoutItemId }) => {
11
11
  })), [checkoutItemId, commandBus]);
12
12
  return [book, status];
13
13
  };
14
- export { useBookCheckouBookingForCheckoutItem };
14
+ export { useBookCheckoutBookingForCheckoutItem };
@@ -10,7 +10,7 @@ const toDomain = (checkoutItem) => {
10
10
  status: checkoutItem.status,
11
11
  price: checkoutItem.price,
12
12
  feedbacks: checkoutItem.feedbacks,
13
- replacedFor: checkoutItem.replacedFor,
13
+ replacedForId: checkoutItem.replacedFor?.id,
14
14
  aggregateId: checkoutItem.id,
15
15
  domainEvents: [],
16
16
  };
@@ -1,13 +1,13 @@
1
1
  import { CHECKOUT_ITEM_REPLACED, } from "../../../../domain/checkoutItem/model/checkoutItemReplaced";
2
2
  const isCheckoutItemReplaced = (event) => event.name === CHECKOUT_ITEM_REPLACED;
3
- const httpCheckoutItemsReplace = ({ httpPost }) => async ({ aggregateId, replacedFor, domainEvents }) => {
3
+ const httpCheckoutItemsReplace = ({ httpPost }) => async ({ aggregateId, replacedForId, domainEvents }) => {
4
4
  const checkoutItemReplaced = domainEvents.find(isCheckoutItemReplaced);
5
5
  if (!checkoutItemReplaced) {
6
6
  return;
7
7
  }
8
8
  await httpPost({
9
9
  endpoint: "/replace-checkout-item",
10
- body: { checkoutItemId: aggregateId, replacedFor },
10
+ body: { checkoutItemId: aggregateId, replacedFor: replacedForId },
11
11
  });
12
12
  };
13
13
  export { httpCheckoutItemsReplace };
@@ -1,6 +1,6 @@
1
1
  import { CommandStatus } from "@lookiero/messaging-react";
2
2
  interface ReplaceCheckoutItemFunctionArgs {
3
- readonly replacedFor: string;
3
+ readonly replacedForId: string;
4
4
  }
5
5
  interface ReplaceCheckoutItemFunction {
6
6
  (args: ReplaceCheckoutItemFunctionArgs): Promise<void>;
@@ -4,9 +4,9 @@ import { replaceCheckoutItem } from "../../../../domain/checkoutItem/command/rep
4
4
  import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
5
5
  const useReplaceCheckoutItem = ({ checkoutItemId }) => {
6
6
  const [commandBus, status] = useCommand({ contextId: MESSAGING_CONTEXT_ID });
7
- const replace = useCallback(({ replacedFor }) => commandBus(replaceCheckoutItem({
7
+ const replace = useCallback(({ replacedForId }) => commandBus(replaceCheckoutItem({
8
8
  aggregateId: checkoutItemId,
9
- replacedFor,
9
+ replacedForId,
10
10
  })), [checkoutItemId, commandBus]);
11
11
  return [replace, status];
12
12
  };
@@ -5,7 +5,7 @@ import { generatePath, useMatch, useNavigate, useParams } from "react-router-nat
5
5
  import { CheckoutItemStatus } from "../../../../domain/checkoutItem/model/checkoutItem";
6
6
  import "../../../../projection/checkout/viewFirstAvailableCheckoutByCustomerId";
7
7
  import { Spinner } from "../../../../shared/ui/components/atoms/spinner/Spinner";
8
- import { useBookCheckouBookingForCheckoutItem } from "../../../domain/checkoutBooking/react/useBookCheckouBookingForCheckoutItem";
8
+ import { useBookCheckoutBookingForCheckoutItem } from "../../../domain/checkoutBooking/react/useBookCheckoutBookingForCheckoutItem";
9
9
  import { useKeepCheckoutItem } from "../../../domain/checkoutItem/react/useKeepCheckoutItem";
10
10
  import { useReplaceCheckoutItem } from "../../../domain/checkoutItem/react/useReplaceCheckoutItem";
11
11
  import { useReturnCheckoutItem } from "../../../domain/checkoutItem/react/useReturnCheckoutItem";
@@ -75,7 +75,7 @@ const Item = ({ customerId }) => {
75
75
  const [bookedSizeChangeProductsVariants, bookedSizeChangeProductsVariantsStatus] = useViewBookedSizeChangeProductsVariantsForCheckoutItem({
76
76
  checkoutItemId: checkoutItem.id,
77
77
  });
78
- const [bookCheckouBooking] = useBookCheckouBookingForCheckoutItem({
78
+ const [bookCheckouBooking] = useBookCheckoutBookingForCheckoutItem({
79
79
  checkoutItemId: checkoutItem.id,
80
80
  });
81
81
  useEffect(() => {
@@ -94,20 +94,14 @@ const Item = ({ customerId }) => {
94
94
  handleOnHideReturnQuestions();
95
95
  returnCheckoutItem({ feedbacks });
96
96
  }, [handleOnHideReturnQuestions, returnCheckoutItem]);
97
- const handleOnReplace = useCallback((replacedFor) => {
97
+ const handleOnReplace = useCallback((replacedForId) => {
98
98
  handleOnShowSizeChangeModal();
99
- replaceCheckoutItem({ replacedFor });
99
+ replaceCheckoutItem({ replacedForId });
100
100
  }, [handleOnShowSizeChangeModal, replaceCheckoutItem]);
101
101
  const handleOnReturn = useCallback(() => handleOnShowReturnQuestions(), [handleOnShowReturnQuestions]);
102
102
  const productVariantSelected = useMemo(() => checkoutItem.status === CheckoutItemStatus.REPLACED && checkoutItem.replacedFor
103
- ? bookedSizeChangeProductsVariants?.productVariants.find((productVariant) => productVariant.id === checkoutItem.replacedFor)
104
- : { id: checkoutItem.productVariant.id, size: checkoutItem.productVariant.size }, [
105
- bookedSizeChangeProductsVariants?.productVariants,
106
- checkoutItem.productVariant.id,
107
- checkoutItem.productVariant.size,
108
- checkoutItem.replacedFor,
109
- checkoutItem.status,
110
- ]);
103
+ ? { id: checkoutItem.replacedFor.id, size: checkoutItem.replacedFor.size }
104
+ : { id: checkoutItem.productVariant.id, size: checkoutItem.productVariant.size }, [checkoutItem.productVariant.id, checkoutItem.productVariant.size, checkoutItem.replacedFor, checkoutItem.status]);
111
105
  const dependenciesLoadedStatuses = [QueryStatus.ERROR, QueryStatus.SUCCESS];
112
106
  const dependenciesLoaded = dependenciesLoadedStatuses.includes(returnQuestionsStatus) &&
113
107
  (dependenciesLoadedStatuses.includes(checkoutStatus) || checkout) &&
@@ -2,12 +2,13 @@ import { Text } from "@lookiero/aurora-next/build/components/primitives/Text/Tex
2
2
  import { useI18nMessage } from "@lookiero/i18n-react";
3
3
  import React, { useCallback } from "react";
4
4
  import { View } from "react-native";
5
+ import { CheckoutItemStatus } from "../../../../../../domain/checkoutItem/model/checkoutItem";
5
6
  import { Tabs } from "../../../../components/layouts/tabs/Tabs";
6
7
  import { I18nMessages } from "../../../../i18n/i18n";
7
8
  import { ProductVariant } from "../../../item/components/productVariant/ProductVariant";
8
9
  import { style } from "./CheckoutItemsTabs.style";
9
- const CheckoutItem = ({ checkoutItem, discarded = false, testID, style: customStyle, onPress, }) => (React.createElement(View, { style: style.checkoutItem, testID: testID },
10
- React.createElement(ProductVariant, { brand: checkoutItem.productVariant.brand, color: checkoutItem.productVariant.color, discarded: discarded, media: checkoutItem.productVariant.media, name: checkoutItem.productVariant.name, price: checkoutItem.price, size: checkoutItem.productVariant.size, status: checkoutItem.status, style: customStyle, onPress: onPress })));
10
+ const CheckoutItem = ({ checkoutItemStatus, checkoutItemProductVariant, checkoutItemPrice, discarded = false, testID, style: customStyle, onPress, }) => (React.createElement(View, { style: style.checkoutItem, testID: testID },
11
+ React.createElement(ProductVariant, { brand: checkoutItemProductVariant.brand, color: checkoutItemProductVariant.color, discarded: discarded, media: checkoutItemProductVariant.media, name: checkoutItemProductVariant.name, price: checkoutItemPrice, size: checkoutItemProductVariant.size, status: checkoutItemStatus, style: customStyle, onPress: onPress })));
11
12
  const CheckoutItemsTabs = ({ checkoutItemsKept, checkoutItemsReturned, onPressItem }) => {
12
13
  const keepTabText = useI18nMessage({ id: I18nMessages.SUMMARY_KEEP_TAB });
13
14
  const returnTabText = useI18nMessage({ id: I18nMessages.SUMMARY_RETURN_TAB });
@@ -15,7 +16,9 @@ const CheckoutItemsTabs = ({ checkoutItemsKept, checkoutItemsReturned, onPressIt
15
16
  const returnEmptyText = useI18nMessage({ id: I18nMessages.SUMMARY_RETURN_EMPTY });
16
17
  const handleOnPressItem = useCallback((checkoutItemId) => onPressItem(checkoutItemId), [onPressItem]);
17
18
  return (React.createElement(Tabs, { style: { sliderContainer: style.sliderContainer }, tabLabels: [`${keepTabText} (${checkoutItemsKept.length})`, `${returnTabText} (${checkoutItemsReturned.length})`] },
18
- React.createElement(React.Fragment, null, checkoutItemsKept.length === 0 ? (React.createElement(Text, null, keepEmptyText)) : (checkoutItemsKept.map((checkoutItem) => (React.createElement(CheckoutItem, { key: checkoutItem.id, checkoutItem: checkoutItem, testID: "keep-checkout-item", onPress: () => handleOnPressItem(checkoutItem.id) }))))),
19
- React.createElement(React.Fragment, null, checkoutItemsReturned.length === 0 ? (React.createElement(Text, null, returnEmptyText)) : (checkoutItemsReturned.map((checkoutItem) => (React.createElement(CheckoutItem, { key: checkoutItem.id, checkoutItem: checkoutItem, style: { image: style.returnCheckoutItem }, testID: "return-checkout-item", discarded: true, onPress: () => handleOnPressItem(checkoutItem.id) })))))));
19
+ React.createElement(React.Fragment, null, checkoutItemsKept.length === 0 ? (React.createElement(Text, null, keepEmptyText)) : (checkoutItemsKept.map((checkoutItem) => (React.createElement(CheckoutItem, { key: checkoutItem.id, checkoutItemPrice: checkoutItem.price, checkoutItemStatus: checkoutItem.status, testID: "keep-checkout-item", checkoutItemProductVariant: checkoutItem.status === CheckoutItemStatus.REPLACED && checkoutItem.replacedFor
20
+ ? checkoutItem.replacedFor
21
+ : checkoutItem.productVariant, onPress: () => handleOnPressItem(checkoutItem.id) }))))),
22
+ React.createElement(React.Fragment, null, checkoutItemsReturned.length === 0 ? (React.createElement(Text, null, returnEmptyText)) : (checkoutItemsReturned.map((checkoutItem) => (React.createElement(CheckoutItem, { key: checkoutItem.id, checkoutItemPrice: checkoutItem.price, checkoutItemProductVariant: checkoutItem.productVariant, checkoutItemStatus: checkoutItem.status, style: { image: style.returnCheckoutItem }, testID: "return-checkout-item", discarded: true, onPress: () => handleOnPressItem(checkoutItem.id) })))))));
20
23
  };
21
24
  export { CheckoutItemsTabs };
@@ -1,5 +1,7 @@
1
+ import { CheckoutStatus } from "../../domain/checkout/model/checkout";
1
2
  interface CheckoutBookingProjection {
2
3
  readonly id: string;
3
4
  readonly checkoutItemIds: string[];
5
+ readonly checkoutStatus: CheckoutStatus;
4
6
  }
5
7
  export type { CheckoutBookingProjection };
@@ -37,7 +37,7 @@ interface CheckoutItemProjection {
37
37
  readonly id: string;
38
38
  readonly status: CheckoutItemStatus;
39
39
  readonly price: PriceProjection;
40
- readonly replacedFor?: string;
40
+ readonly replacedFor: CheckoutItemProductVariantProjection | null;
41
41
  readonly productVariant: CheckoutItemProductVariantProjection;
42
42
  readonly feedbacks: FeedbackProjection;
43
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lookiero/checkout",
3
- "version": "0.3.24",
3
+ "version": "0.3.26",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -1,13 +0,0 @@
1
- import { CommandStatus } from "@lookiero/messaging-react";
2
- interface BookFunction {
3
- (): Promise<void>;
4
- }
5
- type UseBookCheckouBookingForCheckoutItem = [book: BookFunction, status: CommandStatus];
6
- interface UseBookCheckouBookingForCheckoutItemFunctionArgs {
7
- readonly checkoutItemId: string;
8
- }
9
- interface UseBookCheckouBookingForCheckoutItemFunction {
10
- (args: UseBookCheckouBookingForCheckoutItemFunctionArgs): UseBookCheckouBookingForCheckoutItem;
11
- }
12
- declare const useBookCheckouBookingForCheckoutItem: UseBookCheckouBookingForCheckoutItemFunction;
13
- export { useBookCheckouBookingForCheckoutItem };