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 29, 2024
1 parent 3f6b57c commit d8439c7
Show file tree
Hide file tree
Showing 4 changed files with 29 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
18 changes: 16 additions & 2 deletions react/Viewer/Panel/Qualification.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types'
import {
isExpiringSoon,
formatMetadataQualification,
KNOWN_BILLS_ATTRIBUTES_NAMES,
getMetadataQualificationType
} from 'cozy-client/dist/models/paper'

Expand All @@ -20,7 +21,8 @@ const ComponentFromMetadataQualificationType = {
contact: QualificationListItemContact,
date: QualificationListItemDate,
information: QualificationListItemInformation,
other: QualificationListItemOther
other: QualificationListItemOther,
bills: QualificationListItemInformation
}

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

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

if (relatedBills) {
const formattedBillsMetadata = KNOWN_BILLS_ATTRIBUTES_NAMES.map(
attrName => ({ name: attrName, value: relatedBills[attrName] })
)

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 d8439c7

Please sign in to comment.