1 import { c, msgid } from 'ttag';
3 import Icon from '@proton/components/components/icon/Icon';
4 import SettingsLink from '@proton/components/components/link/SettingsLink';
5 import Loader from '@proton/components/components/loader/Loader';
6 import useConfig from '@proton/components/hooks/useConfig';
7 import { PLAN_SERVICES } from '@proton/payments';
8 import { APPS, CALENDAR_APP_NAME, MAIL_APP_NAME, VPN_APP_NAME } from '@proton/shared/lib/constants';
9 import { getInitials } from '@proton/shared/lib/helpers/string';
10 import { getPlan } from '@proton/shared/lib/helpers/subscription';
11 import { getClosestLocaleCode } from '@proton/shared/lib/i18n/helper';
18 } from '@proton/shared/lib/interfaces';
22 userSettings: UserSettings;
23 organization?: Partial<Organization>;
24 subscription?: Subscription;
27 const SummarySection = ({ user, userSettings, organization, subscription }: Props) => {
28 const { APP_NAME, LOCALES = {} } = useConfig();
29 const { Email, DisplayName, Name, canPay, isAdmin } = user;
30 const { UsedMembers = 0, UsedDomains = 0, MaxMembers = 0, MaxDomains = 0 } = organization || {};
31 const initials = getInitials(DisplayName || Name || Email || '');
32 const vpnPlan = subscription ? getPlan(subscription, PLAN_SERVICES.VPN) : undefined;
33 const mailPlan = subscription ? getPlan(subscription, PLAN_SERVICES.MAIL) : undefined;
35 const getPlanTitle = (plan: SubscriptionPlan | undefined, service: string) => {
37 return `${service} Free`;
43 const closestLocale = getClosestLocaleCode(userSettings?.Locale, LOCALES);
44 const languageText = LOCALES[closestLocale];
47 <div className="border bg-norm shadow-norm p-6">
48 <div className="mb-8 text-center">
49 <span className="user-initials rounded text-semibold p-1 mb-2 inline-flex bg-primary">
50 <span className="dropdown-logout-text m-auto">{initials}</span>
52 <h3 className="mb-2 lh-rg text-ellipsis" title={DisplayName || Name}>
55 {organization?.Name ? (
56 <p className="mt-0 mb-2 text-ellipsis" title={organization.Name}>
60 <p className="my-0 text-ellipsis" title={Email}>
65 <div className="mb-4">
66 <strong className="block mb-2">{c('Title').t`Plans`}</strong>
70 <ul className="unstyled my-0">
71 <li className="flex flex-nowrap items-center">
72 <Icon name="brand-proton-vpn" className="mr-2 shrink-0" />
73 <span className="flex-1">{getPlanTitle(vpnPlan, VPN_APP_NAME)}</span>
75 <li className="flex flex-nowrap items-center">
76 <Icon name="brand-proton-mail" className="mr-2 shrink-0" />
77 <span className="flex-1">{getPlanTitle(mailPlan, MAIL_APP_NAME)}</span>
84 <div className="mb-4">
85 <strong className="block mb-2">{c('Title').t`Default language`}</strong>
86 <ul className="unstyled my-0">
87 <li className="flex flex-nowrap items-center">
88 <Icon name="globe" className="mr-2 shrink-0" />
89 <span className="flex-1">{languageText}</span>
95 <div className="mb-4">
96 <strong className="block mb-2">{c('Title').t`Your organization`}</strong>
100 <ul className="unstyled my-0">
102 {c('Organization attribute').ngettext(
103 msgid`${UsedMembers}/${MaxMembers} active user`,
104 `${UsedMembers}/${MaxMembers} active users`,
109 {c('Organization attribute').ngettext(
110 msgid`${UsedDomains}/${MaxDomains} custom domain`,
111 `${UsedDomains}/${MaxDomains} custom domains`,
119 {APP_NAME === APPS.PROTONACCOUNT ? (
120 <div className="mb-4">
121 <strong className="block mb-2">{c('Title').t`Application settings`}</strong>
122 <ul className="unstyled my-0">
123 <li className="flex flex-nowrap items-center">
124 <Icon name="brand-proton-mail" className="mr-2 shrink-0" />
125 <SettingsLink path="/general" app={APPS.PROTONMAIL}>
126 {c('Link').t`${MAIL_APP_NAME} settings`}
129 <li className="flex flex-nowrap items-center">
130 <Icon name="brand-proton-calendar" className="mr-2 shrink-0" />
131 <SettingsLink path="/general" app={APPS.PROTONCALENDAR}>
132 {c('Link').t`${CALENDAR_APP_NAME} settings`}
138 {APP_NAME === APPS.PROTONACCOUNT ? null : (
139 <div className="mb-4">
140 <SettingsLink path="/dashboard">{c('Link').t`Manage account`}</SettingsLink>
147 export default SummarySection;