Skip to content

Commit 50109bc

Browse files
committed
feat: Add an ExpirationAnnotation component
1 parent 6bdaa34 commit 50109bc

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
4+
import { models } from 'cozy-client'
5+
6+
import Typography from '../../Typography'
7+
import { useI18n } from '../../I18n'
8+
import { formatLocallyDistanceToNow } from '../../I18n/format'
9+
10+
const { computeExpirationDate, isExpired } = models.paper
11+
12+
const ExpirationAnnotation = ({ file }) => {
13+
const { t } = useI18n()
14+
15+
if (isExpired(file)) {
16+
return (
17+
<Typography component="span" variant="inherit" color="error">
18+
{t('Viewer.panel.qualification.expired')}
19+
</Typography>
20+
)
21+
}
22+
23+
const expirationDate = computeExpirationDate(file)
24+
25+
return (
26+
<Typography component="span" variant="inherit" className="u-warning">
27+
{t('Viewer.panel.qualification.expiresIn', {
28+
duration: formatLocallyDistanceToNow(expirationDate)
29+
})}
30+
</Typography>
31+
)
32+
}
33+
34+
ExpirationAnnotation.propTypes = {
35+
file: PropTypes.object.isRequired
36+
}
37+
38+
export default ExpirationAnnotation

react/Viewer/locales/en.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@
7272
"copy": "Copy",
7373
"copyClipboard": "Copy to clipboard",
7474
"edit": "Edit"
75-
}
75+
},
76+
"expired": "Expired",
77+
"expiresIn": "Expires in %{duration}"
7678
},
7779
"title": "Useful information"
7880
},

react/Viewer/locales/fr.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@
7272
"copy": "Copier",
7373
"copyClipboard": "Copier dans le presse-papier",
7474
"edit": "Modifier"
75-
}
75+
},
76+
"expired": "Expiré",
77+
"expiresIn": "Expire dans %{duration}"
7678
},
7779
"title": "Informations utiles"
7880
},

0 commit comments

Comments
 (0)