Changed so that most functionality was moved to separate components
This commit is contained in:
parent
15ec2108d3
commit
8cf873a98b
1 changed files with 21 additions and 80 deletions
|
@ -1,71 +1,29 @@
|
||||||
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 { FormEvent, useEffect, useState } from "react";
|
import { Dispatch, FormEvent, SetStateAction, useState } from "react";
|
||||||
import { NewUser } from "../Types/Users";
|
import BackgroundAnimation from "../Components/BackgroundAnimation";
|
||||||
import { useNavigate } from "react-router-dom";
|
import LoginField from "../Components/LoginField";
|
||||||
|
import LoginCheck from "../Components/LoginCheck";
|
||||||
|
|
||||||
const PreloadBackgroundAnimation = (): JSX.Element => {
|
function LoginPage(props: {
|
||||||
useEffect(() => {
|
setAuthority: Dispatch<SetStateAction<number>>;
|
||||||
const images = [
|
}): JSX.Element {
|
||||||
"src/assets/1.jpg",
|
const [username, setUsername] = useState("");
|
||||||
"src/assets/2.jpg",
|
const [password, setPassword] = useState("");
|
||||||
"src/assets/3.jpg",
|
|
||||||
"src/assets/4.jpg",
|
|
||||||
];
|
|
||||||
|
|
||||||
// Pre-load images
|
|
||||||
for (const i of images) {
|
|
||||||
console.log(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start animation
|
|
||||||
document.body.style.animation = "backgroundTransition 30s infinite";
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return <></>;
|
|
||||||
};
|
|
||||||
|
|
||||||
function LoginPage(): JSX.Element {
|
|
||||||
//Example users for testing without backend, remove when using backend
|
|
||||||
const admin: NewUser = {
|
|
||||||
userName: "admin",
|
|
||||||
password: "123",
|
|
||||||
};
|
|
||||||
const pmanager: NewUser = {
|
|
||||||
userName: "pmanager",
|
|
||||||
password: "123",
|
|
||||||
};
|
|
||||||
const user: NewUser = {
|
|
||||||
userName: "user",
|
|
||||||
password: "123",
|
|
||||||
};
|
|
||||||
|
|
||||||
const navigate = useNavigate();
|
|
||||||
|
|
||||||
/* On submit (enter or button click) check if username and password match any user
|
/* On submit (enter or button click) check if username and password match any user
|
||||||
and if so, redirect to correct page */
|
and if so, redirect to correct page */
|
||||||
function handleSubmit(event: FormEvent<HTMLFormElement>): void {
|
function handleSubmit(event: FormEvent<HTMLFormElement>): void {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
//TODO: Compare with db instead when finished
|
props.setAuthority((prevAuth) => {
|
||||||
if (username === admin.userName && password === admin.password) {
|
prevAuth = LoginCheck({ username: username, password: password });
|
||||||
navigate("/admin-menu");
|
return prevAuth;
|
||||||
} else if (
|
});
|
||||||
username === pmanager.userName &&
|
|
||||||
password === pmanager.password
|
|
||||||
) {
|
|
||||||
navigate("/PM-project-page");
|
|
||||||
} else if (username === user.userName && password === user.password) {
|
|
||||||
navigate("/your-projects");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const [username, setUsername] = useState("");
|
|
||||||
const [password, setPassword] = useState("");
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PreloadBackgroundAnimation />
|
<BackgroundAnimation />
|
||||||
<div
|
<div
|
||||||
className="flex flex-col h-screen items-center justify-center bg-cover bg-fixed"
|
className="flex flex-col h-screen items-center justify-center bg-cover bg-fixed"
|
||||||
style={{
|
style={{
|
||||||
|
@ -88,30 +46,13 @@ function LoginPage(): JSX.Element {
|
||||||
{" "}
|
{" "}
|
||||||
Please log in to continue{" "}
|
Please log in to continue{" "}
|
||||||
</h2>
|
</h2>
|
||||||
<form className="flex flex-col items-center" onSubmit={handleSubmit}>
|
<LoginField
|
||||||
<input
|
handleSubmit={handleSubmit}
|
||||||
className="border-2 border-black mb-3 rounded-lg w-[20vw] p-1"
|
setUsername={setUsername}
|
||||||
type="text"
|
setPassword={setPassword}
|
||||||
placeholder="Username"
|
username={username}
|
||||||
onChange={(e) => {
|
password={password}
|
||||||
setUsername(e.target.value);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<input
|
|
||||||
className="border-2 border-black mb-3 rounded-lg w-[20vw] p-1"
|
|
||||||
type="password"
|
|
||||||
placeholder="Password"
|
|
||||||
onChange={(e) => {
|
|
||||||
setPassword(e.target.value);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Button
|
|
||||||
text="Login"
|
|
||||||
onClick={(): void => {
|
|
||||||
return;
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|
Loading…
Reference in a new issue