cardAddReducer.js 2.02 KB
'use strict';

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

const {
    SHOW_BANK_INFO,
    SHOW_RESULT_INFO,
    RESET_CARD_ADD_INFO,
    SET_USER_NAME,
} = require('../../constants/actionTypes').default;

const initialState = new InitialState;

export default function cardAddReducer(state = initialState, action) {
    //if (!(state instanceof InitialState)) return initialState.merge(state);

    switch (action.type) {
        case SET_USER_NAME:
            return state.set('userName', action.payload)        
        case SHOW_BANK_INFO:
            return state.set('bankCode', action.payload.bankCode)
                        .set('bankName', action.payload.bankName)
                        .set('cardNO', action.payload.cardNO)
                        .set('bankSupport', action.payload.bankSupport)
                        .set('showBankInfo', action.payload.showBankInfo);
        case SHOW_RESULT_INFO:
            return state.set('showResult', action.payload.showResult)
                        .set('result', action.payload.result)
                        .set('message', action.payload.message)
                        .set('description', action.payload.description)
                        .set('buttonText', action.payload.buttonText);
        case RESET_CARD_ADD_INFO:
            return state.set('bankCode', action.payload.bankCode)
                        .set('bankName', action.payload.bankName)
                        .set('cardNO', action.payload.cardNO)
                        .set('bankSupport', action.payload.bankSupport)
                        .set('showBankInfo', action.payload.showBankInfo)
                        .set('showResult', action.payload.showResult)
                        .set('result', action.payload.result)
                        .set('message', action.payload.message)
                        .set('description', action.payload.description)
                        .set('buttonText', action.payload.buttonText);                        
    }

    return state;
}