Skip to content

Commit eb9c596

Browse files
committed
feat(Viewer): Use contact formatting from cozy-client
1 parent 98b6510 commit eb9c596

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

react/Viewer/Panel/QualificationListItemContact.jsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import React, { useRef, useState } from 'react'
22
import PropTypes from 'prop-types'
33

4+
import {
5+
getTranslatedNameForContact,
6+
formatContactValue
7+
} from 'cozy-client/dist/models/paper'
8+
49
import ListItem from '../../ListItem'
510
import ListItemSecondaryAction from '../../ListItemSecondaryAction'
611
import IconButton from '../../IconButton'
@@ -13,7 +18,7 @@ import { useI18n } from '../../providers/I18n'
1318
import ActionMenuWrapper from './ActionMenuWrapper'
1419

1520
const QualificationListItemContact = ({ file }) => {
16-
const { t } = useI18n()
21+
const { lang } = useI18n()
1722
const actionBtnRef = useRef()
1823
const [optionFile, setOptionFile] = useState({
1924
name: '',
@@ -27,7 +32,7 @@ const QualificationListItemContact = ({ file }) => {
2732
return { name, value }
2833
})
2934

30-
const { contactName, isLoadingContacts } = useReferencedContactName(file)
35+
const { contacts, isLoadingContacts } = useReferencedContactName(file)
3136

3237
if (isLoadingContacts) {
3338
return (
@@ -37,21 +42,24 @@ const QualificationListItemContact = ({ file }) => {
3742
)
3843
}
3944

40-
if (!isLoadingContacts && !contactName) {
45+
const formattedTitle = getTranslatedNameForContact({ lang })
46+
const formattedValue = formatContactValue(contacts)
47+
48+
if (!isLoadingContacts && !formattedValue) {
4149
return null
4250
}
4351

4452
return (
4553
<>
4654
<ListItem className={'u-ph-2'}>
4755
<QualificationListItemText
48-
primary={t('Viewer.panel.qualification.contact')}
49-
secondary={contactName}
56+
primary={formattedTitle}
57+
secondary={formattedValue}
5058
/>
5159
<ListItemSecondaryAction>
5260
<IconButton
5361
ref={actionBtnRef}
54-
onClick={() => toggleActionsMenu('contact', contactName)}
62+
onClick={() => toggleActionsMenu('contact', formattedValue)}
5563
>
5664
<Icon icon={Dots} />
5765
</IconButton>

react/Viewer/hooks/useReferencedContactName.jsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import { getReferencedBy, useQuery, models, isQueryLoading } from 'cozy-client'
1+
import { getReferencedBy, useQuery, isQueryLoading } from 'cozy-client'
22

33
import { buildContactByIdsQuery } from '../queries'
44

5-
const {
6-
contact: { getDisplayName }
7-
} = models
8-
95
const useReferencedContactName = file => {
106
const contactIds = getReferencedBy(file, 'io.cozy.contacts').map(
117
ref => ref.id
@@ -25,11 +21,6 @@ const useReferencedContactName = file => {
2521
isContactByIdsQueryEnabled &&
2622
(isQueryLoading(contactsQueryResult) || contactsQueryResult.hasMore)
2723

28-
const contactName =
29-
contacts && contacts.length > 0
30-
? contacts.map(contact => `${getDisplayName(contact)}`).join(', ')
31-
: ''
32-
33-
return { contactName, isLoadingContacts }
24+
return { contacts, isLoadingContacts }
3425
}
3526
export default useReferencedContactName

0 commit comments

Comments
 (0)