yearActivityReducer.js 1.21 KB
'use strict';

import InitialState from './yearActivityInitialState';
import Immutable, {Map} from 'immutable';

const {
	SET_TYPE,

	SET_SIMILAR_PRODUCT_INDEX,

    GET_YEARACTIVITY_PRODUCT_REQUEST,
    GET_YEARACTIVITY_PRODUCT_SUCCESS,
    GET_YEARACTIVITY_PRODUCT_FAILURE,

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

const initialState = new InitialState;

export default function yearActivityReducer(state=initialState, action) {
    switch(action.type) {

		case SET_TYPE: {
			return state.set('type', action.payload);
		}
		case SET_SIMILAR_PRODUCT_INDEX: {
			return state.set('similarIndex', action.payload.rowID);
		}
		case GET_YEARACTIVITY_PRODUCT_REQUEST: {
			return state.set('isFetching', true);
		}
		case GET_YEARACTIVITY_PRODUCT_SUCCESS:{

			let json = action.payload;
			return state.set('isFetching', false)
			            .set('list', Immutable.fromJS(json.list))
			            .set('currentPage', json.currentPage)
                        .set('pageCount', json.pageCount)
                        .set('total', json.total)
                        .set('endReached', json.endReached);
		}
		case GET_YEARACTIVITY_PRODUCT_FAILURE: {
			return state.set('isFetching', false);
		}
    }

    return state;
}