Skip to content

Commit

Permalink
fix: validation profile password
Browse files Browse the repository at this point in the history
  • Loading branch information
ialexanderbrito committed Mar 31, 2022
1 parent 90b8763 commit b7ad9a4
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/validations/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import * as yup from 'yup';
export const profileSchema = yup.object({
nome: yup.string().required('O nome é obrigatório'),
email: yup.string().email('Email inválido').required('Campo obrigatório'),
password: yup.string().min(6, 'Senha deve ter no mínimo 6 caracteres'),
newPassword: yup.string().when('password', {
is: (val: string | any[]) => !!val.length,
then: yup.string().min(6, 'Senha deve ter no mínimo 6 caracteres'),
otherwise: yup.string(),
}),
confirmPassword: yup.string().when('newPassword', {
is: (val: string | any[]) => !!val.length,
then: yup.string().oneOf([yup.ref('newPassword')], 'As senhas não conferem'),
otherwise: yup.string(),
}),
password: yup.string(),
newPassword: yup
.string()
.when('password', (password, field) => (password ? field.required('Campo obrigatório') : field)),
confirmPassword: yup
.string()
.when('newPassword', (newPassword, field) =>
newPassword ? field.required('Campo obrigatório').oneOf([yup.ref('newPassword')]) : field,
),
});

0 comments on commit b7ad9a4

Please sign in to comment.