deliverGoodsReducer.js 2.54 KB

'use strict';
/**
 * ## Imports
 *
 * InitialState
 */
import InitialState from './deliverGoodsInitialState';

import Immutable, {List, Record} from 'immutable';

const {

	LOGOUT,
	DELIVERY_GOODS_REQUEST,
	DELIVERY_GOODS_SUCCESS,
	DELIVERY_GOODS_FAILURE,

	GET_EXPRESS_LIST_REQUEST,
	GET_EXPRESS_LIST_SUCCESS,
	GET_EXPRESS_LIST_FAILURE,

	QUERYBYSUPPLIER_REQUEST,
	QUERYBYSUPPLIER_SUCCESS,
	QUERYBYSUPPLIER_FAILURE,
	SET_EXPRESS_NUM,
	SET_EXPRESS_VALUE,

} = 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 DELIVERY_GOODS_REQUEST:{
			return state;
		}
		case DELIVERY_GOODS_SUCCESS:{
			return state;
		}
		case DELIVERY_GOODS_FAILURE:{
			return state;
		}
		case GET_EXPRESS_LIST_REQUEST:{
			return state.setIn(['expressList', 'isFetching'], true)
				.setIn(['expressList', 'error'], null);
		}
		case GET_EXPRESS_LIST_SUCCESS:{
			return state.setIn(['expressList', 'isFetching'], false)
				.setIn(['expressList', 'error'], null)
				.setIn(['expressList', 'list'], Immutable.fromJS(action.payload));
		}
		case GET_EXPRESS_LIST_FAILURE:{
			return state.setIn(['expressList', 'isFetching'], false)
				.setIn(['expressList', 'error'], action.payload);
		}
		case QUERYBYSUPPLIER_REQUEST:{
			return state.setIn(['storehouse', 'isFetching'], true)
				.setIn(['storehouse', 'error'], null);
		}
		case QUERYBYSUPPLIER_SUCCESS:{
			return state.setIn(['storehouse', 'isFetching'], false)
				.setIn(['storehouse', 'adminName'], action.payload.adminName)
				.setIn(['storehouse', 'address'], action.payload.address)
				.setIn(['storehouse', 'phone'], action.payload.phone)
				.setIn(['storehouse', 'storehouseName'], action.payload.storehouseName)
				.setIn(['storehouse', 'id'], action.payload.id)
				.setIn(['storehouse', 'status'], action.payload.status)
				.setIn(['storehouse', 'error'], null)
		}
		case QUERYBYSUPPLIER_FAILURE:{
			return state.setIn(['storehouse', 'isFetching'], false)
				.setIn(['storehouse', 'error'], action.payload);
		}
		case SET_EXPRESS_NUM:{
			return state.set('expressNum', action.payload);
		}
		case SET_EXPRESS_VALUE:{
			return state.set('expressValue', Immutable.fromJS(action.payload.value))
				.set('deliverData', Immutable.fromJS(action.payload.initialRes));
		}
		return state;
	}

    return state;
}