Skip to content

Commit

Permalink
feat: add alterar senha pelo perfil
Browse files Browse the repository at this point in the history
  • Loading branch information
ialexanderbrito committed Mar 31, 2022
1 parent 03bc837 commit 66a075b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/hooks/useProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ export function useProfile() {
avatar: '',
nome: '',
email: '',
password: '',
newPassword: '',
confirmPassword: '',
},
validationSchema: profileSchema,
onSubmit: async (values) => {
setLoading(true);
const { user: userData, error } = await supabase.auth.update({
email: values.email,
password: values.password === '' ? undefined : values.newPassword,
data: { name: values.nome },
});

Expand Down
39 changes: 39 additions & 0 deletions src/pages/Profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,45 @@ export function Profile() {
)}
</div>

<div className={styles.passwordContainer}>
<Input
type="password"
name="password"
placeholder="Senha Atual"
onChange={formikProfile.handleChange}
onBlur={formikProfile.handleBlur}
value={formikProfile.values.password}
icon={<FiMail color="#666360" size={24} />}
/>
{formikProfile.errors.password && formikProfile.touched.password && (
<span className={styles.error}>{formikProfile.errors.password}</span>
)}
<Input
type="password"
name="newPassword"
placeholder="Nova Senha"
onChange={formikProfile.handleChange}
onBlur={formikProfile.handleBlur}
value={formikProfile.values.newPassword}
icon={<FiMail color="#666360" size={24} />}
/>
{formikProfile.errors.newPassword && formikProfile.touched.newPassword && (
<span className={styles.error}>{formikProfile.errors.newPassword}</span>
)}
<Input
type="password"
name="confirmPassword"
placeholder="Confirmar Senha"
onChange={formikProfile.handleChange}
onBlur={formikProfile.handleBlur}
value={formikProfile.values.confirmPassword}
icon={<FiMail color="#666360" size={24} />}
/>
{formikProfile.errors.confirmPassword && formikProfile.touched.confirmPassword && (
<span className={styles.error}>{formikProfile.errors.confirmPassword}</span>
)}
</div>

<Button type="submit">
{loading ? <SpinnerCircular color="#28262e" size={32} /> : 'Confirmar mudanças'}
</Button>
Expand Down

0 comments on commit 66a075b

Please sign in to comment.