This commit is contained in:
Jake McDermott
2018-09-26 20:56:58 -04:00
parent 0986ebef33
commit f8a4b01da5
6 changed files with 1429 additions and 71 deletions

View File

@@ -7,67 +7,59 @@ import api from '../api';
class Login extends Component {
state = {
username: '',
password: '',
redirect: false,
username: '',
password: '',
redirect: false,
};
handleChange = event => this.setState({ [event.target.name]: event.target.value });
handleSubmit = event => {
const { username, password } = this.state;
const { username, password } = this.state;
event.preventDefault();
event.preventDefault();
api.login(username, password)
.then(() => this.setState({ redirect: true }))
.then(() => api.getProjects())
.then(res => console.log(res));
};
.then(() => this.setState({ redirect: true }));
}
render() {
render () {
const { username, password, redirect } = this.state;
if (redirect) {
return (<Redirect to={'/'} />);
}
if (redirect) {
return (<Redirect to="/" />);
}
return (
<div className='column'>
<form onSubmit={this.handleSubmit}>
<div className='field'>
<label className='label'>Username</label>
<div className='control'>
<input
className='input'
type='text'
name='username'
onChange={this.handleChange}
value={username}
required
/>
</div>
</div>
<div className='field'>
<label className='label'>Password</label>
<div className='control'>
<input
className='input'
type='password'
name='password'
onChange={this.handleChange}
value={password}
required
/>
</div>
</div>
<div className='control'>
<Button type='submit'>
Login
</Button>
</div>
</form>
</div>
<form onSubmit={this.handleSubmit}>
<div className="field">
<label htmlFor="username">
Username
<input
id="username"
name="username"
type="text"
onChange={this.handleChange}
value={username}
/>
</label>
</div>
<div>
<label htmlFor="password">
Password
<input
id="password"
name="password"
type="password"
onChange={this.handleChange}
value={password}
/>
</label>
</div>
<Button type="submit">
Login
</Button>
</form>
);
}
}