ModifyPasswordContainer.js 2.78 KB
'use strict';

import React from 'react-native';

import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';

import {Map} from 'immutable';

import * as userActions from '../reducers/user/userActions';
import * as deviceActions from '../reducers/device/deviceActions';
import ModifyPassword from '../components/ModifyPassword';

let {
    Component,
    View,
    Text,
    StyleSheet,
    Image,
    TextInput,
    Dimensions,
    Alert
} = React;

/**
 * ## Actions
 * 3 of our actions will be available as ```actions```
 */
const actions = [
    userActions,
    deviceActions,
];

/**
 *  Save that state
 */
function mapStateToProps(state) {
    return {
        ...state
    };
};

/**
 * Bind all the functions from the ```actions``` and bind them with
 * ```dispatch```
 */
function mapDispatchToProps(dispatch) {

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

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

export default class ModifyPasswordContainer extends Component {

    constructor(props) {
        super(props);
        this.onModifyOldPwd = this.onModifyOldPwd.bind(this);
        this.onModifyNewPwd = this.onModifyNewPwd.bind(this);
        this.onModifyRepeatPwd = this.onModifyRepeatPwd.bind(this);
        this.onModifySubmitPress = this.onModifySubmitPress.bind(this);
    }

  componentDidMount() {

  }

  componentWillUnmount() {

  }

  onModifyOldPwd(text:string){
    this.props.actions.pwdModifyOld(text);
  }

  onModifyNewPwd(text:string){
    this.props.actions.pwdModifyNew(text);
  }

  onModifyRepeatPwd(text:string){
    this.props.actions.pwdModifyRepeat(text);
  }

  onModifySubmitPress(){
    Alert.alert(
              '修改密码',
              this.props.user.password.old+'+'+this.props.user.password.new+'+'+this.props.user.password.repeat,
              [
                {text: 'OK', onPress: () => this.props.actions.pwdModifySubmit()},
              ]
            );
  }

	render() {
        return (
          <ModifyPassword 
              oldPwd={this.props.user.password.old}
              newPwd={this.props.user.password.new}
              repeatPwd={this.props.user.password.repeat}
              onModifyOldPwd={this.onModifyOldPwd}
              onModifyNewPwd={this.onModifyNewPwd}
              onModifyRepeatPwd={this.onModifyRepeatPwd}
              onModifySubmitPress={this.onModifySubmitPress}
          />

        );
    }
}
let {height, width} = Dimensions.get('window');
let textPaddingTop = height * 7 / 10;
let buttonMargin = (width - 165) / 2;
var styles = StyleSheet.create({

});

/**
 * Connect the properties
 */
export default connect(mapStateToProps, mapDispatchToProps)(ModifyPasswordContainer);