-
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 #8 from fga-eps-mds/9-us04-recuperacao-de-senha
9 us04 recuperacao de senha
- Loading branch information
Showing
9 changed files
with
262 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { useState } from 'react'; | ||
import { useAuth } from '../../../hooks/useAuth'; | ||
import { Stack } from '@chakra-ui/react'; | ||
import { useForm } from 'react-hook-form'; | ||
import { Button } from '../../../components/ui/button'; | ||
import { Field } from '../../../components/ui/field'; | ||
import { PasswordInput } from '../../../components/ui/password-input'; | ||
import { useLocation } from 'react-router'; | ||
|
||
interface FormValues { | ||
password: string; | ||
passwordConfirmation: string; | ||
} | ||
|
||
function useQuery() { | ||
return new URLSearchParams(useLocation().search); | ||
} | ||
|
||
function ChangePasswordForm() { | ||
const query = useQuery(); | ||
const [loading, setLoading] = useState(false); | ||
|
||
const token = query.get('token'); | ||
|
||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors, isValid }, | ||
} = useForm<FormValues>(); | ||
|
||
const { changePassword } = useAuth(); | ||
|
||
const onSubmit = handleSubmit(async (data: FormValues) => { | ||
if (!token) return; | ||
setLoading(true); | ||
await changePassword(data.password, token); | ||
setLoading(false); | ||
}) | ||
|
||
return ( | ||
<form onSubmit={onSubmit}> | ||
<Stack gap={'40px'}> | ||
<Stack gap={'10px'}> | ||
<Field invalid={!!errors.password} errorText={errors.password?.message}> | ||
<PasswordInput | ||
size={'2xl'} | ||
placeholder={'Senha'} | ||
{...register('password', { required: "Campo obrigatório." })} | ||
/> | ||
</Field> | ||
<Field invalid={!!errors.passwordConfirmation} errorText={errors.passwordConfirmation?.message}> | ||
<PasswordInput | ||
size={'2xl'} | ||
placeholder={'Confirmar senha'} | ||
{...register('passwordConfirmation', { required: "Campo obrigatório." })} | ||
/> | ||
</Field> | ||
</Stack> | ||
<Button | ||
loading={loading} | ||
type="submit" | ||
width={'100%'} | ||
size={'2xl'} | ||
bg={'green.100'} | ||
fontWeight={'semibold'} | ||
disabled={!isValid} | ||
> | ||
Alterar senha | ||
</Button> | ||
</Stack> | ||
</form> | ||
); | ||
} | ||
|
||
export default ChangePasswordForm |
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 RecoverPasswordHeader() { | ||
return ( | ||
<Stack gap={'5px'}> | ||
<Text textStyle={'3xl'} fontWeight={'semibold'} color={'blue.100'}>Nova senha</Text> | ||
<Text color={'blue.100'}>Deseja criar uma nova senha? Insira sua senha e confirme-a.</Text> | ||
</Stack> | ||
); | ||
} | ||
|
||
export default RecoverPasswordHeader |
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,18 @@ | ||
import { Box, Center, Stack } from '@chakra-ui/react'; | ||
import ChangePasswordForm from './ChangePasswordForm'; | ||
import ChangePasswordHeader from './ChangePasswordHeader'; | ||
|
||
function ChangePassword() { | ||
return ( | ||
<Box padding='40px'> | ||
<Center> | ||
<Stack gap={'40px'}> | ||
<ChangePasswordHeader /> | ||
<ChangePasswordForm /> | ||
</Stack> | ||
</Center> | ||
</Box> | ||
); | ||
} | ||
|
||
export default ChangePassword |
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,63 @@ | ||
import { useState } from 'react'; | ||
import { useAuth } from '../../../hooks/useAuth'; | ||
import { Input, Stack } from '@chakra-ui/react'; | ||
import { useForm } from 'react-hook-form'; | ||
import { Button } from '../../../components/ui/button'; | ||
import { Field } from '../../../components/ui/field'; | ||
|
||
interface FormValues { | ||
email: string; | ||
} | ||
|
||
function RecoverPasswordForm() { | ||
const [loading, setLoading] = useState(false); | ||
|
||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors, isValid }, | ||
} = useForm<FormValues>(); | ||
|
||
const { recoverPassword } = useAuth(); | ||
|
||
const onSubmit = handleSubmit(async (data: FormValues) => { | ||
setLoading(true); | ||
await recoverPassword(data.email); | ||
setLoading(false); | ||
}) | ||
|
||
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> | ||
</Stack> | ||
<Button | ||
loading={loading} | ||
type="submit" | ||
width={'100%'} | ||
size={'2xl'} | ||
bg={'green.100'} | ||
fontWeight={'semibold'} | ||
disabled={!isValid} | ||
> | ||
Solicitar nova senha | ||
</Button> | ||
</Stack> | ||
</form> | ||
); | ||
} | ||
|
||
export default RecoverPasswordForm |
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 RecoverPasswordHeader() { | ||
return ( | ||
<Stack gap={'5px'}> | ||
<Text textStyle={'3xl'} fontWeight={'semibold'} color={'blue.100'}>Recuperação de Senha</Text> | ||
<Text color={'blue.100'}>Para recuperar o acesso a sua conta, vamos enviar um código para seu e-mail.</Text> | ||
</Stack> | ||
); | ||
} | ||
|
||
export default RecoverPasswordHeader |
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,18 @@ | ||
import { Box, Center, Stack } from '@chakra-ui/react'; | ||
import RecoverPasswordForm from './RecoverPasswordForm'; | ||
import RecoverPasswordHeader from './RecoverPasswordHeader'; | ||
|
||
function RecoverPassword() { | ||
return ( | ||
<Box padding='40px'> | ||
<Center> | ||
<Stack gap={'40px'}> | ||
<RecoverPasswordHeader /> | ||
<RecoverPasswordForm /> | ||
</Stack> | ||
</Center> | ||
</Box> | ||
); | ||
} | ||
|
||
export default RecoverPassword |