Skip to content

Commit

Permalink
fix(Viewer): Editing a contact use now the correct intent path
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed Jan 16, 2025
1 parent 24a4927 commit 44881c3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 73 deletions.
5 changes: 4 additions & 1 deletion packages/cozy-viewer/src/Panel/ActionMenuWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ const ActionMenuWrapper = forwardRef(
const { showAlert } = useAlert()

const isEditable = isEditableAttribute(name, file) && !isReadOnly
const editPath = `${file.metadata.qualification.label}/${file._id}/edit/information?metadata=${optionFile.name}`
const editPath =
name === 'contact'
? `${file.metadata.qualification.label}/${file._id}/edit/contact`
: `${file.metadata.qualification.label}/${file._id}/edit/information?metadata=${optionFile.name}`

const handleCopy = async () => {
try {
Expand Down
4 changes: 2 additions & 2 deletions packages/cozy-viewer/src/Panel/Qualification.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ const Qualification = ({ file, isPublic, isReadOnly }) => {
})}
{optionFile.name && (
<ActionMenuWrapper
onClose={hideActionsMenu}
ref={actionBtnRef.current[optionFile.id]}
file={file}
optionFile={optionFile}
ref={actionBtnRef.current[optionFile.id]}
isReadOnly={isPublic ? true : isReadOnly}
onClose={hideActionsMenu}
/>
)}
</List>
Expand Down
121 changes: 51 additions & 70 deletions packages/cozy-viewer/src/Panel/QualificationListItemContact.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PropTypes from 'prop-types'
import React, { useRef, useState } from 'react'
import React, { forwardRef } from 'react'

import {
getTranslatedNameForContact,
Expand All @@ -15,85 +15,66 @@ import ListItemSecondaryAction from 'cozy-ui/transpiled/react/ListItemSecondaryA
import Spinner from 'cozy-ui/transpiled/react/Spinner'
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'

import ActionMenuWrapper from './ActionMenuWrapper'
import QualificationListItemText from './QualificationListItemText'
import IntentOpener from '../components/IntentOpener'
import useReferencedContactName from '../hooks/useReferencedContactName'

const QualificationListItemContact = ({ file, isReadOnly }) => {
const { lang } = useI18n()
const actionBtnRef = useRef()
const [optionFile, setOptionFile] = useState({
name: '',
value: ''
})
const { contacts, isLoadingContacts } = useReferencedContactName(file)
const QualificationListItemContact = forwardRef(
({ file, isReadOnly, toggleActionsMenu }, ref) => {
const { lang } = useI18n()
const { contacts, isLoadingContacts } = useReferencedContactName(file)

if (isLoadingContacts) {
return (
<ListItem>
<Spinner color="var(--secondaryTextColor)" />
</ListItem>
)
}

const formattedValue = formatContactValue(contacts)
if (isLoadingContacts) {
return (
<ListItem>
<Spinner color="var(--secondaryTextColor)" />
</ListItem>
)
}

if (!formattedValue) {
return null
}
const formattedValue = formatContactValue(contacts)

const formattedTitle = getTranslatedNameForContact({ lang })
const qualificationLabel = file.metadata.qualification.label
if (!formattedValue) {
return null
}

const hideActionsMenu = () => setOptionFile({ name: '', value: '' })
const toggleActionsMenu = (name, value) =>
setOptionFile(prev => {
if (prev.value) return { name: '', value: '' }
return { name, value }
})
const formattedTitle = getTranslatedNameForContact({ lang })
const qualificationLabel = file.metadata.qualification.label

return (
<>
<IntentOpener
action="OPEN"
doctype="io.cozy.files.paper"
options={{
path: `${qualificationLabel}/${file._id}/edit/contact`
}}
disabled={!!formattedValue || isReadOnly}
>
<ListItem button={!formattedValue && !isReadOnly}>
<ListItemIcon>
<Icon icon={PeopleIcon} />
</ListItemIcon>
<QualificationListItemText
primary={formattedTitle}
secondary={formattedValue}
/>
<ListItemSecondaryAction>
<IconButton
ref={actionBtnRef}
onClick={() => toggleActionsMenu('contact', formattedValue)}
>
<Icon icon={Dots} />
</IconButton>
</ListItemSecondaryAction>
</ListItem>
</IntentOpener>
return (
<>
<IntentOpener
action="OPEN"
doctype="io.cozy.files.paper"
options={{
path: `${qualificationLabel}/${file._id}/edit/contact`
}}
disabled={!!formattedValue || isReadOnly}
>
<ListItem button={!formattedValue && !isReadOnly}>
<ListItemIcon>
<Icon icon={PeopleIcon} />
</ListItemIcon>
<QualificationListItemText
primary={formattedTitle}
secondary={formattedValue}
/>
<ListItemSecondaryAction>
<IconButton
ref={ref}
onClick={() => toggleActionsMenu('contact', formattedValue)}
>
<Icon icon={Dots} />
</IconButton>
</ListItemSecondaryAction>
</ListItem>
</IntentOpener>
</>
)
}
)

{optionFile.value && (
<ActionMenuWrapper
onClose={hideActionsMenu}
file={file}
optionFile={optionFile}
ref={actionBtnRef}
isReadOnly={isReadOnly}
/>
)}
</>
)
}
QualificationListItemContact.displayName = 'QualificationListItemContact'

QualificationListItemContact.propTypes = {
file: PropTypes.object.isRequired,
Expand Down

0 comments on commit 44881c3

Please sign in to comment.