diff --git a/frontend/src/hooks/useOus/index.tsx b/frontend/src/hooks/useOus/index.tsx index ba1a2119039e0bfb242355d2e8f78f21f5eba98e..a2f39ecd76eeaa37250b6e14ff03d4006474f6d5 100644 --- a/frontend/src/hooks/useOus/index.tsx +++ b/frontend/src/hooks/useOus/index.tsx @@ -7,6 +7,8 @@ type OuData = { en: string orgreg_id?: string acronym_nob?: string + acronym_nno?: string + acronym_eng?: string } function useOus(): OuData[] | undefined { diff --git a/frontend/src/routes/sponsor/register/stepPersonForm.tsx b/frontend/src/routes/sponsor/register/stepPersonForm.tsx index c018bf8a9121464b318efa91216e583b71d3f896..c0b7513613c5768b389b021b917113c76bf8248d 100644 --- a/frontend/src/routes/sponsor/register/stepPersonForm.tsx +++ b/frontend/src/routes/sponsor/register/stepPersonForm.tsx @@ -18,7 +18,7 @@ import React, { } from 'react' import { addDays } from 'date-fns/fp' import { useTranslation } from 'react-i18next' -import useOus, { enSort, nbSort } from 'hooks/useOus' +import useOus, { enSort, nbSort, OuData } from 'hooks/useOus' import useRoleTypes, { RoleTypeData } from 'hooks/useRoleTypes' import { getOuName, isValidEmail } from 'utils' import { FeatureContext } from 'contexts' @@ -143,6 +143,20 @@ const StepPersonForm = forwardRef( return true } + function getAcronym(ouData: OuData) { + switch (i18n.language) { + case 'en': + return ouData.acronym_eng ?? ouData.acronym_nob + + case 'nn': + return ouData.acronym_nno ?? ouData.acronym_nob + + default: + // There should always be a Norwegian bokmaal acronym set + return ouData.acronym_nob + } + } + return ( <> <Typography @@ -243,8 +257,7 @@ const StepPersonForm = forwardRef( .sort(i18n.language === 'en' ? enSort : nbSort) .map((ou) => ( <MenuItem key={ou.id.toString()} value={ou.id}> - {getOuName(ou)} ({ou.acronym_nob ?? ''}) ( - {ou.orgreg_id ?? ''}) + {getOuName(ou)} ({getAcronym(ou)}) ({ou.orgreg_id ?? ''}) </MenuItem> ))} </TextField> diff --git a/greg/api/serializers/organizational_unit.py b/greg/api/serializers/organizational_unit.py index c9339ccf222114c91f1d58330e5f8ad3dec55c36..e5de710e904a857025e3e82acb2d572f33829cc6 100644 --- a/greg/api/serializers/organizational_unit.py +++ b/greg/api/serializers/organizational_unit.py @@ -29,4 +29,12 @@ class SponsorOrgUnitsSerializer(ModelSerializer): class Meta: model = OrganizationalUnit - fields = ["id", "nb", "en", "orgreg_id", "acronym_nob"] + fields = [ + "id", + "nb", + "en", + "orgreg_id", + "acronym_nob", + "acronym_nno", + "acronym_eng", + ] diff --git a/greg/models.py b/greg/models.py index d1fa4b78c83e4b3d039076f451c966c75d18d0cd..a13668b9884171b3184bceb9e9a4a32de7f91e9f 100644 --- a/greg/models.py +++ b/greg/models.py @@ -491,6 +491,24 @@ class OrganizationalUnit(BaseModel): .first() ) + @property + def acronym_nno(self) -> Optional[str]: + """Gets the Norwegian nynorsk acronym if it exists""" + return ( + self.identifiers.filter(name="acronym_nno") + .values_list("value", flat=True) + .first() + ) + + @property + def acronym_eng(self) -> Optional[str]: + """Gets the English acronym if it exists""" + return ( + self.identifiers.filter(name="acronym_eng") + .values_list("value", flat=True) + .first() + ) + def __repr__(self) -> str: return "{}(id={!r}, name_en={!r}, parent={!r})".format( self.__class__.__name__, self.pk, self.name_en, self.parent