orderDetailReducer.js 2.67 KB
'use strict';

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

const {
    SET_ERROR,
    SET_TIP_MESSAGE,

    SET_ORDER_CODE,
    GET_ORDER_DETAIL_REQUEST,
    GET_ORDER_DETAIL_FAILURE,
    GET_ORDER_DETAIL_SUCCESS,

    SET_BANK_SAFE_PAY_VIEW_STATUS,
    SET_CHANGE_BANK_CARD_VIEW_STATUS,
    SET_PAY_CARD,
    SET_SHOW_CONFIRM_PAY_VIEW_STATUS,
    UPDATE_ORDER_INFO_AND_FORMATE_DATA,
    SET_BANK_CARDS_LIST_AND_PAY_CARD,
    UPDATE_REPAY_TERM_LIST,
    UPDATE_PREPAY_SUCCESS_PARAM,

} = 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_ORDER_CODE:
            return state.set('orderCode', action.payload);
        case GET_ORDER_DETAIL_REQUEST:
            return state.set('isFetching', true)
                        .set('error', null);
        case GET_ORDER_DETAIL_FAILURE:
            return state.set('isFetching', false)
                        .set('error', action.payload);
        case GET_ORDER_DETAIL_SUCCESS:
            return state.set('isFetching', false)
                        .set('error', null)
                        .set('orderInfo', Immutable.fromJS(action.payload));
        case SET_BANK_SAFE_PAY_VIEW_STATUS:
            return state.set('showBankSafePayView',action.payload);
        case SET_CHANGE_BANK_CARD_VIEW_STATUS:
            return state.set('showChangeBankView',action.payload);            
        case SET_SHOW_CONFIRM_PAY_VIEW_STATUS:
            return state.set('showConfirmPayView', action.payload);   
        case UPDATE_ORDER_INFO_AND_FORMATE_DATA:
            return state.setIn(['orderInfo', 'package_list'], Immutable.fromJS(action.payload.package_list))
                        .set('formateData', Immutable.fromJS(action.payload.formateData)); 
        case SET_BANK_CARDS_LIST_AND_PAY_CARD:
            return state.set('bankCardsList', Immutable.fromJS(action.payload))
                        .set('payCard', Immutable.fromJS(action.payload[0]));
        case SET_PAY_CARD:
            return state.set('payCard', Immutable.fromJS(action.payload));                        
        case UPDATE_REPAY_TERM_LIST:
            return state.set('repayTermList', Immutable.fromJS(action.payload));
        case UPDATE_PREPAY_SUCCESS_PARAM:
            return state.set('prePaySuccessParam',Immutable.fromJS(action.payload))
                        .set('showConfirmPayView', true);
    }

    return state;
}