Commit fb58b221 authored by Daniel Puchala's avatar Daniel Puchala
Browse files

feat: invalid credential error added

parent 79842b1d
...@@ -7,19 +7,27 @@ export const Login = () => { ...@@ -7,19 +7,27 @@ export const Login = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const [ name, setName ] = useState<string>(''); const [ name, setName ] = useState<string>('');
const [ password, setPassword ] = useState<string>(''); const [ password, setPassword ] = useState<string>('');
const [ isError, setIsError ] = useState<boolean>(false);
async function handleSubmit(event: any) { async function handleSubmit(event: any) {
event.preventDefault(); event.preventDefault();
const response: any = await login(name, password); const response: any = await login(name, password);
response.status === 200 ? navigate('/pa165/', { replace: true }) : alert('Invalid credentials'); if (response.status === 200) {
setIsError(false);
navigate('/pa165/', { replace: true });
} else {
setIsError(true);
alert('Invalid credentials');
}
} }
return ( return (
<div className="h-[100vh]"> <div className="h-[100vh]">
<Header/> <Header/>
<div className="grid place-items-center h-[90%]"> <div className="grid place-items-center h-[90%]">
{isError && <div className="text-2xl text-center font-bold mt-auto text-red-900">Invalid credentials</div>}
<form onSubmit={handleSubmit} <form onSubmit={handleSubmit}
className="flex flex-col w-1/4 gap-3 border-2 border-black rounded-lg bg-slate-300 p-4"> className={`flex flex-col w-1/4 gap-3 border-2 border-black rounded-lg bg-slate-300 p-4 mb-auto ${isError || 'mt-auto'}`}>
<p className="text-2xl text-center font-bold">Login</p> <p className="text-2xl text-center font-bold">Login</p>
<label className="flex justify-between"> <label className="flex justify-between">
Username: Username:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment