Skip to content

Commit

Permalink
Merge pull request #2588 from cozy/fix/use-helpers-for-account-and-gr…
Browse files Browse the repository at this point in the history
…oup-labels-in-notification-settings

Localize account and group labels in notification settings by using the dedicated helpers
  • Loading branch information
PolariTOON authored Dec 30, 2022
2 parents e1a2b54 + 07e968a commit 73c7a9b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/ducks/groups/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export const isReimbursementsVirtualGroup = group =>
Boolean(group.virtual && group._id === 'Reimbursements')

export const getGroupLabel = (group, t) => {
if (isReimbursementsVirtualGroup(group)) {
if (group == null) {
return ''
} else if (isReimbursementsVirtualGroup(group)) {
return t(`Data.accountTypes.Reimbursements`, { _: 'other' })
} else if (group.virtual) {
return (
Expand Down
12 changes: 8 additions & 4 deletions src/ducks/settings/CategoryAlerts/AccountOrGroupLabel.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { useI18n } from 'cozy-ui/transpiled/react/I18n'

import { getGroupsById, getAccountsById } from 'selectors'
import { connect } from 'react-redux'
import { ACCOUNT_DOCTYPE, GROUP_DOCTYPE } from 'doctypes'
import { getGroupLabel } from 'ducks/groups/helpers'
import { getAccountLabel } from 'ducks/account/helpers.js'

/**
* From a partial doc { _id, _type }, finds the account/group from the redux store
* and displays its label
*/
const AccountOrGroupLabel = ({ groupsById, accountsById, doc }) => {
let docInfo
const { t } = useI18n()
if (doc._type == ACCOUNT_DOCTYPE) {
docInfo = accountsById[doc._id]
return getAccountLabel(accountsById[doc._id], t)
} else if (doc._type == GROUP_DOCTYPE) {
docInfo = groupsById[doc._id]
return getGroupLabel(groupsById[doc._id], t)
}
return docInfo ? docInfo.label : null
return ''
}

export default connect(state => ({
Expand Down

0 comments on commit 73c7a9b

Please sign in to comment.