11import React , { useRef , useState } from 'react'
22import PropTypes from 'prop-types'
33
4+ import {
5+ getTranslatedNameForContact ,
6+ formatContactValue
7+ } from 'cozy-client/dist/models/paper'
8+
49import ListItem from '../../ListItem'
510import ListItemSecondaryAction from '../../ListItemSecondaryAction'
611import IconButton from '../../IconButton'
@@ -13,7 +18,7 @@ import { useI18n } from '../../providers/I18n'
1318import ActionMenuWrapper from './ActionMenuWrapper'
1419
1520const 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 >
0 commit comments