-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from fga-eps-mds/17_auth_usuario
feat: login page
- Loading branch information
Showing
8 changed files
with
180 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useAuth } from '../../../hooks/useAuth'; | ||
import { useNavigate } from 'react-router'; | ||
import { Input, Stack } from '@chakra-ui/react'; | ||
import { useForm } from 'react-hook-form'; | ||
import { PasswordInput } from '../../../components/ui/password-input'; | ||
import { Button } from '../../../components/ui/button'; | ||
import { Field } from '../../../components/ui/field'; | ||
|
||
interface FormValues { | ||
email: string; | ||
password: string; | ||
} | ||
|
||
function SignInForm() { | ||
const [loading, setLoading] = useState(false); | ||
const navigate = useNavigate(); | ||
|
||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors, isValid }, | ||
} = useForm<FormValues>(); | ||
|
||
const { signIn, token } = useAuth(); | ||
|
||
const onSubmit = handleSubmit(async (data: FormValues) => { | ||
setLoading(true); | ||
await signIn({ | ||
email: data.email, | ||
password: data.password, | ||
}); | ||
setLoading(false); | ||
}) | ||
|
||
useEffect(() => { | ||
if (!token) return; | ||
navigate('/inicio'); | ||
}, [token]) | ||
|
||
return ( | ||
<form onSubmit={onSubmit}> | ||
<Stack gap={'40px'}> | ||
<Stack gap={'10px'}> | ||
<Field invalid={!!errors.email} errorText={errors.email?.message}> | ||
<Input | ||
size={'2xl'} | ||
placeholder={'E-mail'} | ||
{...register('email', { | ||
required: "Campo obrigatório.", | ||
pattern: { | ||
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i, | ||
message: "E-mail inválido." | ||
} | ||
})} | ||
/> | ||
</Field> | ||
<Field invalid={!!errors.password} errorText={errors.password?.message}> | ||
<PasswordInput | ||
size={'2xl'} | ||
placeholder={'Senha'} | ||
{...register('password', { required: "Campo obrigatório." })} | ||
/> | ||
</Field> | ||
</Stack> | ||
<Button | ||
loading={loading} | ||
type="submit" | ||
width={'100%'} | ||
size={'2xl'} | ||
bg={'green.100'} | ||
fontWeight={'semibold'} | ||
disabled={!isValid} | ||
> | ||
Entrar | ||
</Button> | ||
</Stack> | ||
</form> | ||
); | ||
} | ||
|
||
export default SignInForm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Stack, Text } from '@chakra-ui/react'; | ||
|
||
function SignUpHeader() { | ||
return ( | ||
<Stack gap={'5px'}> | ||
<Text textStyle={'3xl'} fontWeight={'semibold'} color={'blue.100'}>Bem vindo ao Livro Livre</Text> | ||
<Text color={'blue.100'}>Insira seus dados para fazer o login e começar a ajudar utilizar o Livro Livre</Text> | ||
</Stack> | ||
); | ||
} | ||
|
||
export default SignUpHeader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Link } from 'react-router'; | ||
import { Center, Link as ChakraLink, Separator, Stack, Text } from '@chakra-ui/react'; | ||
|
||
function SignUpButton() { | ||
return ( | ||
<Center width={'100%'}> | ||
<Stack gap={'25px'} width={'100%'}> | ||
<Separator /> | ||
<Text | ||
textAlign={'center'} | ||
color={'blue.100'} | ||
> | ||
Não possuí uma conta? <ChakraLink color={'green.100'}><Link to='/cadastro'>Faça seu cadastro aqui</Link></ChakraLink> | ||
</Text> | ||
</Stack> | ||
</Center> | ||
); | ||
} | ||
|
||
export default SignUpButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Box, Center, Stack } from '@chakra-ui/react'; | ||
import SignInForm from './SignInForm'; | ||
import SignUpButton from './SignUpButton'; | ||
import SignInHeader from './SignInHeader'; | ||
|
||
function SignIn() { | ||
return ( | ||
<Box padding='40px'> | ||
<Center> | ||
<Stack gap={'40px'}> | ||
<SignInHeader /> | ||
<SignInForm /> | ||
<SignUpButton /> | ||
</Stack> | ||
</Center> | ||
</Box> | ||
); | ||
} | ||
|
||
export default SignIn |