@lookiero/checkout 0.8.3-beta.2 → 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.
@@ -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
- console.log({ message });
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lookiero/checkout",
3
- "version": "0.8.3-beta.2",
3
+ "version": "0.8.3-beta.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [