Advertisement
Guest User

Untitled

a guest
Jul 12th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {Component} from 'react'
  2. import PropTypes from 'prop-types'
  3. import { connect } from 'react-redux'
  4.  
  5. import classnames from 'classnames/bind'
  6. import styles from './styles.scss'
  7. const cx = classnames.bind(styles)
  8.  
  9. import { NavLink } from 'react-router-dom'
  10. import {checkLogin, testRequest, searchUserbyId} from 'api'
  11.  
  12. export class Login extends Component {
  13.  
  14.   state = {
  15.     Username: '',
  16.     Password: '',
  17.     isLogin: false
  18.   }
  19.  
  20.   static propTypes = {
  21.     Id: PropTypes.number.isRequired,
  22.     FirstName: PropTypes.string.isRequired,
  23.     LastName: PropTypes.string.isRequired,
  24.     Email: PropTypes.string.isRequired,
  25.     Phone: PropTypes.string.isRequired,
  26.     mapStateToProps: PropTypes.func.isRequired
  27.   }
  28.  
  29.   static defaultProps = {
  30.     Id: 1,
  31.     FirstName: 'Иван',
  32.     LastName: 'Иванов',
  33.     Email: '123@456.789',
  34.     Phone: '89275658358'
  35.   }
  36.  
  37.   onChange = (key, value) => {
  38.     this.setState({
  39.       [key]: value
  40.     });
  41.   }
  42.  
  43. onLogin = (Username, Password) => {
  44.   checkLogin(Username, Password)
  45.   .then(result => {
  46.     console.log(result);
  47.     console.log('Раскомментить и убрать лог(onLogin)');
  48.     //onChange("isLogin", result)
  49.   })
  50. }
  51.  
  52. testbtnRequest = (Id) => {
  53.   searchUserbyId(Id)
  54.   .then(result => {
  55.     console.log(result);
  56.   })
  57. }
  58.  
  59.  
  60.   render() {
  61.     return (
  62.       <div>
  63.       <form id="login">
  64.         <h1>Форма входа</h1>
  65.         <fieldset id="inputs">
  66.           <input id="username" type="text" placeholder="Email" autoFocus required onChange={(event) => {this.onChange("Username", event.target.value)}}/>
  67.           <input id="password" type="password" placeholder="Пароль" required onChange={(event) => {this.onChange("Password", event.target.value)}}/>
  68.         </fieldset>
  69.         <fieldset id="actions">
  70.           <button id="submit" onClick={(e) => {
  71.             e.preventDefault();
  72.             this.onLogin(this.state.Username, this.state.Password)
  73.           }}>ВОЙТИ</button>
  74.           <a href="" onClick={(e) => {
  75.             e.preventDefault();
  76.             this.testbtnRequest(2)
  77.           }}>Забыли пароль?</a>
  78.           <NavLink exact activeClassName = 'active' to='/registration'>
  79.             Регистрация
  80.           </NavLink>
  81.         </fieldset>
  82.       </form>
  83.       <div>{ this.props.loginParams }</div>
  84.       </div>
  85.   )
  86.   }
  87. }
  88.  
  89. mapStateToProps = (state) => {
  90.   return {
  91.     loginParams: state
  92.   }
  93. }
  94.  
  95. export default connect(mapStateToProps)(Login)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement