@lookiero/checkout 0.8.8 → 0.8.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/domain/checkoutItem/command/resetCheckoutItem.d.ts +13 -0
- package/dist/domain/checkoutItem/command/resetCheckoutItem.js +4 -0
- package/dist/domain/checkoutItem/model/checkoutItem.d.ts +3 -1
- package/dist/domain/checkoutItem/model/checkoutItem.js +9 -1
- package/dist/domain/checkoutItem/model/checkoutItemReset.d.ts +13 -0
- package/dist/domain/checkoutItem/model/checkoutItemReset.js +4 -0
- package/dist/infrastructure/delivery/baseBootstrap.js +3 -1
- package/dist/infrastructure/domain/checkoutItem/model/httpCheckoutItems.js +2 -0
- package/dist/infrastructure/domain/checkoutItem/model/httpCheckoutItemsReset.d.ts +5 -0
- package/dist/infrastructure/domain/checkoutItem/model/httpCheckoutItemsReset.js +13 -0
- package/dist/infrastructure/domain/checkoutItem/react/useResetCheckoutItem.d.ts +15 -0
- package/dist/infrastructure/domain/checkoutItem/react/useResetCheckoutItem.js +27 -0
- package/dist/infrastructure/projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId.js +3 -0
- package/dist/infrastructure/ui/routing/CheckoutMiddleware.js +1 -7
- package/dist/infrastructure/ui/views/item/Item.js +9 -1
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command } from "@lookiero/messaging";
|
|
2
|
+
declare const RESET_CHECKOUT_ITEM = "reset_checkout_item";
|
|
3
|
+
interface ResetCheckoutItemPayload {
|
|
4
|
+
readonly aggregateId: string;
|
|
5
|
+
}
|
|
6
|
+
interface ResetCheckoutItem extends Command<typeof RESET_CHECKOUT_ITEM>, ResetCheckoutItemPayload {
|
|
7
|
+
}
|
|
8
|
+
interface ResetCheckoutItemFunction {
|
|
9
|
+
(payload: ResetCheckoutItemPayload): ResetCheckoutItem;
|
|
10
|
+
}
|
|
11
|
+
declare const resetCheckoutItem: ResetCheckoutItemFunction;
|
|
12
|
+
export type { ResetCheckoutItem };
|
|
13
|
+
export { RESET_CHECKOUT_ITEM, resetCheckoutItem };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AggregateRoot, CommandHandlerFunction } from "@lookiero/messaging";
|
|
2
2
|
import { KeepCheckoutItem } from "../command/keepCheckoutItem";
|
|
3
3
|
import { ReplaceCheckoutItem } from "../command/replaceCheckoutItem";
|
|
4
|
+
import { ResetCheckoutItem } from "../command/resetCheckoutItem";
|
|
4
5
|
import { ReturnCheckoutItem } from "../command/returnCheckoutItem";
|
|
5
6
|
import { Feedbacks } from "./feedbacks";
|
|
6
7
|
import { Price } from "./price";
|
|
@@ -19,5 +20,6 @@ interface CheckoutItem extends AggregateRoot {
|
|
|
19
20
|
declare const keepCheckoutItemHandler: CommandHandlerFunction<KeepCheckoutItem, CheckoutItem>;
|
|
20
21
|
declare const returnCheckoutItemHandler: CommandHandlerFunction<ReturnCheckoutItem, CheckoutItem>;
|
|
21
22
|
declare const replaceCheckoutItemHandler: CommandHandlerFunction<ReplaceCheckoutItem, CheckoutItem>;
|
|
23
|
+
declare const resetCheckoutItemHandler: CommandHandlerFunction<ResetCheckoutItem, CheckoutItem>;
|
|
22
24
|
export type { CheckoutItem };
|
|
23
|
-
export { CheckoutItemStatus, keepCheckoutItemHandler, returnCheckoutItemHandler, replaceCheckoutItemHandler };
|
|
25
|
+
export { CheckoutItemStatus, keepCheckoutItemHandler, returnCheckoutItemHandler, replaceCheckoutItemHandler, resetCheckoutItemHandler, };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { checkoutItemKept } from "./checkoutItemKept";
|
|
2
2
|
import { checkoutItemReplaced } from "./checkoutItemReplaced";
|
|
3
|
+
import { checkoutItemReset } from "./checkoutItemReset";
|
|
3
4
|
import { checkoutItemReturned } from "./checkoutItemReturned";
|
|
4
5
|
var CheckoutItemStatus;
|
|
5
6
|
(function (CheckoutItemStatus) {
|
|
@@ -34,4 +35,11 @@ const replaceCheckoutItemHandler = () => async ({ aggregateRoot, command }) => {
|
|
|
34
35
|
domainEvents: [checkoutItemReplaced({ aggregateId })],
|
|
35
36
|
};
|
|
36
37
|
};
|
|
37
|
-
|
|
38
|
+
const resetCheckoutItemHandler = () => async ({ aggregateRoot, command }) => {
|
|
39
|
+
const { aggregateId } = command;
|
|
40
|
+
return {
|
|
41
|
+
...aggregateRoot,
|
|
42
|
+
domainEvents: [checkoutItemReset({ aggregateId })],
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export { CheckoutItemStatus, keepCheckoutItemHandler, returnCheckoutItemHandler, replaceCheckoutItemHandler, resetCheckoutItemHandler, };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DomainEvent } from "@lookiero/messaging";
|
|
2
|
+
declare const CHECKOUT_ITEM_RESET = "checkout_item_reset";
|
|
3
|
+
interface CheckoutItemResetPayload {
|
|
4
|
+
readonly aggregateId: string;
|
|
5
|
+
}
|
|
6
|
+
interface CheckoutItemReset extends DomainEvent<typeof CHECKOUT_ITEM_RESET>, CheckoutItemResetPayload {
|
|
7
|
+
}
|
|
8
|
+
interface CheckoutItemResetFunction {
|
|
9
|
+
(payload: CheckoutItemResetPayload): CheckoutItemReset;
|
|
10
|
+
}
|
|
11
|
+
declare const checkoutItemReset: CheckoutItemResetFunction;
|
|
12
|
+
export type { CheckoutItemReset };
|
|
13
|
+
export { CHECKOUT_ITEM_RESET, checkoutItemReset };
|
|
@@ -11,8 +11,9 @@ import { GIVE_CHECKOUT_FEEDBACK } from "../../domain/checkoutFeedback/command/gi
|
|
|
11
11
|
import { giveCheckoutFeedbackHandler } from "../../domain/checkoutFeedback/model/checkoutFeedback";
|
|
12
12
|
import { KEEP_CHECKOUT_ITEM } from "../../domain/checkoutItem/command/keepCheckoutItem";
|
|
13
13
|
import { REPLACE_CHECKOUT_ITEM } from "../../domain/checkoutItem/command/replaceCheckoutItem";
|
|
14
|
+
import { RESET_CHECKOUT_ITEM } from "../../domain/checkoutItem/command/resetCheckoutItem";
|
|
14
15
|
import { RETURN_CHECKOUT_ITEM } from "../../domain/checkoutItem/command/returnCheckoutItem";
|
|
15
|
-
import { keepCheckoutItemHandler, replaceCheckoutItemHandler, returnCheckoutItemHandler, } from "../../domain/checkoutItem/model/checkoutItem";
|
|
16
|
+
import { keepCheckoutItemHandler, replaceCheckoutItemHandler, resetCheckoutItemHandler, returnCheckoutItemHandler, } from "../../domain/checkoutItem/model/checkoutItem";
|
|
16
17
|
import { UPDATE_UI_SETTING } from "../../domain/uiSetting/command/updateUiSetting";
|
|
17
18
|
import { updateUiSettingHandler } from "../../domain/uiSetting/model/uiSetting";
|
|
18
19
|
import { viewBookedProductsVariantsForCheckoutItemHandler, VIEW_BOOKED_PRODUCT_VARIANTS_FOR_CHECKOUT_ITEM, } from "../../projection/bookedProductsVariants/viewBookedProductVariantsForCheckoutItem";
|
|
@@ -57,6 +58,7 @@ const baseBootstrap = ({ checkoutByIdView, firstAvailableCheckoutByCustomerIdVie
|
|
|
57
58
|
.command(KEEP_CHECKOUT_ITEM, keepCheckoutItemHandler)(getCheckoutItem, saveCheckoutItem, ...checkoutItemsDependencies)
|
|
58
59
|
.command(RETURN_CHECKOUT_ITEM, returnCheckoutItemHandler)(getCheckoutItem, saveCheckoutItem, ...checkoutItemsDependencies)
|
|
59
60
|
.command(REPLACE_CHECKOUT_ITEM, replaceCheckoutItemHandler)(getCheckoutItem, saveCheckoutItem, ...checkoutItemsDependencies)
|
|
61
|
+
.command(RESET_CHECKOUT_ITEM, resetCheckoutItemHandler)(getCheckoutItem, saveCheckoutItem, ...checkoutItemsDependencies)
|
|
60
62
|
.query(VIEW_PRICING_BY_CHECKOUT_ID, viewPricingByCheckoutIdHandler, {
|
|
61
63
|
view: pricingByCheckoutIdView,
|
|
62
64
|
})
|
|
@@ -2,6 +2,7 @@ import invariant from "tiny-invariant";
|
|
|
2
2
|
import { viewCheckoutItemById, } from "../../../../projection/checkoutItem/viewCheckoutItemById";
|
|
3
3
|
import { httpCheckoutItemsKeep } from "./httpCheckoutItemsKeep";
|
|
4
4
|
import { httpCheckoutItemsReplace } from "./httpCheckoutItemsReplace";
|
|
5
|
+
import { httpCheckoutItemsReset } from "./httpCheckoutItemsReset";
|
|
5
6
|
import { httpCheckoutItemsReturn } from "./httpCheckoutItemsReturn";
|
|
6
7
|
const toDomain = (checkoutItem) => {
|
|
7
8
|
invariant(checkoutItem, "No checkoutItem found!");
|
|
@@ -21,6 +22,7 @@ const saveCheckoutItem = ({ httpPost }) => async (aggregateRoot) => {
|
|
|
21
22
|
httpCheckoutItemsKeep({ httpPost })(aggregateRoot),
|
|
22
23
|
httpCheckoutItemsReturn({ httpPost })(aggregateRoot),
|
|
23
24
|
httpCheckoutItemsReplace({ httpPost })(aggregateRoot),
|
|
25
|
+
httpCheckoutItemsReset({ httpPost })(aggregateRoot),
|
|
24
26
|
]);
|
|
25
27
|
};
|
|
26
28
|
export { getCheckoutItem, saveCheckoutItem };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CHECKOUT_ITEM_RESET } from "../../../../domain/checkoutItem/model/checkoutItemReset";
|
|
2
|
+
const isCheckoutItemReset = (event) => event.name === CHECKOUT_ITEM_RESET;
|
|
3
|
+
const httpCheckoutItemsReset = ({ httpPost }) => async ({ aggregateId, domainEvents }) => {
|
|
4
|
+
const checkoutItemReset = domainEvents.find(isCheckoutItemReset);
|
|
5
|
+
if (!checkoutItemReset) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
await httpPost({
|
|
9
|
+
endpoint: "/reset-checkout-item",
|
|
10
|
+
body: { checkoutItemId: aggregateId },
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
export { httpCheckoutItemsReset };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CommandStatus } from "@lookiero/messaging-react";
|
|
2
|
+
import { Logger } from "../../../../shared/logging/Logger";
|
|
3
|
+
interface ResetCheckoutItemFunction {
|
|
4
|
+
(): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
interface UseResetCheckoutItemFunctionArgs {
|
|
7
|
+
readonly checkoutItemId: string;
|
|
8
|
+
readonly logger: Logger;
|
|
9
|
+
}
|
|
10
|
+
type UseResetCheckoutItemResult = [reset: ResetCheckoutItemFunction, status: CommandStatus];
|
|
11
|
+
interface UseResetCheckoutItemFunction {
|
|
12
|
+
(args: UseResetCheckoutItemFunctionArgs): UseResetCheckoutItemResult;
|
|
13
|
+
}
|
|
14
|
+
declare const useResetCheckoutItem: UseResetCheckoutItemFunction;
|
|
15
|
+
export { useResetCheckoutItem };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useCommand } from "@lookiero/messaging-react";
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { resetCheckoutItem } from "../../../../domain/checkoutItem/command/resetCheckoutItem";
|
|
4
|
+
import { useCreateNotification } from "../../../../shared/notifications";
|
|
5
|
+
import { NotificationLevel } from "../../../../shared/notifications/domain/notification/model/notification";
|
|
6
|
+
import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
|
|
7
|
+
import { I18nMessages } from "../../../ui/i18n/i18n";
|
|
8
|
+
const useResetCheckoutItem = ({ checkoutItemId, logger }) => {
|
|
9
|
+
const [commandBus, status] = useCommand({ contextId: MESSAGING_CONTEXT_ID });
|
|
10
|
+
const [createNotification] = useCreateNotification({ contextId: MESSAGING_CONTEXT_ID, logger });
|
|
11
|
+
const reset = useCallback(async () => {
|
|
12
|
+
try {
|
|
13
|
+
await commandBus(resetCheckoutItem({
|
|
14
|
+
aggregateId: checkoutItemId,
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
logger.captureException(error);
|
|
19
|
+
createNotification({
|
|
20
|
+
level: NotificationLevel.ERROR,
|
|
21
|
+
bodyI18nKey: I18nMessages.TOAST_GENERIC_ERROR,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}, [checkoutItemId, commandBus, createNotification, logger]);
|
|
25
|
+
return [reset, status];
|
|
26
|
+
};
|
|
27
|
+
export { useResetCheckoutItem };
|
package/dist/infrastructure/projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId.js
CHANGED
|
@@ -6,12 +6,14 @@ import { CHECKOUT_BOOKING_EXPIRED, } from "../../../../domain/checkoutBooking/mo
|
|
|
6
6
|
import { CHECKOUT_FEEDBACK_GIVEN, } from "../../../../domain/checkoutFeedback/model/checkoutFeedbackGiven";
|
|
7
7
|
import { CHECKOUT_ITEM_KEPT } from "../../../../domain/checkoutItem/model/checkoutItemKept";
|
|
8
8
|
import { CHECKOUT_ITEM_REPLACED, } from "../../../../domain/checkoutItem/model/checkoutItemReplaced";
|
|
9
|
+
import { CHECKOUT_ITEM_RESET } from "../../../../domain/checkoutItem/model/checkoutItemReset";
|
|
9
10
|
import { CHECKOUT_ITEM_RETURNED, } from "../../../../domain/checkoutItem/model/checkoutItemReturned";
|
|
10
11
|
import { viewFirstAvailableCheckoutByCustomerId } from "../../../../projection/checkout/viewFirstAvailableCheckoutByCustomerId";
|
|
11
12
|
import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
|
|
12
13
|
const isCheckoutItemKept = (event) => event.name === CHECKOUT_ITEM_KEPT;
|
|
13
14
|
const isCheckoutItemReturned = (event) => event.name === CHECKOUT_ITEM_RETURNED;
|
|
14
15
|
const isCheckoutItemReplaced = (event) => event.name === CHECKOUT_ITEM_REPLACED;
|
|
16
|
+
const isCheckoutItemReset = (event) => event.name === CHECKOUT_ITEM_RESET;
|
|
15
17
|
const isCheckoutStarted = (event) => event.name === CHECKOUT_STARTED;
|
|
16
18
|
const isCheckoutSubmitted = (event) => event.name === CHECKOUT_SUBMITTED;
|
|
17
19
|
const isCheckoutFeedbackGiven = (event) => event.name === CHECKOUT_FEEDBACK_GIVEN;
|
|
@@ -20,6 +22,7 @@ const isCheckoutBookingExpired = (event) => event.name === CHECKOUT_BOOKING_EXPI
|
|
|
20
22
|
const shouldInvalidate = (event) => isCheckoutItemKept(event) ||
|
|
21
23
|
isCheckoutItemReplaced(event) ||
|
|
22
24
|
isCheckoutItemReturned(event) ||
|
|
25
|
+
isCheckoutItemReset(event) ||
|
|
23
26
|
isCheckoutStarted(event) ||
|
|
24
27
|
isCheckoutSubmitted(event) ||
|
|
25
28
|
isCheckoutFeedbackGiven(event) ||
|
|
@@ -12,7 +12,6 @@ import { useBasePath } from "./useBasePath";
|
|
|
12
12
|
const CheckoutMiddleware = ({ customerId, loader = React.createElement(Spinner, null), children }) => {
|
|
13
13
|
const logger = useLogger();
|
|
14
14
|
const basePath = useBasePath();
|
|
15
|
-
const navigatedToFirstItemWithoutCustomerDecision = useRef(false);
|
|
16
15
|
const [checkout, checkoutStatus] = useViewFirstAvailableCheckoutByCustomerId({ customerId });
|
|
17
16
|
const firstItemWithoutCustomerDecision = checkout?.items.find((item) => item.status === CheckoutItemStatus.INITIAL);
|
|
18
17
|
const [startCheckout] = useStartCheckout({ checkoutId: checkout?.id, logger });
|
|
@@ -58,12 +57,7 @@ const CheckoutMiddleware = ({ customerId, loader = React.createElement(Spinner,
|
|
|
58
57
|
return React.createElement(Navigate, { to: `${basePath}/${Routes.HOME}`, replace: true });
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
|
-
|
|
62
|
-
navigatedToFirstItemWithoutCustomerDecision.current =
|
|
63
|
-
navigatedToFirstItemWithoutCustomerDecision.current ||
|
|
64
|
-
Boolean(itemRouteMatch && itemRouteMatch.params.id === firstItemWithoutCustomerDecision?.id);
|
|
65
|
-
if (firstItemWithoutCustomerDecision && !navigatedToFirstItemWithoutCustomerDecision.current) {
|
|
66
|
-
navigatedToFirstItemWithoutCustomerDecision.current = true;
|
|
60
|
+
if (firstItemWithoutCustomerDecision && !itemRouteMatch) {
|
|
67
61
|
return (React.createElement(Navigate, { to: generatePath(`${basePath}/${Routes.ITEM}`, { id: firstItemWithoutCustomerDecision.id }), replace: true }));
|
|
68
62
|
}
|
|
69
63
|
return children;
|
|
@@ -10,6 +10,7 @@ import { Spinner } from "../../../../shared/ui/components/atoms/spinner/Spinner"
|
|
|
10
10
|
import { useBookCheckoutBookingForCheckoutItem } from "../../../domain/checkoutBooking/react/useBookCheckoutBookingForCheckoutItem";
|
|
11
11
|
import { useKeepCheckoutItem } from "../../../domain/checkoutItem/react/useKeepCheckoutItem";
|
|
12
12
|
import { useReplaceCheckoutItem } from "../../../domain/checkoutItem/react/useReplaceCheckoutItem";
|
|
13
|
+
import { useResetCheckoutItem } from "../../../domain/checkoutItem/react/useResetCheckoutItem";
|
|
13
14
|
import { useReturnCheckoutItem } from "../../../domain/checkoutItem/react/useReturnCheckoutItem";
|
|
14
15
|
import { useViewBookedProductsVariantsForCheckoutItem } from "../../../projection/bookedProductsVariants/react/useViewBookedProductsVariantsForCheckoutItem";
|
|
15
16
|
import { useViewFirstAvailableCheckoutByCustomerId } from "../../../projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId";
|
|
@@ -64,7 +65,14 @@ const Item = ({ customerId, country }) => {
|
|
|
64
65
|
useEffect(() => {
|
|
65
66
|
setCustomerDecissionMade(checkoutItem.status !== CheckoutItemStatus.INITIAL);
|
|
66
67
|
}, [checkoutItem.status, id]);
|
|
67
|
-
const
|
|
68
|
+
const [resetCheckoutItem] = useResetCheckoutItem({
|
|
69
|
+
checkoutItemId: checkoutItem.id,
|
|
70
|
+
logger,
|
|
71
|
+
});
|
|
72
|
+
const handleOnBannerPress = useCallback(() => {
|
|
73
|
+
resetCheckoutItem();
|
|
74
|
+
setCustomerDecissionMade(false);
|
|
75
|
+
}, [resetCheckoutItem]);
|
|
68
76
|
const [keepCheckoutItem, keepCheckoutItemStatus] = useKeepCheckoutItem({ checkoutItemId: checkoutItem.id, logger });
|
|
69
77
|
const [returnCheckoutItem, returnCheckoutItemStatus] = useReturnCheckoutItem({
|
|
70
78
|
checkoutItemId: checkoutItem.id,
|