2022-01-10 14:01:24 -08:00
|
|
|
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2020-03-27 13:59:38 -07:00
|
|
|
import {
|
|
|
|
ALERT_SHOW,
|
|
|
|
ALERT_DISMISS,
|
|
|
|
ALERT_CLEAR,
|
|
|
|
} from '../actions/alerts';
|
|
|
|
|
|
|
|
const initialState = ImmutableList([]);
|
|
|
|
|
|
|
|
export default function alerts(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
|
|
|
case ALERT_SHOW:
|
|
|
|
return state.push(ImmutableMap({
|
|
|
|
key: state.size > 0 ? state.last().get('key') + 1 : 0,
|
|
|
|
title: action.title,
|
|
|
|
message: action.message,
|
2020-09-21 20:56:15 -07:00
|
|
|
severity: action.severity || 'info',
|
2022-01-27 07:00:05 -08:00
|
|
|
actionLabel: action.actionLabel,
|
|
|
|
actionLink: action.actionLink,
|
2020-03-27 13:59:38 -07:00
|
|
|
}));
|
|
|
|
case ALERT_DISMISS:
|
|
|
|
return state.filterNot(item => item.get('key') === action.alert.key);
|
|
|
|
case ALERT_CLEAR:
|
|
|
|
return state.clear();
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2021-08-03 12:22:51 -07:00
|
|
|
}
|