cardDetailReducer.js 1.61 KB
'use strict';

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

const {
    SET_ERROR,
    SET_TIP_MESSAGE,
    SET_CARD_ID_NO,

    GET_CARD_DETAIL_REQUEST,
    GET_CARD_DETAIL_FAILURE,
    GET_CARD_DETAIL_SUCCESS,

    UNBIND_CARD_SUCCESS,
    TOGGLE_CARD_SUCCESS,

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

const initialState = new InitialState;

export default function appReducer(state = initialState, action) {

    switch (action.type) {

        case SET_ERROR:
            return state.set('error',action.payload);
        case SET_TIP_MESSAGE:
            return state.set('tipMessage', action.payload);
        case SET_CARD_ID_NO:
            return state.set('cardIdNo', action.payload);            
        case GET_CARD_DETAIL_REQUEST:
            return state.set('isFetching', true)
                        .set('error', null);
        case GET_CARD_DETAIL_FAILURE:
            return state.set('isFetching', false)
                        .set('error', action.payload);
        case GET_CARD_DETAIL_SUCCESS:
            return state.set('isFetching', false)
                        .set('error', null)
                        .set('cardInfo', Immutable.fromJS(action.payload));
        case UNBIND_CARD_SUCCESS:
            return state.set('showToast', true)
                        .set('showToastText', "解除成功!");
        case TOGGLE_CARD_SUCCESS:
            return state.set('showToast', true)
                        .setIn(['cardInfo', "masterType"], "1")
                        .set('showToastText', "切换成功!");       

    }

    return state;
}