From 07e968ae940dd93795286d90db1d71a1d5c6a6ae Mon Sep 17 00:00:00 2001 From: PolariTOON <36267812+PolariTOON@users.noreply.github.com> Date: Thu, 29 Dec 2022 18:05:29 +0100 Subject: [PATCH] fix: Localize account and group labels in notification settings By using the dedicated helpers. --- src/ducks/groups/helpers.js | 4 +++- .../settings/CategoryAlerts/AccountOrGroupLabel.jsx | 12 ++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/ducks/groups/helpers.js b/src/ducks/groups/helpers.js index 11a9af4f0a..ef9870b9e2 100644 --- a/src/ducks/groups/helpers.js +++ b/src/ducks/groups/helpers.js @@ -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 ( diff --git a/src/ducks/settings/CategoryAlerts/AccountOrGroupLabel.jsx b/src/ducks/settings/CategoryAlerts/AccountOrGroupLabel.jsx index 94382445a5..8d01304fe3 100644 --- a/src/ducks/settings/CategoryAlerts/AccountOrGroupLabel.jsx +++ b/src/ducks/settings/CategoryAlerts/AccountOrGroupLabel.jsx @@ -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 => ({