Advertisement
brianq0

loginSignup.js

Feb 23rd, 2019
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import './loginSignup';
  3. import { connect } from 'react-redux';
  4. import { userLogin, logOut, createNewUser } from '../../actions/userAuthActions';
  5.  
  6. class Login extends Component {
  7.   state = {
  8.     userLogin: '',
  9.     pwLogin: '',
  10.     userSignUp: '',
  11.     pwSignUp: '',
  12.   };
  13.  
  14.   onChange = e => {
  15.     const { name, value } = e.target;
  16.     this.setState({ [name]: value });
  17.   };
  18.  
  19.   render() {
  20.     console.log('rerendering login/signup', this.props);
  21.     const { userAuth } = this.props;
  22.     return (
  23.       <div className="login-signup-container">
  24.         {!userAuth.loggedIn && (
  25.           <div className="login-container">
  26.             <button onClick={this.testing}>console.log userSignup Props</button>
  27.  
  28.             <form action="">
  29.               Login:
  30.               <label htmlFor="userLogin">Username: </label>
  31.               <input
  32.                 onChange={this.onChange}
  33.                 name="userLogin"
  34.                 id="userLogin"
  35.                 type="text"
  36.                 value={this.state.username}
  37.                 autoComplete="username"
  38.               />
  39.               <label htmlFor="pwLogin">Password: </label>
  40.               <input
  41.                 onChange={this.onChange}
  42.                 name="pwLogin"
  43.                 id="pwLogin"
  44.                 type="password"
  45.                 value={this.state.pwLogin}
  46.                 autoComplete="current-password"
  47.               />
  48.               <button onClick={this.logIn} type="submit">
  49.                 Login
  50.               </button>
  51.             </form>
  52.           </div>
  53.         )}
  54.         {userAuth.showStatus && <p>{userAuth.message}</p>}
  55.         <br />
  56.  
  57.         {!userAuth.loggedIn && (
  58.           <div className="signup-container">
  59.             <form action="">
  60.               Sign Up:
  61.               <label htmlFor="userSignUp">Username: </label>
  62.               <input
  63.                 onChange={this.onChange}
  64.                 name="userSignUp"
  65.                 id="userSignUp"
  66.                 type="text"
  67.                 value={this.state.userSignUp}
  68.                 autoComplete="username"
  69.               />
  70.               <label htmlFor="pwSignUp">Password: </label>
  71.               <input
  72.                 onChange={this.onChange}
  73.                 name="pwSignUp"
  74.                 id="pwSignUp"
  75.                 type="password"
  76.                 value={this.state.pwSignUp}
  77.                 autoComplete="current-password"
  78.               />
  79.               <button onClick={this.signUp} type="submit">
  80.                 Sign Up
  81.               </button>
  82.             </form>
  83.           </div>
  84.         )}
  85.  
  86.         <button onClick={this.logOut}>Log Out</button>
  87.       </div>
  88.     );
  89.   }
  90. }
  91. const mapStateToProps = state => ({
  92.   userLifts: state.userLifts,
  93.   userAuth: state.userAuth,
  94. });
  95. export default connect(mapStateToProps)(Login);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement