InstallmentMyCardContainer.js 2.26 KB
'use strict'

import React, {Component} from 'react';
import {
    StyleSheet,
    Dimensions,
    Platform,
    View,
    NativeModules,
    InteractionManager,
    DeviceEventEmitter,
    Text,
    ListView,
    TouchableOpacity,
} from 'react-native'

import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as cardListActions from '../reducers/bankCardList/cardListActions';
import ServerError from '../components/installment/ServerError';
import BankCardList from '../components/installment/BankCardList';


const actions = [
    cardListActions,
];
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 InstallmentMyCardContainer extends Component {

    constructor(props) {
        super(props);
        this.onPressCard = this.onPressCard.bind(this);
        this._reloadPage = this._reloadPage.bind(this);

        this.subscription = DeviceEventEmitter.addListener(
            'BankCardChangeEvent',
            () => {
                this._reloadPage();
            }
        );
    }

    _reloadPage() {
        this.props.actions.getBankCards();
    }

    componentDidMount() {
        this.props.actions.getBankCards();
    }

    componentWillUnmount(){
        this.subscription && this.subscription.remove();
    }

    onPressCard(cardIdNo){
        this.props.actions.goMyCardDetail(cardIdNo);
    }

    render() {

        let {cardList} = this.props.myCardList;
        let {error} = cardList;
        if (error) {
            return (
                <ServerError
                    reloadPage={this._reloadPage}
                />
            );
        }

        return (
            <BankCardList
                style={styles.container}
                cardList={cardList}
                onPressCard={this.onPressCard}

            />
        );
    }
}
let styles = StyleSheet.create({
    container: {
        flex: 1,
    },


});

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