diff --git a/services/web/frontend/js/features/settings/components/emails/add-email.tsx b/services/web/frontend/js/features/settings/components/emails/add-email.tsx index 694571d8df..f8b594dcd7 100644 --- a/services/web/frontend/js/features/settings/components/emails/add-email.tsx +++ b/services/web/frontend/js/features/settings/components/emails/add-email.tsx @@ -50,22 +50,27 @@ function AddEmail() { setNewEmailMatchedInstitution(institution || null) } + const getSelectedKnownUniversityId = (): number | undefined => { + if (countryCode) { + return universities[countryCode]?.find( + ({ name }) => name === universityName + )?.id + } + + return newEmailMatchedInstitution?.university.id + } + const handleAddNewEmail = () => { - const selectedKnownUniversity = countryCode - ? universities[countryCode]?.find(({ name }) => name === universityName) - : undefined - - const knownUniversityData = universityName && - selectedKnownUniversity && { - university: { - id: selectedKnownUniversity.id, - }, - role, - department, - } - + const selectedKnownUniversityId = getSelectedKnownUniversityId() + const knownUniversityData = selectedKnownUniversityId && { + university: { + id: selectedKnownUniversityId, + }, + role, + department, + } const unknownUniversityData = universityName && - !selectedKnownUniversity && { + !selectedKnownUniversityId && { university: { name: universityName, country_code: countryCode, @@ -136,6 +141,7 @@ function AddEmail() { setRole={setRole} department={department} setDepartment={setDepartment} + newEmailMatchedInstitution={newEmailMatchedInstitution} /> diff --git a/services/web/frontend/js/features/settings/components/emails/add-email/country-input.tsx b/services/web/frontend/js/features/settings/components/emails/add-email/country-input.tsx index 6cb9f165d9..b676f56ddf 100644 --- a/services/web/frontend/js/features/settings/components/emails/add-email/country-input.tsx +++ b/services/web/frontend/js/features/settings/components/emails/add-email/country-input.tsx @@ -52,7 +52,7 @@ function Downshift({ setValue, inputRef }: CountryInputProps) { } )} > -
+
{/* eslint-disable-next-line jsx-a11y/label-has-for */}