purchaseCodeReducer.js 1.49 KB
'use strict';

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

const {

	GET_MINE_LIMIT_PURCHASE_LIST_REQUEST,
	GET_MINE_LIMIT_PURCHASE_LIST_SUCCESS,
	GET_MINE_LIMIT_PURCHASE_LIST_FAILURE,

	DELETE_MINE_LIMIT_PURCHASE_REQUEST,
	DELETE_MINE_LIMIT_PURCHASE_SUCCESS,
	DELETE_MINE_LIMIT_PURCHASE_FAILURE,

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

const initialState = new InitialState;

export default function detailReducer(state=initialState, action) {
    switch(action.type) {
    	case GET_MINE_LIMIT_PURCHASE_LIST_REQUEST: {
			return state.set('isFetching', true)
			.set('error', null);
    	}
		case GET_MINE_LIMIT_PURCHASE_LIST_SUCCESS: {
			return state.set('isFetching', false)
			.set('error', null)
			.set('invalidLimitCodeProducts', Immutable.fromJS(action.payload.invalidLimitCodeProducts))
			.set('limitCodeProducts', Immutable.fromJS(action.payload.limitCodeProducts));
		}
		case GET_MINE_LIMIT_PURCHASE_LIST_FAILURE: {
			return state.set('isFetching', false)
			.set('error', action.payload);
		}
		case DELETE_MINE_LIMIT_PURCHASE_REQUEST: {
			return state.set('isFetching', true)
			.set('error', null);
		}
		case DELETE_MINE_LIMIT_PURCHASE_SUCCESS: {
			return state.set('isFetching', false)
			.set('error', null)
			.set('invalidLimitCodeProducts', Immutable.fromJS(action.payload))
		}
		case DELETE_MINE_LIMIT_PURCHASE_FAILURE: {
			return state.set('isFetching', false)
			.set('error', action.payload);
		}
    }
    return state;
}