repayListReducer.js 2.42 KB
'use strict';

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

const {
    SET_QUERY_DAYS,
    SET_ERROR,

    QUERY_REPAYMENT_LIST_REQUEST,
    QUERY_REPAYMENT_LIST_FAILURE,
    QUERY_REPAYMENT_LIST_SUCCESS,
    SET_FORMATE_DATA,
    SET_TIP_MESSAGE,
    UPDATE_REPAYMENT_LIST_AND_FORMATE_DATA,
    SET_BANK_CARDS_LIST_AND_PAY_CARD,
    SET_BANK_SAFE_PAY_VIEW_STATUS,
    UPDATE_REPAY_TERM_LIST,
    UPDATE_PREPAY_SUCCESS_PARAM,
    SET_SHOW_CONFIRM_PAY_VIEW_STATUS,

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

const initialState = new InitialState;

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

    switch (action.type) {
        case SET_QUERY_DAYS:
            return state.set('queryDays', action.payload);
        case QUERY_REPAYMENT_LIST_REQUEST:
            return state.set('isFetching', true)
            .set('error', null);
        case SET_ERROR:
        case QUERY_REPAYMENT_LIST_FAILURE:
            return state.set('isFetching', false)
            .set('error',action.payload);
        case UPDATE_REPAYMENT_LIST_AND_FORMATE_DATA:
            return state.set('repaymentList', Immutable.fromJS(action.payload.repaymentList))
            .set('formateData', Immutable.fromJS(action.payload.formateData));
        case QUERY_REPAYMENT_LIST_SUCCESS:
            return state.set('repaymentList', Immutable.fromJS(action.payload))
            .set('isFetching', false);
        case SET_FORMATE_DATA:
            return state.set('formateData', Immutable.fromJS(action.payload));
        case SET_TIP_MESSAGE:
            return state.set('tipMessage', action.payload);
        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_BANK_SAFE_PAY_VIEW_STATUS:
            return state.set('showBankSafePayView',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);
        case SET_SHOW_CONFIRM_PAY_VIEW_STATUS:
            return state.set('showConfirmPayView', action.payload);
    }

    return state;
}