Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Petr Šlézar
PA165 - Movies Recommender Catalogue
Commits
fb58b221
Commit
fb58b221
authored
May 22, 2022
by
Daniel Puchala
Browse files
feat: invalid credential error added
parent
79842b1d
Changes
1
Hide whitespace changes
Inline
Side-by-side
frontend/src/components/Login.tsx
View file @
fb58b221
...
...
@@ -7,19 +7,27 @@ export const Login = () => {
const
navigate
=
useNavigate
();
const
[
name
,
setName
]
=
useState
<
string
>
(
''
);
const
[
password
,
setPassword
]
=
useState
<
string
>
(
''
);
const
[
isError
,
setIsError
]
=
useState
<
boolean
>
(
false
);
async
function
handleSubmit
(
event
:
any
)
{
event
.
preventDefault
();
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
(
<
div
className
=
"h-[100vh]"
>
<
Header
/>
<
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
}
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
>
<
label
className
=
"flex justify-between"
>
Username:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment