#21 Using wouter for navigation and links. Register page works by sending request to register endpoint

This commit is contained in:
2023-03-19 16:34:44 -04:00
parent 0d4c4facd5
commit f6e2b445d7
7 changed files with 235 additions and 46 deletions

View File

@@ -1,5 +1,6 @@
import React, { useContext, useEffect, useState } from "react";
import { Button, Col, Container, Form, Row, Alert } from "react-bootstrap";
import { Link } from "wouter";
import MyNavbar from "../components/MyNavbar";
import UserContext from "../contexts/UserContext";
import { makeRequest } from "../utils.ts";
@@ -12,7 +13,6 @@ const LoginPage = () => {
const { currentUser, setCurrentUser } = useContext(UserContext);
useEffect(() => {
console.log(currentUser);
if (currentUser?.id) {
gotoHome();
}
@@ -42,14 +42,16 @@ const LoginPage = () => {
return (
<React.Fragment>
<MyNavbar />
{error && (
<Container>
<Alert variant="danger" className="m-4 mx-auto w-50 text-center">
{error.message}
</Alert>
</Container>
)}
<Container className="p-5">
{error && (
<Container>
<Alert variant="danger" className="mx-auto w-50 text-center">
{error.message}
</Alert>
</Container>
)}
<h2>Login</h2>
<br />
<Form onSubmit={sendLoginRequest}>
<Form.Group as={Row} className="mb-3" controlId="username">
<Form.Label column sm={2} className="me-2">
@@ -87,7 +89,7 @@ const LoginPage = () => {
</Form.Group>
<Form.Group as={Row}>
<p>
Don't have an account? <a href="/register">Register here</a>
Don't have an account? <Link href="/register">Register here</Link>
</p>
</Form.Group>
</Form>