2017-06-21 23:31:59 +00:00
|
|
|
// @flow
|
2017-08-28 18:05:38 +00:00
|
|
|
import type { Element } from 'react';
|
2017-06-21 23:31:59 +00:00
|
|
|
|
2017-07-27 17:05:09 +00:00
|
|
|
/*** Shared types ***/
|
2017-06-21 23:31:59 +00:00
|
|
|
export type NOTIFICATION_LEVEL = 'danger' | 'warning' | 'success' | 'info';
|
2017-07-31 23:14:30 +00:00
|
|
|
export type INFINITY = 'infinity';
|
2017-06-21 23:31:59 +00:00
|
|
|
|
|
|
|
export type Notification = {
|
2017-07-04 03:28:56 +00:00
|
|
|
level: NOTIFICATION_LEVEL,
|
2017-08-28 18:05:38 +00:00
|
|
|
msg: Element<*> | string,
|
2017-07-31 23:14:30 +00:00
|
|
|
duration?: number | INFINITY
|
2017-06-21 23:31:59 +00:00
|
|
|
};
|
|
|
|
|
2017-07-27 17:05:09 +00:00
|
|
|
/*** Show Notification ***/
|
2017-06-21 23:31:59 +00:00
|
|
|
export type ShowNotificationAction = {
|
2017-07-04 03:28:56 +00:00
|
|
|
type: 'SHOW_NOTIFICATION',
|
|
|
|
payload: Notification
|
2017-06-21 23:31:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export function showNotification(
|
2017-07-04 03:28:56 +00:00
|
|
|
level: NOTIFICATION_LEVEL = 'info',
|
2017-08-28 18:05:38 +00:00
|
|
|
msg: Element<*> | string,
|
2017-09-04 16:30:31 +00:00
|
|
|
duration?: number | INFINITY
|
2017-06-21 23:31:59 +00:00
|
|
|
): ShowNotificationAction {
|
2017-07-04 03:28:56 +00:00
|
|
|
return {
|
|
|
|
type: 'SHOW_NOTIFICATION',
|
|
|
|
payload: {
|
|
|
|
level,
|
|
|
|
msg,
|
|
|
|
duration
|
|
|
|
}
|
|
|
|
};
|
2017-06-21 23:31:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-27 17:05:09 +00:00
|
|
|
/*** Close notification ***/
|
|
|
|
export type CloseNotificationAction = {
|
|
|
|
type: 'CLOSE_NOTIFICATION',
|
|
|
|
payload: Notification
|
|
|
|
};
|
|
|
|
|
2017-07-04 03:28:56 +00:00
|
|
|
export function closeNotification(
|
|
|
|
notification: Notification
|
|
|
|
): CloseNotificationAction {
|
|
|
|
return {
|
|
|
|
type: 'CLOSE_NOTIFICATION',
|
|
|
|
payload: notification
|
|
|
|
};
|
2017-06-21 23:31:59 +00:00
|
|
|
}
|
2017-07-27 17:05:09 +00:00
|
|
|
|
|
|
|
/*** Union Type ***/
|
|
|
|
export type NotificationsAction =
|
|
|
|
| ShowNotificationAction
|
|
|
|
| CloseNotificationAction;
|