Files
coopgo/node_modules/redux-notifications/src/actions.js
sgauthier 6e64e138e2
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s
planning
2024-10-14 09:15:30 +02:00

44 lines
1017 B
JavaScript

const objectAssign = require('object-assign');
export const NOTIF_SEND = 'NOTIF_SEND';
export const NOTIF_DISMISS = 'NOTIF_DISMISS';
export const NOTIF_CLEAR = 'NOTIF_CLEAR';
/**
* Publish a notification,
* - if `dismissAfter` was set, the notification will be auto dismissed after the given period.
* - if id wasn't specified, a time based id will be generated.``
*/
export function notifSend(notif) {
const payload = objectAssign({}, notif);
if (!payload.id) {
payload.id = new Date().getTime();
}
return dispatch => {
dispatch({ type: NOTIF_SEND, payload });
if (payload.dismissAfter) {
setTimeout(() => {
dispatch({
type: NOTIF_DISMISS,
payload: payload.id,
});
}, payload.dismissAfter);
}
};
}
/**
* Dismiss a notification by the given id.
*/
export function notifDismiss(id) {
return { type: NOTIF_DISMISS, payload: id };
}
/**
* Clear all notifications
*/
export function notifClear() {
return { type: NOTIF_CLEAR };
}