File size: 2,044 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import React from 'react';
import {withRouter} from 'react-router-dom';
class LoginForm extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      email: "",
      password: ""
    };
    this.handleSubmit = this.handleSubmit.bind(this);
  }


  handleSubmit(e) {
    e.preventDefault();
    const user = Object.assign({}, this.state);
    this.props.processForm(user);
  }


  update(field) {
    return (e) => {
      e.preventDefault();
      this.setState({[field]: e.target.value});
    };
  }

  renderLogin(){
    const errors = this.props.errors;
    const {formType} = this.props;
    if(formType === "LOGIN"){
    return(
        <div>

        <form onSubmit={this.handleSubmit}>
          <div className="login-label-div">
          <label> Email
          <div className="tooltip">
          <input  type="text"
             className={errors.loginErrors.length > 0 ? 'error' : ''}
             value={this.state.email}
             onChange={this.update('email')} />
          {this.renderErrors()}
           </div>
          </label>
        </div>
          <div className="login-label-div">
          <label> Password
            <div className="tooltip">
            <input type="password"
               className={errors.loginErrors.length > 0 ? 'error' : ''}
               value={this.state.password}
               onChange={this.update('password')} />
             {this.renderErrors()}
             </div>
             <a href="#" className="forgot-password deadlinks">Forgot account?</a>
          </label>
          </div>
          <button type="submit" value={formType}>Log In</button>
         </form>

       </div>
    );
  }
  }

  renderErrors(){
    const {errors} = this.props;
    if (errors.loginErrors.length > 0){
    return (<span className="tooltiptext">
              Incorrect email or password
            </span>);
    }
  }

  render(){
    const {formType} = this.props;

    return(
      this.renderLogin()
    );
  }
}

export default withRouter(LoginForm);