PersonalInfoContainer.js 1.78 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 personalInfoActions from '../reducers/personalInfo/personalInfoActions';

import PersonalInfo from '../components/PersonalInfo';


const actions = [
    personalInfoActions,
];

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 PersonalInfoContainer extends Component {
    constructor(props) {
        super(props);
        this._onPressInfoCell = this._onPressInfoCell.bind(this);
    }

    _onPressInfoCell(cellInfo) {
        this.props.actions.onPressInfoCell(cellInfo);
    }

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

    componentWillUnmount() {
        this.props.actions.modifyUserBaseInfo();
    }

    render() {
        let {personalInfo} = this.props;
        let {pageCellList} = personalInfo;
        return (
            <View style={styles.container}>
                <PersonalInfo
                    dataSource={pageCellList}
                    onPressInfoCell={this._onPressInfoCell}
                />
            </View>
        );
    }
}

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

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