Skip to content

Commit

Permalink
fix: Improve secondary text of GroupRecipient
Browse files Browse the repository at this point in the history
  • Loading branch information
cballevre committed Apr 8, 2024
1 parent 632658a commit d747f9c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/cozy-sharing/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@
}
},
"GroupRecipient": {
"secondary": "%{nbMemberReady}/%{nbMember} members",
"secondary": "%{memberCount} member |||| %{memberCount} members",
"secondary_you": "including you"
},
"RevokeGroupItem": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cozy-sharing/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@
}
},
"GroupRecipient": {
"secondary": "%{nbMemberReady}/%{nbMember} membres",
"secondary": "%{memberCount} membre |||| %{memberCount} membres",
"secondary_you": "dont vous"
},
"RevokeGroupItem": {
Expand Down
19 changes: 11 additions & 8 deletions packages/cozy-sharing/src/components/Recipient/GroupRecipient.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'

import { GroupRecipientDetail } from './GroupRecipientDetail'
import { GroupRecipientPermissions } from './GroupRecipientPermissions'
import { FADE_IN_DURATION } from '../../helpers/recipients'
import {
FADE_IN_DURATION,
getGroupRecipientSecondaryText
} from '../../helpers/recipients'
import { GroupAvatar } from '../Avatar/GroupAvatar'

const GroupRecipient = props => {
Expand All @@ -27,7 +30,7 @@ const GroupRecipient = props => {
const nbMemberReady = members.filter(
member => !['revoked', 'mail-not-sent'].includes(member.status)
).length
const isCurrentInstanceInsideMembers = members.some(
const isUserInsideMembers = members.some(
member => member.instance === client.options.uri
)

Expand Down Expand Up @@ -56,12 +59,12 @@ const GroupRecipient = props => {
{name}
</Typography>
}
secondary={
t('GroupRecipient.secondary', { nbMember, nbMemberReady }) +
(isCurrentInstanceInsideMembers
? ` (${t('GroupRecipient.secondary_you')})`
: '')
}
secondary={getGroupRecipientSecondaryText({
t,
nbMember,
nbMemberReady,
isUserInsideMembers
})}
/>
<ListItemSecondaryAction className={isMobile ? 'u-mr-1' : 'u-mr-2'}>
<GroupRecipientPermissions {...props} />
Expand Down
19 changes: 19 additions & 0 deletions packages/cozy-sharing/src/helpers/recipients.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,22 @@ export const spreadGroupAndMergeRecipients = (
export const mergeRecipients = (recipients, newRecipient) => {
return [...recipients, newRecipient]
}

export const getGroupRecipientSecondaryText = ({
nbMember,
nbMemberReady,
t,
isUserInsideMembers
}) => {
const memberCount =
nbMember === nbMemberReady ? nbMember : [nbMemberReady, nbMember].join('/')
const secondary = t('GroupRecipient.secondary', {
memberCount,
smart_count: nbMember
})

return (
secondary +
(isUserInsideMembers ? ` (${t('GroupRecipient.secondary_you')})` : '')
)
}

0 comments on commit d747f9c

Please sign in to comment.