All files / @gce/interactions/store reducers.js

76.47% Statements 13/17
100% Branches 5/5
42.86% Functions 3/7
91.67% Lines 11/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117                    1x                               1x                     1x                       1x                       1x                         1x                       1x           1x                                   4x 2x     2x    
import {
  interactionsStatusEnum,
  SET_INTERACTIONS,
  SET_INTERACTIONS_LOADING,
  SET_INTERACTION_DETAIL,
  SET_FILTER_SELECTED,
  SET_APPLICANT_FILTER,
  SET_INTERACTION_DETAIL_LOADING,
} from './constants';
 
const initialState = {
  interactions: [],
  interactionsLoading: false,
  interactionDetail: {},
  interactionDetailLoading: false,
  filter: interactionsStatusEnum.ALL,
  applicantFilter: null,
};
 
/**
* Set the current "concerned user" (usr switcher filter)
* @param {Object} state
* @param {Object} action
* @param {String|Number} action.payload.applicantFilter
* @returns {Object}
*/
const setApplicantFilter = (state, action) => (
  { ...state, applicantFilter: action.payload.applicantFilter }
);
 
/**
 * Set fetched interaction
 *
 * @param {Object} state
 * @param {Object} action
 * @param {Array} action.payload.interactions
 */
const setInteractions = (state, action) => ({
  ...state,
  interactions: action.payload.interactions,
});
 
/**
 * Set interaction loading
 *
 * @param {Object} state
 * @param {Object} action
 * @param {Array} action.payload.changeTrackingLoading
 */
const setInteractionsLoading = (state, action) => ({
  ...state,
  interactionsLoading: action.payload.loading,
});
 
/**
 * Set interaction detail
 *
 * @param {Object} state
 * @param {Object} action
 * @param {Array} action.payload.detail
 */
const setInteractionDetail = (state, action) => ({
  ...state,
  interactionDetail: action.payload.detail,
});
 
 
/**
 * Set filter selected
 *
 * @param {Object} state
 * @param {Object} action
 * @param {String} action.payload.filter
 */
const setFilterSelected = (state, action) => ({
  ...state,
  filter: action.payload.filter,
});
 
/**
 * Set interaction detail loading flag
 *
 * @param {Object} state
 * @param {Object} action
 * @param {Array} action.payload.loading
 */
const setInteractionDetailLoading = (state, action) => ({
  ...state,
  interactionDetailLoading: action.payload.loading,
});
 
// convenience object to map actions to functions
const FUNCTION_BY_ACTION = {
  [SET_INTERACTIONS]: setInteractions,
  [SET_INTERACTION_DETAIL]: setInteractionDetail,
  [SET_FILTER_SELECTED]: setFilterSelected,
  [SET_APPLICANT_FILTER]: setApplicantFilter,
  [SET_INTERACTIONS_LOADING]: setInteractionsLoading,
  [SET_INTERACTION_DETAIL_LOADING]: setInteractionDetailLoading,
};
 
/**
 * Reducer function
 *
 * @param {Object} state
 * @param {Object=} action
 *
 * @returns {Object}
 */
export default (state = initialState, action) => {
  if (action && action.type in FUNCTION_BY_ACTION) {
    return FUNCTION_BY_ACTION[action.type](state, action);
  }
 
  return state;
};