Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add expiration annotation to cozy mespapiers lib #1894

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/cozy-mespapiers-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"@testing-library/react": "11.2.7",
"babel-preset-cozy-app": "2.0.1",
"cozy-bar": "7.16.0",
"cozy-client": "^34.2.0",
"cozy-client": "^34.5.0",
"cozy-device-helper": "^2.6.0",
"cozy-doctypes": "^1.86.0",
"cozy-harvest-lib": "^9.32.5",
"cozy-intent": "^2.7.0",
"cozy-realtime": "^4.2.9",
"cozy-sharing": "^4.8.0",
"cozy-ui": "^77.8.0",
"cozy-ui": "^78.0.0",
"jest-environment-jsdom-sixteen": "2.0.0",
"react-router-dom": "6.3.0"
},
Expand All @@ -37,14 +37,14 @@
"react-input-mask": "3.0.0-alpha.2"
},
"peerDependencies": {
"cozy-client": ">=34.2.0",
"cozy-client": ">=34.5.0",
"cozy-device-helper": ">=2.2.0",
"cozy-doctypes": ">=1.83.8",
"cozy-harvest-lib": ">=9.10.1",
"cozy-intent": ">=2.2.0",
"cozy-realtime": ">=4.2.0",
"cozy-sharing": ">=4.3.0",
"cozy-ui": ">=77.8.0",
"cozy-ui": ">=78.0.0",
"react-router-dom": ">=6.3.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react'
import PropTypes from 'prop-types'

import { models } from 'cozy-client'

import Typography from 'cozy-ui/transpiled/react/Typography'
import { useI18n } from 'cozy-ui/transpiled/react/I18n'
import { formatLocallyDistanceToNow } from 'cozy-ui/transpiled/react/I18n/format'

const { computeExpirationDate, isExpired } = models.paper

const ExpirationAnnotation = ({ file }) => {
const { t } = useI18n()

if (isExpired(file)) {
return (
<Typography component="span" variant="inherit" color="error">
{t('PapersList.expired')}
</Typography>
)
}

const expirationDate = computeExpirationDate(file)

return (
<Typography component="span" variant="inherit" className="u-warning">
{t('PapersList.expiresIn', {
duration: formatLocallyDistanceToNow(expirationDate)
})}
</Typography>
)
}

ExpirationAnnotation.propTypes = {
file: PropTypes.object.isRequired
}

export default ExpirationAnnotation
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useNavigate, useLocation } from 'react-router-dom'
import PropTypes from 'prop-types'
import cx from 'classnames'

import { useClient } from 'cozy-client'
import { models, useClient } from 'cozy-client'
import { useI18n } from 'cozy-ui/transpiled/react/I18n'
import ListItem from 'cozy-ui/transpiled/react/MuiCozyTheme/ListItem'
import ListItemIcon from 'cozy-ui/transpiled/react/MuiCozyTheme/ListItemIcon'
Expand All @@ -18,6 +18,9 @@ import { makeStyles } from 'cozy-ui/transpiled/react/styles'

import { useMultiSelection } from '../Hooks/useMultiSelection'
import RenameInput from './Renaming/RenameInput'
import ExpirationAnnotation from './ExpirationAnnotation'

const { isExpired, isExpiringSoon } = models.paper

const useStyles = makeStyles(() => ({
checkbox: {
Expand Down Expand Up @@ -84,9 +87,19 @@ const PaperItem = ({
)
}

const secondaryText = `${contactNames ? contactNames : ''}${
contactNames && paperDate ? ' · ' : ''
}${paperDate ? paperDate : ''}`
const secondaryText = (
<>
{contactNames ? contactNames : ''}
{contactNames && paperDate ? ' · ' : ''}
{paperDate ? paperDate : ''}
{(isExpired(paper) || isExpiringSoon(paper)) && (
<>
{contactNames || paperDate ? ' · ' : ''}
<ExpirationAnnotation file={paper} />
</>
)}
</>
)

return (
<>
Expand Down
4 changes: 3 additions & 1 deletion packages/cozy-mespapiers-lib/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@
"PapersListByContact": {
"seeMore": "See more (%{number})"
},
"empty": "You do not have any papers yet in this topic."
"empty": "You do not have any papers yet in this topic.",
"expired": "Expired",
"expiresIn": "Expires in %{duration}"
},
"PlaceholdersList": {
"title": "New paper%{name}"
Expand Down
4 changes: 3 additions & 1 deletion packages/cozy-mespapiers-lib/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@
"PapersListByContact": {
"seeMore": "Voir plus (%{number})"
},
"empty": "Vous n'avez aucun papier dans ce thème."
"empty": "Vous n'avez aucun papier dans ce thème.",
"expired": "Expiré",
"expiresIn": "Expire dans %{duration}"
},
"PlaceholdersList": {
"title": "Nouveau papier%{name}"
Expand Down
33 changes: 15 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6976,16 +6976,17 @@ cozy-client@^32.2.0:
sift "^6.0.0"
url-search-params-polyfill "^8.0.0"

cozy-client@^34.2.0:
version "34.2.0"
resolved "https://registry.yarnpkg.com/cozy-client/-/cozy-client-34.2.0.tgz#d5af57b638b46dc640653e4bc603534353239632"
integrity sha512-t4YYXuGlrStQPEmReJm6nrrVWeKh4Jxrwuh4XSEuHCApH775wPGZZfDs1RdtYx/wCFPfI5PVM0BmvCosGju/bw==
cozy-client@^34.5.0:
version "34.5.0"
resolved "https://registry.yarnpkg.com/cozy-client/-/cozy-client-34.5.0.tgz#862e62d3cb545fa34a66fdc0457521bc2959cb3b"
integrity sha512-oqrJZTg1UtqtsPBMuk4alJP/D3A2JLh0ofzAmikmnxS/wYlsP0Dn6T4Rl6FUWU4udg7wZ+3AU9PkusIWpe4zrg==
dependencies:
"@cozy/minilog" "1.0.0"
"@types/jest" "^26.0.20"
"@types/lodash" "^4.14.170"
btoa "^1.2.1"
cozy-stack-client "^34.1.5"
date-fns "2.29.3"
json-stable-stringify "^1.0.1"
lodash "^4.17.13"
microee "^0.0.6"
Expand Down Expand Up @@ -7114,16 +7115,7 @@ cozy-stack-client@^32.2.0:
mime "^2.4.0"
qs "^6.7.0"

cozy-stack-client@^34.1.0:
version "34.1.0"
resolved "https://registry.yarnpkg.com/cozy-stack-client/-/cozy-stack-client-34.1.0.tgz#2ff134ad3717947c669e49489da3bd1dedae12d0"
integrity sha512-Xg5yqtJTpJtxLVEHJbtrEdIpA/yNePHI4k9jFkoHII72Rb/sW71aWihQHuOhm+7fKyYDeV5hi7cHg82BB6+cAQ==
dependencies:
detect-node "^2.0.4"
mime "^2.4.0"
qs "^6.7.0"

cozy-stack-client@^34.1.5:
cozy-stack-client@^34.1.0, cozy-stack-client@^34.1.5:
version "34.1.5"
resolved "https://registry.yarnpkg.com/cozy-stack-client/-/cozy-stack-client-34.1.5.tgz#28fbc22b72f6343d968d4899d91c70f0261252f4"
integrity sha512-i0GsaaHNI2XmXUncbNPzuFY+DDC4/io3m7mwCmhAFyI/REHPdqOi3Oo5Mb7Euuky4A6iZjAWn5t0F69itv3rvg==
Expand Down Expand Up @@ -7246,10 +7238,10 @@ [email protected]:
react-swipeable-views "^0.13.3"
rooks "^5.11.2"

cozy-ui@^77.8.0:
version "77.8.0"
resolved "https://registry.yarnpkg.com/cozy-ui/-/cozy-ui-77.8.0.tgz#cfbebbc3e15da4a704d3a6680bbd0418d8afdc63"
integrity sha512-pcXdDxApnGkj+g+KZbm4DZbFBUD2dxmlvOYP5t2ZIs4KEgwMUmQ91PSiw1kTL+r4Mw3pVk75VxarB9dBllj1Gg==
cozy-ui@^78.0.0:
version "78.0.0"
resolved "https://registry.yarnpkg.com/cozy-ui/-/cozy-ui-78.0.0.tgz#3109d83f7f288c738e48f8e93de0eedac5c3f697"
integrity sha512-2q+TIWcCpXo57gtmIac4NeNePDJaJcyOUTWqczPnopgzXrd0D1oKOuuULnOoWiun7+6becpviPeutuxo4WBGIw==
dependencies:
"@babel/runtime" "^7.3.4"
"@material-ui/core" "4.12.3"
Expand Down Expand Up @@ -7762,6 +7754,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.23.0.tgz#4e886c941659af0cf7b30fafdd1eaa37e88788a9"
integrity sha512-5ycpauovVyAk0kXNZz6ZoB9AYMZB4DObse7P3BPWmyEjXNORTI8EJ6X0uaSAq4sCHzM1uajzrkr6HnsLQpxGXA==

[email protected]:
version "2.29.3"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.29.3.tgz#27402d2fc67eb442b511b70bbdf98e6411cd68a8"
integrity sha512-dDCnyH2WnnKusqvZZ6+jA1O51Ibt8ZMRNkDZdyAyK4YfbDwa/cEmuztzG5pk6hqlp9aSBPYcjOlktquahGwGeA==

date-now@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/date-now/-/date-now-0.1.4.tgz#eaf439fd4d4848ad74e5cc7dbef200672b9e345b"
Expand Down