-
Notifications
You must be signed in to change notification settings - Fork 27
/
hide-notifications.js
32 lines (29 loc) 路 1023 Bytes
/
hide-notifications.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import {
removeNotification,
ADD_NOTIFICATION,
} from '@commercetools-frontend/notifications';
import { selectPageNotifications } from '@commercetools-local/react-notifications';
import { HIDE_ALL_PAGE_NOTIFICATIONS } from '@commercetools-frontend/constants';
function isErrorNotificationKind(kind) {
return kind === 'api-error' || kind === 'unexpected-error';
}
export default ({ getState }) => next => action => {
if (!action) return next(action);
if (action.type === HIDE_ALL_PAGE_NOTIFICATIONS) {
const state = getState();
selectPageNotifications(state).forEach(notification =>
next(removeNotification(notification.id))
);
} else if (
action.type === ADD_NOTIFICATION &&
action.payload &&
isErrorNotificationKind(action.payload.kind)
) {
const state = getState();
selectPageNotifications(state).forEach(notification => {
if (isErrorNotificationKind(notification.kind))
next(removeNotification(notification.id));
});
}
return next(action);
};