| 36 | } |
| 37 | |
| 38 | export const confirmPasswordRules = (getValues: () => unknown, isRequired = true) => { |
| 39 | const rules: { |
| 40 | validate: (value: string) => boolean | string |
| 41 | required?: string |
| 42 | } = { |
| 43 | validate: (value: string) => { |
| 44 | const formValues = getValues() as { |
| 45 | password?: string |
| 46 | new_password?: string |
| 47 | } |
| 48 | const password = formValues.password || formValues.new_password |
| 49 | return value === password ? true : t('general.errors.passwordsDoNotMatch') |
| 50 | }, |
| 51 | } |
| 52 | |
| 53 | if (isRequired) { |
| 54 | rules.required = t('general.errors.passwordConfirmationIsRequired') |
| 55 | } |
| 56 | |
| 57 | return rules |
| 58 | } |
| 59 | |
| 60 | export const handleError = ( |
| 61 | err: ApiError, |