Skip to content

Commit

Permalink
Merge pull request #1327 from research-software-directory/1313-contac…
Browse files Browse the repository at this point in the history
…t-person-email

fix: use additional validation for email and contact person switch
  • Loading branch information
dmijatovic authored Oct 25, 2024
2 parents 851b8c7 + a563764 commit a1cc2a8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion frontend/components/person/AggregatedPersonModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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<FormPerson>({
const {handleSubmit, watch, formState, control, register, setValue, trigger} = useForm<FormPerson>({
mode: 'onChange',
defaultValues: {
...person,
Expand All @@ -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)
Expand Down

0 comments on commit a1cc2a8

Please sign in to comment.