Login.jsx 1001B

12345678910111213141516171819202122232425262728293031323334353637
  1. import React from 'react'
  2. import { connect } from 'react-redux'
  3. import { ConnectionForm } from '../component/ConnectionForm.jsx'
  4. import { userLogin } from '../action-creator.async.js'
  5. class Login extends React.Component {
  6. constructor (props) {
  7. super(props)
  8. this.state = {
  9. inputLogin: '',
  10. inputPassword: ''
  11. }
  12. }
  13. handleChangeLogin = e => this.setState({inputLogin: e.target.value})
  14. handleChangePassword = e => this.setState({inputPassword: e.target.value})
  15. handleClickSubmit = () => this.props.dispatch(userLogin(this.state.inputLogin, this.state.inputPassword))
  16. render () {
  17. const { user } = this.props
  18. return (
  19. <div>
  20. <ConnectionForm
  21. user={user}
  22. onChangeLogin={this.handleChangeLogin}
  23. onChangePassword={this.handleChangePassword}
  24. onClickSubmit={this.handleClickSubmit}
  25. />
  26. </div>
  27. )
  28. }
  29. }
  30. const mapStateToProps = ({ user }) => ({ user })
  31. export default connect(mapStateToProps)(Login)