Skip to content

Commit

Permalink
feat(Viewer): Support for io.cozy.bills
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed May 28, 2024
1 parent 3304ef0 commit b83867f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
5 changes: 3 additions & 2 deletions react/Viewer/Panel/ActionMenuWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const ActionMenuWrapper = forwardRef(({ onClose, file, optionFile }, ref) => {
editPath
)
const isAppLinkLoaded = fetchStatus === 'loaded'
const isEditable = Boolean(editPath) && isEditableAttribute(name, file)

const handleCopy = async () => {
try {
Expand Down Expand Up @@ -70,7 +71,7 @@ const ActionMenuWrapper = forwardRef(({ onClose, file, optionFile }, ref) => {
return (
<ActionMenuMobile
onClose={onClose}
isEditable={Boolean(editPath) && isEditableAttribute(name, file)}
isEditable={isEditable}
actions={{ handleCopy, handleEdit }}
appLink={url}
appSlug={mespapiersAppSlug}
Expand All @@ -82,7 +83,7 @@ const ActionMenuWrapper = forwardRef(({ onClose, file, optionFile }, ref) => {
<ActionMenuDesktop
ref={ref}
onClose={onClose}
isEditable={Boolean(editPath) && isEditableAttribute(name, file)}
isEditable={isEditable}
actions={{ handleCopy, handleEdit }}
appLink={url}
appSlug={mespapiersAppSlug}
Expand Down
19 changes: 17 additions & 2 deletions react/Viewer/Panel/Qualification.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const ComponentFromMetadataQualificationType = {
contact: QualificationListItemContact,
date: QualificationListItemDate,
information: QualificationListItemInformation,
other: QualificationListItemOther
other: QualificationListItemOther,
bills: QualificationListItemInformation
}

const isExpirationAlertHidden = file => {
Expand Down Expand Up @@ -48,8 +49,22 @@ const Qualification = ({ file }) => {
}

const formattedMetadataQualification = useMemo(() => {
const relatedBills = file.bills?.data?.[0]

if (relatedBills) {
const formattedBillsMetadata = [
{ name: 'amount', value: relatedBills.amount },
{ name: 'subtype', value: relatedBills.subtype },
{ name: 'employer', value: relatedBills.employer }
]

return formatMetadataQualification(metadata).concat(
formattedBillsMetadata
)
}

return formatMetadataQualification(metadata)
}, [metadata])
}, [metadata, file.bills?.data])

useEffect(() => {
actionBtnRef.current = formattedMetadataQualification.map(
Expand Down
1 change: 1 addition & 0 deletions react/Viewer/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const files = [
type: 'file',
name: 'My vehicle registration.pdf',
mime: 'application/pdf',
bills: { data: [{ amount: '500' }] },
metadata: {
carbonCopy: true,
AObtentionDate: null,
Expand Down
16 changes: 9 additions & 7 deletions react/Viewer/helpers.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { models, generateWebLink } from 'cozy-client'
import { generateWebLink } from 'cozy-client'

const {
import {
isEncrypted,
isFromKonnector,
hasQualifications,
hasCertifications,
normalize
} = models.file
} from 'cozy-client/dist/models/file'

const {
import {
KNOWN_DATE_METADATA_NAMES,
KNOWN_INFORMATION_METADATA_NAMES
} = models.paper
KNOWN_INFORMATION_METADATA_NAMES,
KNOWN_BILLS_ATTRIBUTES_NAMES
} from 'cozy-client/dist/models/paper'

export const getCurrentModel = metadataName => {
if (
KNOWN_DATE_METADATA_NAMES.includes(metadataName) ||
KNOWN_INFORMATION_METADATA_NAMES.includes(metadataName)
KNOWN_INFORMATION_METADATA_NAMES.includes(metadataName) ||
KNOWN_BILLS_ATTRIBUTES_NAMES.includes(metadataName)
) {
return 'information'
}
Expand Down

0 comments on commit b83867f

Please sign in to comment.