diff --git a/react/Viewer/Panel/QualificationListItemContact.jsx b/react/Viewer/Panel/QualificationListItemContact.jsx index 65599c186b..42e7f8169b 100644 --- a/react/Viewer/Panel/QualificationListItemContact.jsx +++ b/react/Viewer/Panel/QualificationListItemContact.jsx @@ -1,6 +1,11 @@ import React, { useRef, useState } from 'react' import PropTypes from 'prop-types' +import { + getTranslatedNameForContact, + formatContactValue +} from 'cozy-client/dist/models/paper' + import ListItem from '../../ListItem' import ListItemSecondaryAction from '../../ListItemSecondaryAction' import IconButton from '../../IconButton' @@ -13,7 +18,7 @@ import { useI18n } from '../../providers/I18n' import ActionMenuWrapper from './ActionMenuWrapper' const QualificationListItemContact = ({ file }) => { - const { t } = useI18n() + const { lang } = useI18n() const actionBtnRef = useRef() const [optionFile, setOptionFile] = useState({ name: '', @@ -27,7 +32,7 @@ const QualificationListItemContact = ({ file }) => { return { name, value } }) - const { contactName, isLoadingContacts } = useReferencedContactName(file) + const { contacts, isLoadingContacts } = useReferencedContactName(file) if (isLoadingContacts) { return ( @@ -37,7 +42,10 @@ const QualificationListItemContact = ({ file }) => { ) } - if (!isLoadingContacts && !contactName) { + const formattedTitle = getTranslatedNameForContact({ lang }) + const formattedValue = formatContactValue(contacts) + + if (!isLoadingContacts && !formattedValue) { return null } @@ -45,13 +53,13 @@ const QualificationListItemContact = ({ file }) => { <> toggleActionsMenu('contact', contactName)} + onClick={() => toggleActionsMenu('contact', formattedValue)} > diff --git a/react/Viewer/hooks/useReferencedContactName.jsx b/react/Viewer/hooks/useReferencedContactName.jsx index bff6b8d50e..9861a9efcb 100644 --- a/react/Viewer/hooks/useReferencedContactName.jsx +++ b/react/Viewer/hooks/useReferencedContactName.jsx @@ -1,11 +1,7 @@ -import { getReferencedBy, useQuery, models, isQueryLoading } from 'cozy-client' +import { getReferencedBy, useQuery, isQueryLoading } from 'cozy-client' import { buildContactByIdsQuery } from '../queries' -const { - contact: { getDisplayName } -} = models - const useReferencedContactName = file => { const contactIds = getReferencedBy(file, 'io.cozy.contacts').map( ref => ref.id @@ -25,11 +21,6 @@ const useReferencedContactName = file => { isContactByIdsQueryEnabled && (isQueryLoading(contactsQueryResult) || contactsQueryResult.hasMore) - const contactName = - contacts && contacts.length > 0 - ? contacts.map(contact => `${getDisplayName(contact)}`).join(', ') - : '' - - return { contactName, isLoadingContacts } + return { contacts, isLoadingContacts } } export default useReferencedContactName