Fixed date issue with models.

This commit is contained in:
2022-04-07 20:23:32 -05:00
parent 5d2528da5f
commit 9c4696b797
6 changed files with 42 additions and 18 deletions

View File

@@ -2,6 +2,7 @@ import React from "react";
import { Alert, Button, Card, Container, Form } from "react-bootstrap";
import { Link } from "react-router-dom";
import validator from "validator";
import globals from "../globals";
import { apiClient } from "../utils/httpClients";
export default class Signup extends React.Component {
@@ -27,9 +28,10 @@ export default class Signup extends React.Component {
this.setUserState = this.setUserState.bind(this);
}
static contextType = globals;
async registerUser(event) {
event.preventDefault(); // We need this so that the page doesn't refresh.
event.preventDefault();
let formIssues = this.validateCurrentForm();
if (formIssues.length > 0) {
this.notifyUser("Oops there were issue(s)", (
@@ -47,7 +49,10 @@ export default class Signup extends React.Component {
const res = await apiClient.post("/user", this.state.user);
console.log(res.data);
if (res.status === 201) {
this.notifyUser("Success!", <div>You are successfully signed up! You <Link to="/login">can now go log in</Link>.</div>, "success");
this.notifyUser("Success!", <div>You are successfully signed up! You wil be directed to <Link to="/login">login</Link> now.</div>, "success");
this.redirectTimer = setTimeout(() => {
this.context.navigate("/signin", { replace: true });
}, 1000);
} else if (res.status === 409) {
this.notifyUser("User exists!", <div>This user already exists. Try <Link to="/login">logging in</Link> instead.</div>, "danger");
} else if (res.status === 400) {
@@ -57,6 +62,10 @@ export default class Signup extends React.Component {
}
}
componentWillUnmount() {
clearTimeout(this.redirectTimer);
}
validateCurrentForm() {
console.log(this.state);
let formIssues = [];
@@ -104,8 +113,8 @@ export default class Signup extends React.Component {
</Alert>
<Card style={{ width: "35rem" }}>
<Card.Body>
<Card.Title>Login</Card.Title>
<Card.Subtitle>Welcome to Sports Matcher!</Card.Subtitle>
<Card.Title>Sign up!</Card.Title>
<Card.Subtitle>Welcome to Sports Matcher! Already <Link to="/login">have an account</Link>?</Card.Subtitle>
<Form onSubmit={this.registerUser}>
<Form.Group className="mb-3" controlId="firstName">
<Form.Label>First name</Form.Label>