reducer.ts 583 B

12345678910111213141516171819202122
  1. import { getType } from 'typesafe-actions';
  2. import { dismissAlert } from 'redux/actions';
  3. import { Action, AlertsState } from 'redux/interfaces';
  4. import { addError, removeAlert } from './utils';
  5. export const initialState: AlertsState = {};
  6. const reducer = (state = initialState, action: Action): AlertsState => {
  7. const { type } = action;
  8. const matches = /(.*)__(FAILURE)$/.exec(type);
  9. if (matches && matches[2]) return addError(state, action);
  10. if (type === getType(dismissAlert)) {
  11. return removeAlert(state, action);
  12. }
  13. return state;
  14. };
  15. export default reducer;