PurchaseCodeContainer.js 1.76 KB
'use strict'

import React, {Component} from 'react';
import ReactNative, {
    StyleSheet,
    Dimensions,
    Platform,
    View,
    Text,
    NativeModules,
    InteractionManager,
    NativeAppEventEmitter,
} from 'react-native'

import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as purchaseCodeActions from '../reducers/purchaseCode/purchaseCodeActions';
import PurchaseCode from '../components/purchaseCode/PurchaseCode';

const actions = [
    purchaseCodeActions,
];

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 PurchaseCodeContainer extends Component {
    constructor(props) {
        super(props);
        this.subscription = NativeAppEventEmitter.addListener(
            'purchaseListChange',
            (reminder) => {
                this.props.actions.getMineLimitPurchaseList();
            }
        );
    }

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

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

    render() {
        let {purchaseCode} = this.props;

        return (
            <View style={styles.container}>
                <PurchaseCode
                    resource={purchaseCode}
                />
            </View>
        );
    }
}

let styles = StyleSheet.create({
    container: {
        flex: 1,
    },

});

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