transferShipmentReducer.js 2.1 KB

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

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

const {

	GO_TO_OUT_STOCK,
	GO_TO_OUT_DELIVERGOODS,

	GET_PURCHASE_LIST_REQUEST,
	GET_PURCHASE_LIST_SUCCESS,
	GET_PURCHASE_LIST_FAILURE,

	CHECKUP_REQUEST,
	SET_PURCHASE_NUM,
} = 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 GO_TO_OUT_STOCK:{
			return state;
		}
		case GO_TO_OUT_DELIVERGOODS:{
			return state;
		}
		case GET_PURCHASE_LIST_REQUEST:{
			return state.setIn(['purchaseList', 'isFetching'], true)
				.setIn(['purchaseList', 'error'], null)
				.setIn(['purchaseList', 'pageNo'], 0)
                .setIn(['purchaseList', 'totalPage'], 0)
                .setIn(['purchaseList', 'totalCount'], 0)
                .setIn(['purchaseList', 'endReached'], false);
		}
		case GET_PURCHASE_LIST_SUCCESS:{
			let {
				records,
				pageNo,
				totalPage,
				totalCount,
				endReached,
			} = action.payload;

			return state.setIn(['purchaseList', 'isFetching'], false)
					.setIn(['purchaseList', 'error'], null)
					.setIn(['purchaseList', 'records'], Immutable.fromJS(records))
					.setIn(['purchaseList', 'pageNo'], pageNo)
					.setIn(['purchaseList', 'totalPage'], totalPage)
					.setIn(['purchaseList', 'totalCount'], totalCount)
					.setIn(['purchaseList', 'endReached'], endReached);
		}
		case GET_PURCHASE_LIST_FAILURE:{
			return state.setIn(['purchaseList', 'isFetching'], false)
					.setIn(['purchaseList', 'error'], action.payload)
		}
		case CHECKUP_REQUEST:{
			return state.setIn(['purchaseList', 'records'], Immutable.fromJS(action.payload));
		}
		case SET_PURCHASE_NUM:{
			return state.setIn(['purchaseList', 'records'], Immutable.fromJS(action.payload));
		}
		return state;
	}

    return state;
}