homeReducer.js 1.4 KB
/**
 * # guideReducer.js
 *
 * The reducer for all the actions from the various log states
 */
'use strict';
/**
 * ## Imports
 *
 * InitialState
 */
import InitialState from './homeInitialState';

const {

	HOME_OVERVIEW_REQUEST,
    HOME_OVERVIEW_SUCCESS,
    HOME_OVERVIEW_FAILURE,

} = require('../../constants/actionTypes').default;

const initialState = new InitialState;

/**
 * ## guideReducer function
 * @param {Object} state - initialState
 * @param {Object} action - type and payload
 */
export default function userReducer(state = initialState, action) {
    if (!(state instanceof InitialState)) return initialState.merge(state);

    switch (action.type) {

		case HOME_OVERVIEW_REQUEST: {
			let nextState =  state.set('isFetching', true)
				.set('error', null)
				.set('shopId', action.payload.shopId);
			return nextState;
		}
		
		case HOME_OVERVIEW_SUCCESS: {
			let nextState =  state.set('isFetching', false)
				.set('error', null)
				.setIn(['overview', 'rank'], action.payload.rank)
				.setIn(['overview', 'rise'], action.payload.rise)
				.setIn(['overview', 'riseCount'], action.payload.riseCount)
				.setIn(['overview', 'goodsCount'], action.payload.goodsCount)
				.setIn(['overview', 'goodsAmount'], action.payload.goodsAmount);
			return nextState;
		}

		case HOME_OVERVIEW_FAILURE:
    	return state.set('isFetching', false)
      		.set('error', action.payload);


    }

    return state;
}