Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Make the signup form a lot more dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
tdemin committed Nov 10, 2019
1 parent 399320b commit 7155493
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/views/assets/locales.ts
Expand Up @@ -8,7 +8,9 @@ export default new LocalizedStrings({
login_userNameTp: "User name",
login_passwordTp: "Password",
login_wrongPassTp: "Login failed. Check username and password.",
signup_msg: "Signup failed",
signup_processMsg: "Signing up...",
signup_successMsg: "Success. Redirecting to login...",
signup_failMsg: "Signup failed",
signup_unknownError: "Unknown error",
signup_disabled: "Signup disabled",
signup_userExists: "User with this name exists",
Expand Down
43 changes: 34 additions & 9 deletions src/views/signupForm.tsx
Expand Up @@ -9,9 +9,10 @@ import strings from "./assets/locales";
import "./styles/signupForm.scss";

enum Status {
UNDEFINED,
FAILED,
SUCCESS,
UNDEFINED,
IN_PROCESS,
}
enum Errors {
FORBIDDEN = 403,
Expand All @@ -24,6 +25,22 @@ interface State {
httpCode: number;
}

interface MsgProps {
message: string;
code: Status;
matchCode: Status;
}
/**
* Used for displaying messages on matching status code.
*/
const Msg: React.FC<MsgProps> = (props) => (
<span
style={{ display: props.code === props.matchCode ? "block" : "none" }}
>
{props.message}
</span>
);

class SignupForm extends React.PureComponent<RCP, State> {
state = {
name: "",
Expand All @@ -39,6 +56,7 @@ class SignupForm extends React.PureComponent<RCP, State> {
}
};
signup = () => {
this.setState({ status: Status.IN_PROCESS });
// prettier-ignore
req.post("/signup", {
name: this.state.name,
Expand Down Expand Up @@ -107,14 +125,21 @@ class SignupForm extends React.PureComponent<RCP, State> {
</div>
</div>
<div className="level-item">
<span
style={{
display:
this.state.status === Status.FAILED
? "block"
: "none",
}}
>{`${strings.signup_msg}: ${message}`}</span>
<Msg
code={this.state.status}
matchCode={Status.FAILED}
message={`${strings.signup_failMsg}: ${message}`}
/>
<Msg
code={this.state.status}
matchCode={Status.IN_PROCESS}
message={strings.signup_processMsg}
/>
<Msg
code={this.state.status}
matchCode={Status.SUCCESS}
message={strings.signup_successMsg}
/>
</div>
<div className="level-item level-right">
<div className="control">
Expand Down

0 comments on commit 7155493

Please sign in to comment.