ModifyPasswordContainer.js 3.05 KB
'use strict';

import React from 'react';
import ReactNative 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';

const {
    Component,
} = React;

const {
    View,
    Text,
    StyleSheet,
    Image,
    TextInput,
    Dimensions,
    Alert,
} = ReactNative;

/**
 * ## 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() {
    this.props.actions.pwdModifyOld('');
    this.props.actions.pwdModifyNew('');
     this.props.actions.pwdModifyRepeat('');
  }

  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(){
      if(this.props.user.password.repeat==this.props.user.password.new){
          this.props.actions.pwdModifySubmit(this.props.user.profile.pid,this.props.user.password.old,this.props.user.password.new,this.props.user.password.repeat);
      }else{
       Alert.alert(
              '密码不相同'
            );

    }
  }

	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}
              isFetching={this.props.user.isFetching}
          />

        );
    }
}
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);