Added some functionality to login page. Checks username + password and compares with "fake" users to determine which page to get
This commit is contained in:
parent
ef28e1743e
commit
2ad7146588
1 changed files with 54 additions and 14 deletions
|
@ -1,8 +1,9 @@
|
||||||
import Button from "../Components/Button";
|
import Button from "../Components/Button";
|
||||||
import Logo from "/src/assets/Logo.svg";
|
import Logo from "/src/assets/Logo.svg";
|
||||||
import "./LoginPage.css";
|
import "./LoginPage.css";
|
||||||
import { useEffect } from "react";
|
import { FormEvent, useEffect, useState } from "react";
|
||||||
import { Link } from "react-router-dom";
|
import { NewUser } from "../Types/Users";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
const PreloadBackgroundAnimation = (): JSX.Element => {
|
const PreloadBackgroundAnimation = (): JSX.Element => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -26,6 +27,39 @@ const PreloadBackgroundAnimation = (): JSX.Element => {
|
||||||
};
|
};
|
||||||
|
|
||||||
function LoginPage(): JSX.Element {
|
function LoginPage(): JSX.Element {
|
||||||
|
//Example users for testing without backend, remove when using backend
|
||||||
|
const admin: NewUser = {
|
||||||
|
name: "admin",
|
||||||
|
password: "123",
|
||||||
|
};
|
||||||
|
const pmanager: NewUser = {
|
||||||
|
name: "pmanager",
|
||||||
|
password: "123",
|
||||||
|
};
|
||||||
|
const user: NewUser = {
|
||||||
|
name: "user",
|
||||||
|
password: "123",
|
||||||
|
};
|
||||||
|
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
/* On submit (enter or button click) check if username and password match any user
|
||||||
|
and if so, redirect to correct page */
|
||||||
|
function handleSubmit(event: FormEvent<HTMLFormElement>): void {
|
||||||
|
event.preventDefault();
|
||||||
|
//TODO: Compare with db instead when finished
|
||||||
|
if (username === admin.name && password === admin.password) {
|
||||||
|
navigate("/admin-menu");
|
||||||
|
} else if (username === pmanager.name && password === pmanager.password) {
|
||||||
|
navigate("/PM-project-page");
|
||||||
|
} else if (username === user.name && password === user.password) {
|
||||||
|
navigate("/your-projects");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const [username, setUsername] = useState("");
|
||||||
|
const [password, setPassword] = useState("");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PreloadBackgroundAnimation />
|
<PreloadBackgroundAnimation />
|
||||||
|
@ -51,24 +85,30 @@ function LoginPage(): JSX.Element {
|
||||||
{" "}
|
{" "}
|
||||||
Please log in to continue{" "}
|
Please log in to continue{" "}
|
||||||
</h2>
|
</h2>
|
||||||
<input
|
<form className="flex flex-col items-center" onSubmit={handleSubmit}>
|
||||||
className="border-2 border-black mb-3 rounded-lg w-[20vw] p-1"
|
<input
|
||||||
type="text"
|
className="border-2 border-black mb-3 rounded-lg w-[20vw] p-1"
|
||||||
placeholder="Username"
|
type="text"
|
||||||
/>
|
placeholder="Username"
|
||||||
<input
|
onChange={(e) => {
|
||||||
className="border-2 border-black mb-3 rounded-lg w-[20vw] p-1"
|
setUsername(e.target.value);
|
||||||
type="password"
|
}}
|
||||||
placeholder="Password"
|
/>
|
||||||
/>
|
<input
|
||||||
<Link to="/your-projects">
|
className="border-2 border-black mb-3 rounded-lg w-[20vw] p-1"
|
||||||
|
type="password"
|
||||||
|
placeholder="Password"
|
||||||
|
onChange={(e) => {
|
||||||
|
setPassword(e.target.value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<Button
|
<Button
|
||||||
text="Login"
|
text="Login"
|
||||||
onClick={(): void => {
|
onClick={(): void => {
|
||||||
return;
|
return;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Link>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|
Loading…
Reference in a new issue