import { useState , useEffect } from 'react' ; import { get } from 'lodash' ; import { useFormData , useFormContext , ValidationError } from '../../../../../../shared_imports' ; import { ROLLOVER_FORM_PATHS } from '../../../constants' ; import { ROLLOVER_VALUE_REQUIRED_VALIDATION_CODE } from '../../../form' ; const rolloverFieldPaths = Object . values ( ROLLOVER_FORM_PATHS ) ; export const useRolloverValueRequiredValidation = ( ) : boolean => { const [ isValid , setIsValid ] = useState ( false ) ; const [ formData ] = useFormData ( { watch : rolloverFieldPaths } ) ; const { getFields } = useFormContext ( ) ; useEffect ( ( ) => { const rolloverFieldErrors = get ( getFields ( ) , ROLLOVER_FORM_PATHS . maxPrimaryShardSize ) ?. errors ?? [ ] ; setIsValid ( rolloverFieldErrors . some ( ( validation ) => validation . code === ROLLOVER_VALUE_REQUIRED_VALIDATION_CODE ) ) ; } , [ getFields , formData ] ) ; return isValid ; } ;