fathom/assets/js/components/LoginForm.js

65 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-11-23 18:40:35 +00:00
'use strict';
import { h, render, Component } from 'preact';
import Client from '../lib/client.js';
import Notification from '../components/Notification.js';
2016-11-23 18:40:35 +00:00
class LoginForm extends Component {
constructor(props) {
super(props)
this.handleSubmit = this.handleSubmit.bind(this);
this.state = {
2016-11-23 18:40:35 +00:00
email: '',
password: '',
message: ''
}
2016-11-23 18:40:35 +00:00
}
handleSubmit(e) {
e.preventDefault();
Client.request('session', {
2016-11-23 18:40:35 +00:00
method: "POST",
data: {
email: this.state.email,
password: this.state.password,
}
}).then((r) => {
this.props.onSuccess()
}).catch((e) => {
this.setState({
message: e.message,
password: ''
})
})
2016-11-23 18:40:35 +00:00
}
render() {
return (
<div class="block">
<h2>Login</h2>
<p>Please enter your credentials to access your Ana dashboard.</p>
<form method="POST" onSubmit={this.handleSubmit}>
<div class="small-margin">
2016-11-23 18:40:35 +00:00
<label>Email address</label>
<input type="email" name="email" placeholder="Email address" value={this.state.email} onChange={this.linkState('email')} required="required" />
2016-11-23 18:40:35 +00:00
</div>
<div class="small-margin">
2016-11-23 18:40:35 +00:00
<label>Password</label>
<input type="password" name="password" placeholder="**********" value={this.state.password} onChange={this.linkState('password')} required="required" />
2016-11-23 18:40:35 +00:00
</div>
<div class="small-margin">
2016-11-23 18:40:35 +00:00
<input type="submit" value="Sign in" />
</div>
</form>
<Notification message={this.state.message} kind="" />
2016-11-23 18:40:35 +00:00
</div>
2016-11-23 18:40:35 +00:00
)
}
}
export default LoginForm