addCouponReducer.js 955 Bytes
'use strict';

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

const {
	ADD_COUPON_REQUEST,
	ADD_COUPON_SUCCESS,
	ADD_COUPON_FAILURE,

	RESETRECEIVECOUPONRES,

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

const initialState = new InitialState;

export default function detailReducer(state=initialState, action) {
    switch(action.type) {
    	case ADD_COUPON_REQUEST: {
			return state.set('isFetching', true)
			.set('error', null);
    	}
		case ADD_COUPON_SUCCESS: {
			return state.set('isFetching', false)
			.set('message', '领取成功')
			.set('showMessage', true);
    	}
		case ADD_COUPON_FAILURE: {
			return state.set('isFetching', false)
			.set('error', action.payload)
			.set('message', action.payload.message)
			.set('showMessage', true);
    	}
		case RESETRECEIVECOUPONRES: {
			return state.set('message', '').set('showMessage', false);
		}
		break;
    }
    return state;
}