client/reducers/applications.js
import { fromJS } from 'immutable';
import * as constants from '../constants';
import createReducer from '../utils/createReducer';
const initialState = {
loading: false,
error: null,
records: [],
total: 0
};
export const applications = createReducer(fromJS(initialState), { // eslint-disable-line import/prefer-default-export
[constants.FETCH_APPLICATIONS_PENDING]: (state) =>
state.merge({
loading: true,
error: null
}),
[constants.FETCH_APPLICATIONS_REJECTED]: (state, action) =>
state.merge({
loading: false,
error: `An error occured while loading the applications: ${action.errorMessage}`
}),
[constants.FETCH_APPLICATIONS_FULFILLED]: (state, action) =>
state.merge({
loading: false,
error: null,
records: fromJS(action.payload.data)
})
});