Skip to content

Commit

Permalink
Turn login div into form to allow using enter
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jan 1, 2020
1 parent 6bc6a08 commit 9ee0e09
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions maubot/management/frontend/src/pages/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class Login extends Component {

inputChanged = event => this.setState({ [event.target.name]: event.target.value })

login = async () => {
login = async evt => {
evt.preventDefault()
this.setState({ loading: true })
const resp = await api.login(this.state.username, this.state.password)
if (resp.token) {
Expand All @@ -53,17 +54,17 @@ class Login extends Component {
</div>
}
return <div className="login-wrapper">
<div className={`login ${this.state.error && "errored"}`}>
<form className={`login ${this.state.error && "errored"}`} onSubmit={this.login}>
<h1>Maubot Manager</h1>
<input type="text" placeholder="Username" value={this.state.username}
name="username" onChange={this.inputChanged}/>
<input type="password" placeholder="Password" value={this.state.password}
name="password" onChange={this.inputChanged}/>
<button onClick={this.login}>
<button onClick={this.login} type="submit">
{this.state.loading ? <Spinner/> : "Log in"}
</button>
{this.state.error && <div className="error">{this.state.error}</div>}
</div>
</form>
</div>
}
}
Expand Down

0 comments on commit 9ee0e09

Please sign in to comment.