fastExpressReducer.js 1.55 KB
'use strict';

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

const {
	SET_TYPE,

	SET_SIMILAR_PRODUCT_INDEX,

	GET_FASTEXPRESS_INFO_REQUEST,
    GET_FASTEXPRESS_INFO_SUCCESS,
    GET_FASTEXPRESS_INFO_FAILURE,

    GET_FASTEXPRESS_PRODUCT_REQUEST,
    GET_FASTEXPRESS_PRODUCT_SUCCESS,
    GET_FASTEXPRESS_PRODUCT_FAILURE,

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

const initialState = new InitialState;

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

		case SET_SIMILAR_PRODUCT_INDEX: {
			return state.set('similarIndex', action.payload.rowID);
		}

		case GET_FASTEXPRESS_INFO_REQUEST: {
			return state.set('isFetching', true);
		}
		case GET_FASTEXPRESS_INFO_SUCCESS:{
			return state.set('isFetching', false)
			            .set('fastExpressList', Immutable.fromJS(action.payload));
		}
		case GET_FASTEXPRESS_INFO_FAILURE: {
			return state.set('isFetching', true);
		}

		case GET_FASTEXPRESS_PRODUCT_REQUEST: {
			return state.set('isFetching', true);
		}
		case GET_FASTEXPRESS_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_FASTEXPRESS_PRODUCT_FAILURE: {
			return state.set('isFetching', false);
		}
    }

    return state;
}