import React from 'react'; import { UseFormReturn } from 'react-hook-form'; import { FieldNamesType, FieldsType } from '../../types'; import { numberRegex, specialCharRegex } from './HookFormValidationSchemas'; import { errorMessages } from './HookFormValidationSchemas'; export interface HookFormPasswordValidatorProps { dirtyFields: UseFormReturn['formState']['dirtyFields']; /** * An object with field errors. * @see https://react-hook-form.com/docs/useform/formstate `errors` entry */ errors: UseFormReturn['formState']['errors']; /** * The name of the field to validate. */ fieldName: FieldNamesType; /** * The value of the password field to validate. */ password?: string; } /** * This is only to be consumed inside the HookForm component. You should not need to use this component directly. Did you mean to use `` component? */ const HookFormPasswordValidator = ({ dirtyFields, errors, fieldName, password, }: HookFormPasswordValidatorProps) => { const isTouched = dirtyFields[fieldName]; const hasError = errors[fieldName]; const tooShort = password ? password.length < 8 : true; const missingSpecialChar = !specialCharRegex.test(password || ''); const missingNum = !numberRegex.test(password || ''); const isInvalid = (