huridocs/uwazi

View on GitHub
app/react/Notifications/actions/notificationsActions.js

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import * as actions from 'app/Notifications/actions/actionTypes';
import ID from 'shared/uniqueID';

const NOTIFICATION_DELAY = process.env.NOTIFICATION_DELAY || 6000;

export function removeNotification(id) {
  return {
    type: actions.REMOVE_NOTIFICATION,
    id,
  };
}

export function notify(message, type, delay = NOTIFICATION_DELAY) {
  return dispatch => {
    const id = ID();
    dispatch({ type: actions.NOTIFY, notification: { message, type, id } });
    if (delay) {
      setTimeout(() => {
        dispatch(removeNotification(id));
      }, delay);
    }
    return id;
  };
}