@lookiero/checkout 3.0.0 → 3.1.0
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/infrastructure/domain/checkout/react/useSubmitCheckout.js +1 -3
- package/dist/infrastructure/ui/Root.d.ts +1 -0
- package/dist/infrastructure/ui/Root.js +2 -2
- package/dist/infrastructure/ui/hooks/useSubmitCheckout.d.ts +1 -0
- package/dist/infrastructure/ui/hooks/useSubmitCheckout.js +3 -2
- package/dist/infrastructure/ui/routing/Routing.d.ts +1 -0
- package/dist/infrastructure/ui/routing/Routing.js +2 -2
- package/dist/infrastructure/ui/views/checkout/components/checkoutPaymentModal/CheckoutPaymentModal.d.ts +1 -0
- package/dist/infrastructure/ui/views/checkout/components/checkoutPaymentModal/CheckoutPaymentModal.js +4 -3
- package/package.json +1 -1
|
@@ -12,9 +12,7 @@ const useSubmitCheckout = ({ checkoutId, logger }) => {
|
|
|
12
12
|
const submit = useCallback(async () => {
|
|
13
13
|
invariant(checkoutId, "CheckoutId must be defined in order to submit checkout");
|
|
14
14
|
try {
|
|
15
|
-
|
|
16
|
-
aggregateId: checkoutId,
|
|
17
|
-
}));
|
|
15
|
+
await commandBus(submitCheckout({ aggregateId: checkoutId }));
|
|
18
16
|
}
|
|
19
17
|
catch (error) {
|
|
20
18
|
logger.captureException(error);
|
|
@@ -21,6 +21,7 @@ interface RootProps {
|
|
|
21
21
|
readonly customer: Customer | undefined;
|
|
22
22
|
readonly layout: Layout;
|
|
23
23
|
readonly onNotAccessible: () => void;
|
|
24
|
+
readonly onCheckoutSubmitted?: () => void;
|
|
24
25
|
readonly useRedirect: () => Record<string, string>;
|
|
25
26
|
readonly useRoutes?: typeof reactRouterUseRoutes;
|
|
26
27
|
}
|
|
@@ -6,10 +6,10 @@ import { sentryLoggerHOC } from "../../shared/logging/SentryLoggerHOC";
|
|
|
6
6
|
import { Routing } from "./routing/Routing";
|
|
7
7
|
const root = ({ Messaging, I18n, getAuthToken, development, sentry }) => {
|
|
8
8
|
// eslint-disable-next-line react/display-name, react/prop-types
|
|
9
|
-
const Root = ({ basePath, locale = "en", customer, layout, onNotAccessible, useRedirect, useRoutes = reactRouterUseRoutes, }) => {
|
|
9
|
+
const Root = ({ basePath, locale = "en", customer, layout, onNotAccessible, onCheckoutSubmitted, useRedirect, useRoutes = reactRouterUseRoutes, }) => {
|
|
10
10
|
const handleOnI18nError = useCallback(() => void 0, []);
|
|
11
11
|
return (React.createElement(Messaging, { includeReactQueryDevTools: Platform.OS === "web" },
|
|
12
|
-
React.createElement(Routing, { I18n: I18n, basePath: basePath, customer: customer, getAuthToken: getAuthToken, layout: layout, locale: locale, useRedirect: useRedirect, useRoutes: useRoutes, onI18nError: development ? undefined : handleOnI18nError, onNotAccessible: onNotAccessible })));
|
|
12
|
+
React.createElement(Routing, { I18n: I18n, basePath: basePath, customer: customer, getAuthToken: getAuthToken, layout: layout, locale: locale, useRedirect: useRedirect, useRoutes: useRoutes, onCheckoutSubmitted: onCheckoutSubmitted, onI18nError: development ? undefined : handleOnI18nError, onNotAccessible: onNotAccessible })));
|
|
13
13
|
};
|
|
14
14
|
return sentryLoggerHOC({ logger: sentryLogger(sentry) })(Root);
|
|
15
15
|
};
|
|
@@ -16,6 +16,7 @@ interface UseSubmitCheckoutFunctionArgs {
|
|
|
16
16
|
readonly checkoutBookingId: string;
|
|
17
17
|
readonly paymentFlowRef: RefObject<PaymentFlowRef>;
|
|
18
18
|
readonly onError: () => void;
|
|
19
|
+
readonly onSuccess?: () => void;
|
|
19
20
|
readonly logger: Logger;
|
|
20
21
|
}
|
|
21
22
|
interface UseSubmitCheckoutFunction {
|
|
@@ -7,7 +7,7 @@ import { MESSAGING_CONTEXT_ID } from "../../delivery/baseBootstrap";
|
|
|
7
7
|
import { useSubmitCheckout as useSubmitCheckoutCommand } from "../../domain/checkout/react/useSubmitCheckout";
|
|
8
8
|
import { useBlockCheckoutBooking } from "../../domain/checkoutBooking/react/useBlockCheckoutBooking";
|
|
9
9
|
import { I18nMessages } from "../i18n/i18n";
|
|
10
|
-
const useSubmitCheckout = ({ checkoutId, checkoutBookingId, paymentFlowRef, onError, logger, }) => {
|
|
10
|
+
const useSubmitCheckout = ({ checkoutId, checkoutBookingId, paymentFlowRef, onError, onSuccess, logger, }) => {
|
|
11
11
|
const [submitCheckoutCommand, submitCheckoutCommandStatus] = useSubmitCheckoutCommand({ checkoutId, logger });
|
|
12
12
|
const [blockCheckoutBooking, blockCheckoutBookingStatus] = useBlockCheckoutBooking({ checkoutBookingId, logger });
|
|
13
13
|
const [createNotification] = useCreateToastNotification({ contextId: MESSAGING_CONTEXT_ID, logger });
|
|
@@ -33,6 +33,7 @@ const useSubmitCheckout = ({ checkoutId, checkoutBookingId, paymentFlowRef, onEr
|
|
|
33
33
|
if (status === ChargeStatus.EXECUTED) {
|
|
34
34
|
setStartLegacyBoxCheckoutStatus("success");
|
|
35
35
|
await submitCheckoutCommand();
|
|
36
|
+
onSuccess?.();
|
|
36
37
|
}
|
|
37
38
|
else {
|
|
38
39
|
createNotification({
|
|
@@ -43,7 +44,7 @@ const useSubmitCheckout = ({ checkoutId, checkoutBookingId, paymentFlowRef, onEr
|
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
});
|
|
46
|
-
}, [paymentFlowRef, blockCheckoutBooking, submitCheckoutCommand, createNotification]);
|
|
47
|
+
}, [paymentFlowRef, blockCheckoutBooking, submitCheckoutCommand, onSuccess, createNotification]);
|
|
47
48
|
const status = useMemo(() => {
|
|
48
49
|
if (blockCheckoutBookingStatus === CommandStatus.LOADING ||
|
|
49
50
|
startLegacyBoxCheckoutStatus === "loading" ||
|
|
@@ -11,6 +11,7 @@ interface RoutingProps {
|
|
|
11
11
|
readonly layout: Layout;
|
|
12
12
|
readonly getAuthToken: () => Promise<string>;
|
|
13
13
|
readonly onNotAccessible: () => void;
|
|
14
|
+
readonly onCheckoutSubmitted?: () => void;
|
|
14
15
|
readonly onI18nError?: (err: Error) => void;
|
|
15
16
|
readonly useRedirect: () => Record<string, string>;
|
|
16
17
|
readonly useRoutes: typeof reactRouterUseRoutes;
|
|
@@ -11,7 +11,7 @@ const Item = lazy(() => import("../views/item/Item").then((module) => ({ default
|
|
|
11
11
|
const Summary = lazy(() => import("../views/summary/Summary").then((module) => ({ default: module.Summary })));
|
|
12
12
|
const Checkout = lazy(() => import("../views/checkout/Checkout").then((module) => ({ default: module.Checkout })));
|
|
13
13
|
const Feedback = lazy(() => import("../views/feedback/Feedback").then((module) => ({ default: module.Feedback })));
|
|
14
|
-
const Routing = ({ basePath = "", customer, locale, I18n, layout, getAuthToken, onI18nError, onNotAccessible, useRedirect, useRoutes = reactRouterUseRoutes, }) => {
|
|
14
|
+
const Routing = ({ basePath = "", customer, locale, I18n, layout, getAuthToken, onI18nError, onNotAccessible, onCheckoutSubmitted, useRedirect, useRoutes = reactRouterUseRoutes, }) => {
|
|
15
15
|
return useRoutes([
|
|
16
16
|
{
|
|
17
17
|
path: "",
|
|
@@ -45,7 +45,7 @@ const Routing = ({ basePath = "", customer, locale, I18n, layout, getAuthToken,
|
|
|
45
45
|
children: [
|
|
46
46
|
{
|
|
47
47
|
path: Routes.CHECKOUT_PAYMENT,
|
|
48
|
-
element: React.createElement(CheckoutPaymentModal, { customerId: customer?.customerId, getAuthToken: getAuthToken }),
|
|
48
|
+
element: (React.createElement(CheckoutPaymentModal, { customerId: customer?.customerId, getAuthToken: getAuthToken, onCheckoutSubmitted: onCheckoutSubmitted })),
|
|
49
49
|
},
|
|
50
50
|
],
|
|
51
51
|
},
|
|
@@ -2,6 +2,7 @@ import { FC } from "react";
|
|
|
2
2
|
interface CheckoutPaymentModalProps {
|
|
3
3
|
readonly customerId: string;
|
|
4
4
|
readonly getAuthToken: () => Promise<string>;
|
|
5
|
+
readonly onCheckoutSubmitted?: () => void;
|
|
5
6
|
}
|
|
6
7
|
declare const CheckoutPaymentModal: FC<CheckoutPaymentModalProps>;
|
|
7
8
|
export { CheckoutPaymentModal };
|
|
@@ -9,7 +9,7 @@ import { useViewPaymentFlowPayloadByCheckoutId } from "../../../../../projection
|
|
|
9
9
|
import { useSubmitCheckout } from "../../../../hooks/useSubmitCheckout";
|
|
10
10
|
import { Routes } from "../../../../routing/routes";
|
|
11
11
|
import { useBasePath } from "../../../../routing/useBasePath";
|
|
12
|
-
const CheckoutPaymentModal = ({ customerId, getAuthToken }) => {
|
|
12
|
+
const CheckoutPaymentModal = ({ customerId, getAuthToken, onCheckoutSubmitted }) => {
|
|
13
13
|
const paymentFlowRef = useRef(null);
|
|
14
14
|
const logger = useLogger();
|
|
15
15
|
const [checkout, checkoutStatus] = useViewFirstAvailableCheckoutByCustomerId({ customerId });
|
|
@@ -24,12 +24,13 @@ const CheckoutPaymentModal = ({ customerId, getAuthToken }) => {
|
|
|
24
24
|
}, [getAuthToken]);
|
|
25
25
|
const basePath = useBasePath();
|
|
26
26
|
const navigate = useNavigate();
|
|
27
|
-
const
|
|
27
|
+
const handleOnSubmitCheckoutError = useCallback(() => navigate(`${basePath}/${Routes.CHECKOUT}`, { replace: true }), [basePath, navigate]);
|
|
28
28
|
const [submitCheckout] = useSubmitCheckout({
|
|
29
29
|
checkoutId: checkout?.id,
|
|
30
30
|
checkoutBookingId: checkout?.checkoutBookingId,
|
|
31
31
|
paymentFlowRef,
|
|
32
|
-
onError:
|
|
32
|
+
onError: handleOnSubmitCheckoutError,
|
|
33
|
+
onSuccess: onCheckoutSubmitted,
|
|
33
34
|
logger,
|
|
34
35
|
});
|
|
35
36
|
useEffect(() => {
|