This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Implement a basic signup form
- Loading branch information
Showing
5 changed files
with
145 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import React from "react"; | ||
import { RouteComponentProps as RCP } from "react-router-dom"; | ||
|
||
import req from "../axios"; | ||
|
||
import strings from "./assets/locales"; | ||
|
||
import "./styles/signupForm.scss"; | ||
|
||
enum Status { | ||
FAILED, | ||
SUCCESS, | ||
UNDEFINED, | ||
} | ||
interface State { | ||
name: string; | ||
password: string; | ||
status: Status; | ||
} | ||
|
||
class SignupForm extends React.PureComponent<RCP, State> { | ||
state = { | ||
name: "", | ||
password: "", | ||
status: Status.UNDEFINED, | ||
}; | ||
componentDidUpdate = () => { | ||
if (this.state.status === Status.SUCCESS) { | ||
setTimeout(() => { | ||
this.props.history.push("/"); | ||
}, 5000); | ||
} | ||
}; | ||
signup = () => { | ||
// prettier-ignore | ||
req.post("/signup", { | ||
name: this.state.name, | ||
password: this.state.password, | ||
}) | ||
.then( | ||
() => this.setState({ status: Status.SUCCESS }), | ||
() => this.setState({ status: Status.FAILED }) | ||
); | ||
}; | ||
goBack = () => this.props.history.push("/"); | ||
updateName = (e: React.FormEvent<HTMLInputElement>) => | ||
this.setState({ name: e.currentTarget.value }); | ||
updatePassword = (e: React.FormEvent<HTMLInputElement>) => | ||
this.setState({ password: e.currentTarget.value }); | ||
render = () => { | ||
return ( | ||
<div className="container signup_form"> | ||
<form className="signupForm"> | ||
<div className="field"> | ||
<label className="label"> | ||
{strings.login_userNameTp} | ||
</label> | ||
<div className="control"> | ||
<input | ||
type="text" | ||
autoFocus | ||
className="input" | ||
onChange={this.updateName} | ||
/> | ||
</div> | ||
</div> | ||
<div className="field"> | ||
<label className="label"> | ||
{strings.login_passwordTp} | ||
</label> | ||
<div className="control"> | ||
<input | ||
className="input" | ||
type="password" | ||
onChange={this.updatePassword} | ||
/> | ||
</div> | ||
</div> | ||
<div className="level is-mobile"> | ||
<div className="level-item level-left"> | ||
<div className="control"> | ||
<input | ||
type="button" | ||
className="button" | ||
value={strings.login_signupBtn} | ||
onClick={this.signup} | ||
/> | ||
</div> | ||
</div> | ||
<div className="level-item level-right"> | ||
<div className="control"> | ||
<input | ||
type="button" | ||
className="button" | ||
value={strings.login_goBackBtn} | ||
onClick={this.goBack} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
); | ||
}; | ||
} | ||
|
||
export default SignupForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@import "./common.scss"; | ||
|
||
form.signupForm { | ||
max-width: 320px; | ||
} |