birthReducer.js 1.4 KB
'use strict';

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

const {
    GET_BIRTH_PRODUCT_REQUEST,
    GET_BIRTH_PRODUCT_SUCCESS,
    GET_BIRTH_PRODUCT_FAILURE,

    SET_SHOW_ALERT_STATUS,
    SET_BIRTH_COUPON_NOT_SUPPORT,

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

const initialState = new InitialState;

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

		case GET_BIRTH_PRODUCT_REQUEST: {
			return state.set('isFetching', true);
		}
		case GET_BIRTH_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_BIRTH_PRODUCT_FAILURE: {
			return state.set('isFetching', false);
		}
		case SET_SHOW_ALERT_STATUS: {
			return state.set('showAlert', action.payload);
		}
		case SET_BIRTH_COUPON_NOT_SUPPORT: {
			return state.set('showAlert', true)
						.set('notSupportReasons', action.payload.not_support_reasons)
						.set('notSupportReasonsTitle', action.payload.not_support_reasons_title)
						.set('notSupportReasonsMessage', action.payload.not_support_reasons_message);
		}		
    }

    return state;
}