How to use @commercetools-frontend/actions-global - 9 common examples

To help you get started, weā€™ve selected a few @commercetools-frontend/actions-global examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github commercetools / merchant-center-application-kit / src / utils / setup-global-error-listener / setup-global-error-listener.js View on Github external
window.addEventListener('unhandledrejection', event => {
    if (process.env.NODE_ENV !== 'production')
      // eslint-disable-next-line no-console
      console.warn(
        'An uncaught promise has been rejected and not properly ' +
          'handled. This is most likely a bug in the software. Please ensure ' +
          'that the promise is correctly handled.'
      );
    dispatch(
      showUnexpectedErrorNotification({ error: { message: event.reason } })
    );
  });
github commercetools / merchant-center-application-kit / packages / application-shell / src / components / handle-apollo-errors / handle-apollo-errors.js View on Github external
// If an error has been dispatched already, we don't do anything else.
          // If an error has been dispatched already but the query does not contain an error anymore,
          // we remove the entry from the dispatchedErrors map.
          // If an error has not been dispatched yet, we keep track of it and we dispatch it.
          const queryResult = this.props[name];
          if (queryResult) {
            const hasPreviouslyDispatchedError = Boolean(
              this.dispatchedErrors.get(name)
            );
            const hasQueryErrored = Boolean(queryResult.error);
            if (hasPreviouslyDispatchedError && !hasQueryErrored) {
              this.dispatchedErrors.delete(name);
            }
            if (!hasPreviouslyDispatchedError && hasQueryErrored) {
              this.dispatchedErrors.set(name, queryResult.error);
              this.context.store.dispatch(handleActionError(queryResult.error));
            }
          }
        });
      }
github commercetools / merchant-center-application-kit / playground / src / components / entry-point / entry-point.js View on Github external
Sdk.Get.errorHandler = error =>
            globalActions.handleActionError(error, 'sdk')(dispatch);
        }}
github commercetools / merchant-center-application-kit / packages / application-shell / src / utils / setup-global-error-listener / setup-global-error-listener.js View on Github external
window.addEventListener('error', errorEvent => {
    internalReduxStore.dispatch(
      showUnexpectedErrorNotification({ error: errorEvent })
    );
  });
}
github commercetools / merchant-center-application-kit / packages / react-notifications / src / components / notifications-connector / notifications-connector.js View on Github external
showNotification: PropTypes.func.isRequired,
  removeNotification: PropTypes.func.isRequired,
  showApiErrorNotification: PropTypes.func.isRequired,
  showUnexpectedErrorNotification: PropTypes.func.isRequired,
};
NotificationsFaC.displayName = 'NotificationsFaC';

const NotificationsConnector = connect(
  (state, ownProps) => {
    const notificationsByDomain = selectNotificationsByDomain(state);
    return { notifications: notificationsByDomain[ownProps.domain] };
  },
  {
    removeNotification,
    showNotification: globalActions.showNotification,
    showApiErrorNotification: globalActions.showApiErrorNotification,
    showUnexpectedErrorNotification:
      globalActions.showUnexpectedErrorNotification,
  }
)(NotificationsFaC);

export default NotificationsConnector;
github commercetools / merchant-center-application-kit / packages / react-notifications / src / components / notifications-connector / notifications-connector.js View on Github external
notifications: PropTypes.array.isRequired,
  showNotification: PropTypes.func.isRequired,
  removeNotification: PropTypes.func.isRequired,
  showApiErrorNotification: PropTypes.func.isRequired,
  showUnexpectedErrorNotification: PropTypes.func.isRequired,
};
NotificationsFaC.displayName = 'NotificationsFaC';

const NotificationsConnector = connect(
  (state, ownProps) => {
    const notificationsByDomain = selectNotificationsByDomain(state);
    return { notifications: notificationsByDomain[ownProps.domain] };
  },
  {
    removeNotification,
    showNotification: globalActions.showNotification,
    showApiErrorNotification: globalActions.showApiErrorNotification,
    showUnexpectedErrorNotification:
      globalActions.showUnexpectedErrorNotification,
  }
)(NotificationsFaC);

export default NotificationsConnector;
github commercetools / merchant-center-application-kit / playground / src / components / state-machines-details / state-machines-details.js View on Github external
const StateMachinesDetails = props => {
  const dataLocale = useApplicationContext(context => context.dataLocale);
  const dispatch = useDispatch();
  const fetcher = React.useCallback(
    (...args) => dispatch(fetchStateMachine(...args)),
    [dispatch]
  );
  const showApiErrorNotification = useShowApiErrorNotification();

  return (
    
      {({ isLoading, data, error }) => {
        if (isLoading) {
          return ;
        }
        if (error) {
          return null;
        }
        return (
github commercetools / merchant-center-application-kit / packages / react-notifications / src / components / notifier / notifier.tsx View on Github external
const Notifier = (props: Props) => {
  const showNotification = globalActions.useShowNotification<
    Props & { id: number }
  >();

  React.useEffect(() => {
    const notification = showNotification(
      {
        id: 0,
        domain: props.domain,
        kind: props.kind,
        text: props.text,
      },
      isNumber(props.dismissAfter)
        ? { ...props.meta, dismissAfter: props.dismissAfter }
        : props.meta
    );
    return () => {