File size: 2,253 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 SessionForm extends React.Component {
constructor(props) {
super(props);
this.state = this.props.loginInfo;
this.handleSubmit = this.handleSubmit.bind(this);
}
renderErrors(errors) {
const loginErrors = document.getElementById("login-errors")
while (loginErrors.firstChild) {
loginErrors.firstChild.remove();
}
loginErrors.appendChild(document.createTextNode(errors.errors.responseJSON))
}
handleSubmit(e) {
e.preventDefault();
this.props.login(this.state).then(
null,
errors => this.renderErrors(errors)
);
}
handleChange(field) {
return e => this.setState({[field]: e.target.value});
}
render() {
return (
<div className={"login-container"}>
<div id="login-errors"></div>
<form onSubmit={this.handleSubmit}>
<table>
<tbody>
<tr>
<td>
<label htmlFor="email">Email or Phone</label>
</td>
<td>
<label htmlFor="password">Password</label>
</td>
</tr>
<tr>
<td>
<input
type="text"
id="login-email"
onChange={this.handleChange('email')}
/>
</td>
<td>
<input
type="password"
id="login-password"
onChange={this.handleChange('password')}
/>
</td>
<td>
<label className="login-button">
<input
type="submit"
value="Log In"
/>
</label>
</td>
</tr>
<tr>
<td />
<td>
<label>
<a href="#">Forgot account?</a>
</label>
</td>
</tr>
</tbody>
</table>
</form>
</div>
);
}
}
export default withRouter(SessionForm);
|