From a563764fc43ea5e0f07f81e323c9a4590b45684e Mon Sep 17 00:00:00 2001 From: "Dusan Mijatovic (PC2020)" Date: Tue, 22 Oct 2024 13:59:21 +0200 Subject: [PATCH] fix: use additional validation for email and contact person switch --- frontend/components/person/AggregatedPersonModal.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/components/person/AggregatedPersonModal.tsx b/frontend/components/person/AggregatedPersonModal.tsx index e577f0a04..1b3afc7a9 100644 --- a/frontend/components/person/AggregatedPersonModal.tsx +++ b/frontend/components/person/AggregatedPersonModal.tsx @@ -3,6 +3,8 @@ // // SPDX-License-Identifier: Apache-2.0 +import {useEffect} from 'react' + import Button from '@mui/material/Button' import Dialog from '@mui/material/Dialog' import DialogActions from '@mui/material/DialogActions' @@ -60,7 +62,7 @@ export default function AggregatedPersonModal({ }: AggregatedPersonModalProps) { const {loading, options} = useAggregatedPerson(person?.orcid) const smallScreen = useMediaQuery('(max-width:640px)') - const {handleSubmit, watch, formState, control, register, setValue} = useForm({ + const {handleSubmit, watch, formState, control, register, setValue, trigger} = useForm({ mode: 'onChange', defaultValues: { ...person, @@ -73,6 +75,13 @@ export default function AggregatedPersonModal({ const {isValid, isDirty} = formState const formData = watch() + useEffect(()=>{ + // when is_contact_person OR email_address changes + // we trigger additional validation on email because + // email is required for the contact person + trigger('email_address') + },[formData.email_address,formData.is_contact_person,trigger]) + // console.group('AggregatedPersonModal') // console.log('errors...', errors) // console.log('isDirty...', isDirty)