Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / packages / components / containers / account / getEmailSubscriptionCategories.tsx
blob3f3bf5ae092d721f9ee95867810f8195f8cee048
1 import { c } from 'ttag';
3 import type { NEWSLETTER_SUBSCRIPTIONS_BITS } from '@proton/shared/lib/helpers/newsletter';
4 import isTruthy from '@proton/utils/isTruthy';
6 import { getEmailSubscriptionsMap } from './constants/email-subscriptions';
8 export const getEmailSubscriptionCategories = (news: NEWSLETTER_SUBSCRIPTIONS_BITS[]) => {
9     const emailSubscriptionMap = getEmailSubscriptionsMap();
10     const categoryTitles = news
11         .map((newsKind) => emailSubscriptionMap[newsKind]?.title)
12         .filter((title) => isTruthy(title));
14     if (!categoryTitles.length) {
15         return null;
16     }
18     const allCategoryTitlesExceptTheLastOne = categoryTitles.slice(0, -1).join(', ');
19     const lastCategoryTitle = categoryTitles[categoryTitles.length - 1];
21     return categoryTitles.length > 1
22         ? c('news').t`${allCategoryTitlesExceptTheLastOne} and ${lastCategoryTitle}`
23         : lastCategoryTitle;