All files / recent-reports reducer.js

100% Statements 8/8
100% Branches 4/4
100% Functions 2/2
100% Lines 8/8
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 33 34      3x       3x         6x   1x         1x         4x       3x 1x        
import { actionTypes as asyncDataFetchActionTypes } from '@bufferapp/async-data-fetch';
import keyWrapper from '@bufferapp/keywrapper';
 
export const actionTypes = keyWrapper('REPORTS', {
  FETCH: 'FETCH',
});
 
const initialState = {
  reports: [],
};
 
export default (state = initialState, action) => {
  switch (action.type) {
    case `list_reports_${asyncDataFetchActionTypes.FETCH_SUCCESS}`:
      return {
        ...state,
        reports: action.result,
      };
    case `list_reports_${asyncDataFetchActionTypes.FETCH_FAIL}`:
      return {
        ...state,
        hasError: true,
      };
    default:
      return state;
  }
};
 
export const actions = {
  fetch: () => ({
    type: actionTypes.FETCH,
  }),
};