mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-16 16:20:04 +00:00
Added error to LoginView
This commit is contained in:
@@ -1,11 +1,14 @@
|
|||||||
import {useAuth} from "Frontend/util/auth";
|
import {useAuth} from "Frontend/util/auth";
|
||||||
import {useState} from "react";
|
import {useState} from "react";
|
||||||
import {Link, useNavigate} from "react-router-dom";
|
import {Link, useNavigate} from "react-router-dom";
|
||||||
import {Button, Card, Input, Typography} from "@material-tailwind/react";
|
import {Alert, Button, Card, Input, Spinner, Typography} from "@material-tailwind/react";
|
||||||
|
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
||||||
|
import {faCircleInfo, faCircleXmark} from "@fortawesome/free-solid-svg-icons";
|
||||||
|
|
||||||
export default function LoginView() {
|
export default function LoginView() {
|
||||||
const {state, login} = useAuth();
|
const {state, login} = useAuth();
|
||||||
const [hasError, setError] = useState<boolean>();
|
const [hasError, setError] = useState(false);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
const [username, setUsername] = useState<string>();
|
const [username, setUsername] = useState<string>();
|
||||||
const [password, setPassword] = useState<string>();
|
const [password, setPassword] = useState<string>();
|
||||||
const [url, setUrl] = useState<string>();
|
const [url, setUrl] = useState<string>();
|
||||||
@@ -25,18 +28,26 @@ export default function LoginView() {
|
|||||||
src="/images/Logo.svg"
|
src="/images/Logo.svg"
|
||||||
/>
|
/>
|
||||||
<div className="mt-8 mb-2 w-80 max-w-screen-lg sm:w-96">
|
<div className="mt-8 mb-2 w-80 max-w-screen-lg sm:w-96">
|
||||||
|
{ hasError &&
|
||||||
|
<Alert
|
||||||
|
icon={ <FontAwesomeIcon icon={faCircleXmark}/> }
|
||||||
|
className="mb-4 bg-red-500"
|
||||||
|
>
|
||||||
|
Wrong username and/or password
|
||||||
|
</Alert> }
|
||||||
<form
|
<form
|
||||||
className="mb-1 flex flex-col gap-6"
|
className="mb-1 flex flex-col gap-6"
|
||||||
onSubmit={async e => {
|
onSubmit={async e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (typeof username === "string" && password != null) {
|
if (typeof username === "string" && password != null) {
|
||||||
|
setLoading(true);
|
||||||
const {defaultUrl, error, redirectUrl} = await login(username, password);
|
const {defaultUrl, error, redirectUrl} = await login(username, password);
|
||||||
if (error) {
|
if (error) {
|
||||||
setError(true);
|
setError(true);
|
||||||
alert("Wrong username and/or password!");
|
|
||||||
} else {
|
} else {
|
||||||
setUrl(redirectUrl ?? defaultUrl ?? '/');
|
setUrl(redirectUrl ?? defaultUrl ?? '/');
|
||||||
}
|
}
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -85,9 +96,10 @@ export default function LoginView() {
|
|||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
size="lg"
|
size="lg"
|
||||||
className="w-28"
|
className="w-28 h-12 flex justify-center"
|
||||||
|
disabled={loading}
|
||||||
>
|
>
|
||||||
Log in
|
{loading ? <Spinner className="h-6 w-6"/> : "Log in"}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user