@lookiero/checkout 0.8.3-beta.1 → 0.8.3-beta.3
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/ui/hooks/usePaymentInstrumentUpdateEvents.js +4 -17
- package/dist/infrastructure/ui/hooks/useToast.d.ts +11 -0
- package/dist/infrastructure/ui/hooks/useToast.js +45 -0
- package/dist/infrastructure/ui/views/checkout/Checkout.js +3 -7
- package/dist/infrastructure/ui/views/checkout/components/paymentInstrument/PaymentInstrument.d.ts +6 -0
- package/dist/infrastructure/ui/views/checkout/components/paymentInstrument/PaymentInstrument.js +10 -0
- package/package.json +1 -1
|
@@ -1,34 +1,21 @@
|
|
|
1
1
|
import { useEvent } from "@lookiero/event";
|
|
2
2
|
import { useCallback, useEffect } from "react";
|
|
3
3
|
import { useCreateNotification } from "../../../shared/notifications";
|
|
4
|
-
import { NotificationLevel } from "../../../shared/notifications/domain/notification/model/notification";
|
|
5
4
|
import { MESSAGING_CONTEXT_ID } from "../../delivery/baseBootstrap";
|
|
6
5
|
import { I18nMessages } from "../i18n/i18n";
|
|
6
|
+
import { useToast } from "./useToast";
|
|
7
7
|
const PAYMENT_ERROR = "ERROR";
|
|
8
8
|
const PAYMENT_SUCCESS = "PAYMENT_INSTRUMENT_UPDATED";
|
|
9
9
|
const usePaymentInstrumentUpdateEvents = () => {
|
|
10
10
|
const { subscribe, unsubscribe } = useEvent();
|
|
11
|
+
const { showError, showSuccess } = useToast();
|
|
11
12
|
const [createNotification] = useCreateNotification({ contextId: MESSAGING_CONTEXT_ID });
|
|
12
|
-
const onSuccess = useCallback(({ message }) => {
|
|
13
|
-
|
|
14
|
-
createNotification({
|
|
15
|
-
level: NotificationLevel.SUCCESS,
|
|
16
|
-
bodyI18nKey: message.id,
|
|
17
|
-
});
|
|
18
|
-
}, [createNotification]);
|
|
19
|
-
const onError = useCallback(({ error }) => {
|
|
20
|
-
console.log({ error });
|
|
21
|
-
createNotification({
|
|
22
|
-
level: NotificationLevel.ERROR,
|
|
23
|
-
bodyI18nKey: error.toaster?.id || I18nMessages.CHECKOUT_TOAST_PAYMENT_ERROR,
|
|
24
|
-
});
|
|
25
|
-
}, [createNotification]);
|
|
13
|
+
const onSuccess = useCallback(({ message }) => showSuccess({ message: message.id }), [showSuccess]);
|
|
14
|
+
const onError = useCallback(({ error }) => showError({ message: error.toaster?.id || I18nMessages.CHECKOUT_TOAST_PAYMENT_ERROR }), [showError]);
|
|
26
15
|
useEffect(() => {
|
|
27
|
-
console.log("subscribe");
|
|
28
16
|
subscribe({ event: PAYMENT_ERROR }, onError);
|
|
29
17
|
subscribe({ event: PAYMENT_SUCCESS }, onSuccess);
|
|
30
18
|
return () => {
|
|
31
|
-
console.log("unsubscribe");
|
|
32
19
|
unsubscribe({ event: PAYMENT_ERROR }, onError);
|
|
33
20
|
unsubscribe({ event: PAYMENT_SUCCESS }, onSuccess);
|
|
34
21
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface ShowErrorFunctionArgs {
|
|
2
|
+
readonly message: string;
|
|
3
|
+
}
|
|
4
|
+
interface ShowErrorFunction {
|
|
5
|
+
(args: ShowErrorFunctionArgs): void;
|
|
6
|
+
}
|
|
7
|
+
declare const useToast: () => {
|
|
8
|
+
showError: ShowErrorFunction;
|
|
9
|
+
showSuccess: ShowErrorFunction;
|
|
10
|
+
};
|
|
11
|
+
export { useToast };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Notification } from "@lookiero/aurora-next/build/components/molecules/Notification/Notification";
|
|
2
|
+
import { useStack } from "@lookiero/aurora-next/build/contexts/Stack/Stack";
|
|
3
|
+
import { useCallback } from "react";
|
|
4
|
+
import { StyleSheet } from "react-native";
|
|
5
|
+
import { v4 as uuid } from "uuid";
|
|
6
|
+
import { theme } from "../theme/theme";
|
|
7
|
+
const { layoutXXS, elevationColor, elevationOffset, elevationOpacityM, elevationRadius } = theme();
|
|
8
|
+
const style = StyleSheet.create({
|
|
9
|
+
container: {
|
|
10
|
+
marginHorizontal: layoutXXS,
|
|
11
|
+
marginTop: layoutXXS,
|
|
12
|
+
shadowColor: elevationColor,
|
|
13
|
+
shadowOffset: elevationOffset,
|
|
14
|
+
shadowOpacity: elevationOpacityM,
|
|
15
|
+
shadowRadius: elevationRadius,
|
|
16
|
+
},
|
|
17
|
+
inAppContainer: {
|
|
18
|
+
top: 75,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
const NOTIFICATION_DEFAULTS = {
|
|
22
|
+
motion: "top",
|
|
23
|
+
timeoutClose: 10000,
|
|
24
|
+
style: style.container,
|
|
25
|
+
};
|
|
26
|
+
const IN_APP_NOTIFICATION_DEFAULTS = {
|
|
27
|
+
...NOTIFICATION_DEFAULTS,
|
|
28
|
+
style: [style.container, style.inAppContainer],
|
|
29
|
+
};
|
|
30
|
+
const iOSInAppBrowser = window.screen.height > 667 && /FBIOS/.test(navigator.userAgent);
|
|
31
|
+
const getNotificationDefaults = () => (iOSInAppBrowser ? IN_APP_NOTIFICATION_DEFAULTS : NOTIFICATION_DEFAULTS);
|
|
32
|
+
const useToast = () => {
|
|
33
|
+
const Stack = useStack();
|
|
34
|
+
const showError = useCallback(({ message }) => {
|
|
35
|
+
Stack.alert(uuid(), Notification, { ...getNotificationDefaults(), text: message });
|
|
36
|
+
}, [Stack]);
|
|
37
|
+
const showSuccess = useCallback(({ message }) => {
|
|
38
|
+
Stack.success(uuid(), Notification, { ...getNotificationDefaults(), text: message });
|
|
39
|
+
}, [Stack]);
|
|
40
|
+
return {
|
|
41
|
+
showError,
|
|
42
|
+
showSuccess,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export { useToast };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Text } from "@lookiero/aurora-next/build/components/primitives/Text/Text";
|
|
2
2
|
import { useI18nMessage } from "@lookiero/i18n-react";
|
|
3
3
|
import { QueryStatus } from "@lookiero/messaging-react";
|
|
4
|
-
import {
|
|
5
|
-
import React, { useCallback, useMemo, useRef } from "react";
|
|
4
|
+
import React, { useCallback, useMemo } from "react";
|
|
6
5
|
import { Platform, View } from "react-native";
|
|
7
6
|
import { useNavigate } from "react-router-native";
|
|
8
7
|
import { CheckoutItemStatus } from "../../../../domain/checkoutItem/model/checkoutItem";
|
|
@@ -13,7 +12,6 @@ import { useViewPricingByCheckoutId } from "../../../projection/pricing/react/us
|
|
|
13
12
|
import { TrackingPage } from "../../../tracking/tracking";
|
|
14
13
|
import { Body } from "../../components/layouts/body/Body";
|
|
15
14
|
import { SafeAreaScrollView } from "../../components/templates/SafeAreaScrollView";
|
|
16
|
-
import { usePaymentInstrumentUpdateEvents } from "../../hooks/usePaymentInstrumentUpdateEvents";
|
|
17
15
|
import { I18nMessages } from "../../i18n/i18n";
|
|
18
16
|
import { Routes } from "../../routing/routes";
|
|
19
17
|
import { useBasePath } from "../../routing/useBasePath";
|
|
@@ -22,9 +20,9 @@ import { HEADER_HEIGHT } from "../navigation/components/header/Header.style";
|
|
|
22
20
|
import { Pricing } from "../summary/components/pricing/Pricing";
|
|
23
21
|
import { style } from "./Checkout.style";
|
|
24
22
|
import { DeliveryBanner } from "./components/deliveryBanner/DeliveryBanner";
|
|
23
|
+
import { PaymentInstrument } from "./components/paymentInstrument/PaymentInstrument";
|
|
25
24
|
const Checkout = ({ children, customerId, country, useRedirect }) => {
|
|
26
25
|
const titleText = useI18nMessage({ id: I18nMessages.CHECKOUT_TITLE });
|
|
27
|
-
const paymentInstrumentSelectRef = useRef(null);
|
|
28
26
|
const [checkout, checkoutStatus] = useViewFirstAvailableCheckoutByCustomerId({ customerId });
|
|
29
27
|
const [pricing, pricingStatus] = useViewPricingByCheckoutId({ checkoutId: checkout?.id });
|
|
30
28
|
usePageView({
|
|
@@ -32,10 +30,8 @@ const Checkout = ({ children, customerId, country, useRedirect }) => {
|
|
|
32
30
|
country,
|
|
33
31
|
checkoutId: checkout?.id,
|
|
34
32
|
});
|
|
35
|
-
usePaymentInstrumentUpdateEvents();
|
|
36
33
|
const navigate = useNavigate();
|
|
37
34
|
const basePath = useBasePath();
|
|
38
|
-
const { returnUrl } = useRedirect();
|
|
39
35
|
const handleOnSubmit = useCallback(() => {
|
|
40
36
|
navigate(`${basePath}/${Routes.CHECKOUT}/${Routes.CHECKOUT_PAYMENT}`);
|
|
41
37
|
}, [basePath, navigate]);
|
|
@@ -51,7 +47,7 @@ const Checkout = ({ children, customerId, country, useRedirect }) => {
|
|
|
51
47
|
React.createElement(Body, { style: { column: style.bodyColumn } },
|
|
52
48
|
hasReplacedCheckoutItem && (React.createElement(View, { style: style.deliveryBannerContainer },
|
|
53
49
|
React.createElement(DeliveryBanner, null))),
|
|
54
|
-
React.createElement(
|
|
50
|
+
React.createElement(PaymentInstrument, { useRedirect: useRedirect }),
|
|
55
51
|
React.createElement(Text, { level: 3, style: style.title, heading: true }, titleText),
|
|
56
52
|
checkoutItemsKept?.map((checkoutItem) => (React.createElement(View, { key: checkoutItem.id, style: style.checkoutItemKept, testID: "checkout-items-kept" },
|
|
57
53
|
React.createElement(ProductVariant, { brand: checkoutItem.productVariant.brand, color: checkoutItem.productVariant.color, country: country, media: checkoutItem.productVariant.media, name: checkoutItem.productVariant.name, price: checkoutItem.price, status: checkoutItem.status, size: checkoutItem.status === CheckoutItemStatus.REPLACED && checkoutItem.replacedFor
|
package/dist/infrastructure/ui/views/checkout/components/paymentInstrument/PaymentInstrument.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PaymentInstrumentSelect, PaymentMethod, Section } from "@lookiero/payments-front";
|
|
2
|
+
import React, { useRef } from "react";
|
|
3
|
+
import { usePaymentInstrumentUpdateEvents } from "../../../../hooks/usePaymentInstrumentUpdateEvents";
|
|
4
|
+
const PaymentInstrument = ({ useRedirect }) => {
|
|
5
|
+
const paymentInstrumentSelectRef = useRef(null);
|
|
6
|
+
const { returnUrl } = useRedirect();
|
|
7
|
+
usePaymentInstrumentUpdateEvents();
|
|
8
|
+
return (React.createElement(PaymentInstrumentSelect, { ref: paymentInstrumentSelectRef, beforeRedirect: returnUrl ? () => Promise.resolve(returnUrl) : undefined, hasError: false, hidePaymentMethods: [PaymentMethod.GOOGLE_PAY], section: Section.BOX_CHECKOUT }));
|
|
9
|
+
};
|
|
10
|
+
export { PaymentInstrument };
|