diff --git a/src/components/Contacts/ContactDetails/ContactDetailsTab/People/Items/PersonModal/PersonEmail/PersonEmailItem.tsx b/src/components/Contacts/ContactDetails/ContactDetailsTab/People/Items/PersonModal/PersonEmail/PersonEmailItem.tsx index 3496ccf95..40b0c28c1 100644 --- a/src/components/Contacts/ContactDetails/ContactDetailsTab/People/Items/PersonModal/PersonEmail/PersonEmailItem.tsx +++ b/src/components/Contacts/ContactDetails/ContactDetailsTab/People/Items/PersonModal/PersonEmail/PersonEmailItem.tsx @@ -17,6 +17,7 @@ import { PersonEmailAddressInput, PersonUpdateInput, } from 'src/graphql/types.generated'; +import { useEmailLocations } from 'src/hooks/useEmailLocations'; import { isEditableSource } from 'src/utils/sourceHelper'; import { ModalSectionContainer } from '../ModalSectionContainer/ModalSectionContainer'; import { ModalSectionDeleteIcon } from '../ModalSectionDeleteIcon/ModalSectionDeleteIcon'; @@ -68,6 +69,8 @@ export const PersonEmailItem: React.FC = ({ const [isEmailPrimaryChecked, setIsEmailPrimaryChecked] = React.useState(false); + const locations = useEmailLocations(); + const source = sources?.find((email) => email.id === emailAddress.id)?.source; const locked = !isEditableSource(source); @@ -134,17 +137,13 @@ export const PersonEmailItem: React.FC = ({ fullWidth > - None - - - {t('Work')} - - - {t('Personal')} - - - {t('Other')} + {t('None')} + {Object.entries(locations).map(([value, label]) => ( + + {label} + + ))} diff --git a/src/components/Contacts/ContactDetails/ContactDetailsTab/People/Items/PersonModal/PersonPhoneNumber/PersonPhoneNumberItem.tsx b/src/components/Contacts/ContactDetails/ContactDetailsTab/People/Items/PersonModal/PersonPhoneNumber/PersonPhoneNumberItem.tsx index 187bcd309..8de79563c 100644 --- a/src/components/Contacts/ContactDetails/ContactDetailsTab/People/Items/PersonModal/PersonPhoneNumber/PersonPhoneNumberItem.tsx +++ b/src/components/Contacts/ContactDetails/ContactDetailsTab/People/Items/PersonModal/PersonPhoneNumber/PersonPhoneNumberItem.tsx @@ -17,6 +17,7 @@ import { PersonPhoneNumberInput, PersonUpdateInput, } from 'src/graphql/types.generated'; +import { usePhoneLocations } from 'src/hooks/usePhoneLocations'; import { isEditableSource } from 'src/utils/sourceHelper'; import { ModalSectionContainer } from '../ModalSectionContainer/ModalSectionContainer'; import { ModalSectionDeleteIcon } from '../ModalSectionDeleteIcon/ModalSectionDeleteIcon'; @@ -67,6 +68,8 @@ export const PersonPhoneNumberItem: React.FC = ({ const [isPrimaryChecked, setIsPrimaryChecked] = React.useState(false); + const locations = usePhoneLocations(); + const source = sources?.find( (number) => number.id === phoneNumber.id, )?.source; @@ -136,20 +139,13 @@ export const PersonPhoneNumberItem: React.FC = ({ fullWidth > - None - - - {t('Mobile')} - - - {t('Home')} - - - {t('Work')} - - - {t('Other')} + {t('None')} + {Object.entries(locations).map(([value, label]) => ( + + {label} + + ))} diff --git a/src/components/Shared/CollapsibleContactInfo/CollapsibleEmailList.tsx b/src/components/Shared/CollapsibleContactInfo/CollapsibleEmailList.tsx index e66bf85e5..dfce3a7b6 100644 --- a/src/components/Shared/CollapsibleContactInfo/CollapsibleEmailList.tsx +++ b/src/components/Shared/CollapsibleContactInfo/CollapsibleEmailList.tsx @@ -1,5 +1,6 @@ import { Link, Typography } from '@mui/material'; import { EmailAddress } from 'src/graphql/types.generated'; +import { useEmailLocations } from 'src/hooks/useEmailLocations'; import { CollapsibleList } from './CollapsibleList'; import { ContactInfoText } from './StyledComponents'; @@ -7,14 +8,23 @@ interface EmailProps { email: Partial; } -const Email: React.FC = ({ email }) => ( - - - {email.email} - - {email.location && - {email.location}} - -); +const Email: React.FC = ({ email }) => { + const locations = useEmailLocations(); + + return ( + + + {email.email} + + {email.location && ( + + {' - '} + {locations[email.location.toLowerCase()] ?? email.location} + + )} + + ); +}; interface CollapsibleEmailListProps { emails: Array>; diff --git a/src/components/Shared/CollapsibleContactInfo/CollapsiblePhoneList.tsx b/src/components/Shared/CollapsibleContactInfo/CollapsiblePhoneList.tsx index df4067665..3f73aedaf 100644 --- a/src/components/Shared/CollapsibleContactInfo/CollapsiblePhoneList.tsx +++ b/src/components/Shared/CollapsibleContactInfo/CollapsiblePhoneList.tsx @@ -1,5 +1,6 @@ import { Link, Typography } from '@mui/material'; import { PhoneNumber } from 'src/graphql/types.generated'; +import { usePhoneLocations } from 'src/hooks/usePhoneLocations'; import { CollapsibleList } from './CollapsibleList'; import { ContactInfoText } from './StyledComponents'; @@ -7,14 +8,23 @@ interface PhoneProps { phone: Pick; } -const Phone: React.FC = ({ phone }) => ( - - - {phone.number} - - {phone.location && - {phone.location}} - -); +const Phone: React.FC = ({ phone }) => { + const locations = usePhoneLocations(); + + return ( + + + {phone.number} + + {phone.location && ( + + {' - '} + {locations[phone.location.toLowerCase()] ?? phone.location} + + )} + + ); +}; interface CollapsiblePhoneListProps { phones: Array>; diff --git a/src/components/Shared/CollapsibleContactInfo/StyledComponents.ts b/src/components/Shared/CollapsibleContactInfo/StyledComponents.ts index 30f5f56d6..5c451a4a7 100644 --- a/src/components/Shared/CollapsibleContactInfo/StyledComponents.ts +++ b/src/components/Shared/CollapsibleContactInfo/StyledComponents.ts @@ -2,7 +2,4 @@ import { styled } from '@mui/material/styles'; export const ContactInfoText = styled('span')({ overflow: 'hidden', - '& span': { - textTransform: 'capitalize', - }, }); diff --git a/src/hooks/useEmailLocations.ts b/src/hooks/useEmailLocations.ts new file mode 100644 index 000000000..82b570125 --- /dev/null +++ b/src/hooks/useEmailLocations.ts @@ -0,0 +1,18 @@ +import { useMemo } from 'react'; +import { useTranslation } from 'react-i18next'; + +// Return an object where the keys are email address locations and the values are the localized labels +export const useEmailLocations = (): Record => { + const { t } = useTranslation(); + + const locations = useMemo( + () => ({ + work: t('Work'), + personal: t('Personal'), + other: t('Other'), + }), + [t], + ); + + return locations; +}; diff --git a/src/hooks/usePhoneLocations.ts b/src/hooks/usePhoneLocations.ts new file mode 100644 index 000000000..5de21b1b1 --- /dev/null +++ b/src/hooks/usePhoneLocations.ts @@ -0,0 +1,19 @@ +import { useMemo } from 'react'; +import { useTranslation } from 'react-i18next'; + +// Return an object where the keys are phone number locations and the values are the localized labels +export const usePhoneLocations = (): Record => { + const { t } = useTranslation(); + + const locations = useMemo( + () => ({ + mobile: t('Mobile'), + home: t('Home'), + work: t('Work'), + other: t('Other'), + }), + [t], + ); + + return locations; +};