-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mespapiers): Add a
PaperItemAnnotation
component
- Loading branch information
1 parent
b0fcedb
commit 90cd7fe
Showing
3 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
packages/cozy-mespapiers-lib/src/components/Papers/PaperItemAnnotation.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import { models } from 'cozy-client' | ||
|
||
import { useI18n } from 'cozy-ui/transpiled/react/I18n' | ||
import { formatLocallyDistanceToNow } from 'cozy-ui/transpiled/react/I18n/format' | ||
|
||
const { computeExpirationDate, isExpired, isExpiringSoon } = models.paper | ||
|
||
const PaperItemAnnotation = ({ file }) => { | ||
const { t } = useI18n() | ||
|
||
if (isExpired(file)) { | ||
return ( | ||
<> | ||
{' · '} | ||
<span className="u-error">{t('PapersList.expired')}</span> | ||
</> | ||
) | ||
} | ||
|
||
if (isExpiringSoon(file)) { | ||
const expirationDate = computeExpirationDate(file) | ||
|
||
return ( | ||
<> | ||
{' · '} | ||
<span className="u-warning"> | ||
{t('PapersList.expiresIn', { | ||
duration: formatLocallyDistanceToNow(expirationDate) | ||
})} | ||
</span> | ||
</> | ||
) | ||
} | ||
|
||
return null | ||
} | ||
|
||
PaperItemAnnotation.propTypes = { | ||
file: PropTypes.object.isRequired | ||
} | ||
|
||
export default PaperItemAnnotation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters