UserLogoutContainer.js 6.36 KB
/**
 * sub app userLogout
 * @author: lixia.zhang
 * @date: 2018/04/17
 */

'use strict'

import React, {Component} from 'react';
import {
    StyleSheet,
    Dimensions,
} from 'react-native'

import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as userLogoutActions from '../reducers/userLogout/userLogoutActions';
import UserLogout from '../components/userLogout/UserLogout';
import UserLogoutFailed from '../components/userLogout/UserLogoutFailed';
import UserLogoutStatus from '../components/userLogout/UserLogoutStatus';
import LoadingIndicator from '../../common/components/LoadingIndicator';

const actions = [
    userLogoutActions,
];

function mapStateToProps(state) {
    return {
        ...state
    };
}

function mapDispatchToProps(dispatch) {

    const creators = Map()
        .merge(...actions)
        .filter(value => typeof value === 'function')
        .toObject();

    return {
        actions: bindActionCreators(creators, dispatch),
        dispatch
    };
}

class UserLogoutContainer extends Component {
    constructor(props) {
        super(props);
        this._onPressLogoutClause = this._onPressLogoutClause.bind(this);
        this._gotoReapply = this._gotoReapply.bind(this);
        this._enableSubmitBtn = this._enableSubmitBtn.bind(this);
        this._showLogoutReasonModalAction = this._showLogoutReasonModalAction.bind(this);
        this._fetchCanleCode = this._fetchCanleCode.bind(this);
        this._confirmLogout = this._confirmLogout.bind(this);
        this._changeImageCode = this._changeImageCode.bind(this);
        this._onPromptHidden = this._onPromptHidden.bind(this);
        this._gotoLogoutStatus = this._gotoLogoutStatus.bind(this);
        this._hiddenTipModalstate = this._hiddenTipModalstate.bind(this);
        this._naviBackAction = this._naviBackAction.bind(this);
        this._gotoUserLogout = this._gotoUserLogout.bind(this);
        this._gotoOnlineService = this._gotoOnlineService.bind(this);
    }
    componentWillMount() {
        this.props.actions.checkUserLogedIn();
        this.props.actions.fetchUserProfile();
        this.props.actions.fetchImageCheckSwitchState();
    }


    componentWillUnmount() {

    }
    _onPressLogoutClause() {
        this.props.actions.onPressLogoutClause();
    }

    _gotoReapply(){
        this.props.actions.gotoReapply();
    }

    _enableSubmitBtn(state) {
        this.props.actions.enableSubmitBtn(state);
    }

    _showLogoutReasonModalAction(state) {
        if(state){
            this.props.actions.generateCheckImageUrl();
        }
        this.props.actions.showLogoutReasonModal(state);
    }

    _fetchCanleCode(mobile, degrees) {
        this.props.actions.fetchCanleCode(mobile, degrees);
    }

    _changeImageCode() {
        this.props.actions.generateCheckImageUrl();
    }

    _confirmLogout(code, reason) {
        this.props.actions.confirmLogout(code, reason);
    }

    _onPromptHidden() {
        this.props.actions.updateTipMessage('');
    }

    _gotoLogoutStatus(){
        this.props.actions.gotoLogoutStatus();
    }

    _hiddenTipModalstate(){
        this.props.actions.hiddenTipModalstate()
    }

    _naviBackAction(){
        this.props.actions.naviBackAction()
    }

    _gotoUserLogout(){
        this.props.actions.gotoUserLogout()
    }

    _gotoOnlineService(){
        this.props.actions.gotoOnlineService();
    }

    render() {
        let {submitBtnEnable,
            showModalFlag,
            imageCheckSwitchState,
            imageCheckCodeUrl,
            tipMessage,
            succeedSendCode,
            codeSendMessage,
            showTipModal,
            hasValidMobile,
            logoutStatus,
            cancelFailedDesc,
            isFetching
        } = this.props.userLogout;
        cancelFailedDesc = cancelFailedDesc.toJS();
        if (logoutStatus == 0 || this.props.reapply) {
            if (isFetching) {
                return (
                    <LoadingIndicator isVisible={isFetching}/>
                );
            } else {
                return (
                    <UserLogout
                        onPressLogoutClause = {this._onPressLogoutClause}
                        gotoReapply={this._gotoReapply}
                        enableSubmitBtn={this._enableSubmitBtn}
                        showLogoutReasonModalAction={this._showLogoutReasonModalAction}
                        fetchCanleCode={this._fetchCanleCode}
                        confirmLogout={this._confirmLogout}
                        changeImageCode={this._changeImageCode}
                        onPromptHidden={this._onPromptHidden}
                        gotoLogoutStatus={this._gotoLogoutStatus}
                        hiddenTipModalstate={this._hiddenTipModalstate}
                        naviBackAction={this._naviBackAction}
                        gotoOnlineService={this._gotoOnlineService}
                        submitBtnEnable={submitBtnEnable}
                        showModalFlag={showModalFlag}
                        imageCheckSwitchState={imageCheckSwitchState}
                        imageCheckCodeUrl={imageCheckCodeUrl}
                        tipMessage={tipMessage}
                        succeedSendCode={succeedSendCode}
                        codeSendMessage={codeSendMessage}
                        showTipModal={showTipModal}
                        hasValidMobile={hasValidMobile}
                    />
                );
            }

        } else if(logoutStatus == 1){
            if (isFetching) {
                return (
                    <LoadingIndicator isVisible={isFetching}/>
                );
            } else {
                return (
                    <UserLogoutStatus
                    />
                )
            }

        }else if(logoutStatus == 3){
            if (isFetching) {
                return (
                    <LoadingIndicator isVisible={isFetching}/>
                );
            } else {
                return (
                    <UserLogoutFailed
                        gotoReapply={this._gotoReapply}
                        gotoUserLogout={this._gotoUserLogout}
                        gotoOnlineService={this._gotoOnlineService}
                        cancelFailedDesc={cancelFailedDesc}
                    />
                )
            }
        }

    }
}

export default connect(mapStateToProps, mapDispatchToProps)(UserLogoutContainer);