1 import { c } from 'ttag';
3 import Info from '@proton/components/components/link/Info';
4 import Toggle from '@proton/components/components/toggle/Toggle';
5 import SettingsLayout from '@proton/components/containers/account/SettingsLayout';
6 import SettingsLayoutLeft from '@proton/components/containers/account/SettingsLayoutLeft';
7 import SettingsLayoutRight from '@proton/components/containers/account/SettingsLayoutRight';
8 import SettingsSection from '@proton/components/containers/account/SettingsSection';
9 import { useLoading } from '@proton/hooks';
10 import { updateCalendarUserSettings } from '@proton/shared/lib/api/calendars';
11 import { getClosestLocaleCode } from '@proton/shared/lib/i18n/helper';
12 import type { TtagLocaleMap } from '@proton/shared/lib/interfaces/Locale';
13 import type { CalendarUserSettings } from '@proton/shared/lib/interfaces/calendar';
15 import { useApi, useEventManager, useNotifications } from '../../../hooks';
16 import InviteLocaleSelector from './InviteLocaleSelector';
19 calendarUserSettings: CalendarUserSettings;
20 locales: TtagLocaleMap;
23 const CalendarInvitationsSection = ({ calendarUserSettings: { InviteLocale, AutoImportInvite }, locales }: Props) => {
25 const { call } = useEventManager();
26 const { createNotification } = useNotifications();
28 const [loadingInviteLocale, withLoadingInviteLocale] = useLoading();
29 const [loadingAutoImportInvite, withLoadingAutoImportInvite] = useLoading();
31 const handleChange = async (data: Partial<CalendarUserSettings>) => {
32 await api(updateCalendarUserSettings(data));
34 createNotification({ text: c('Success').t`Preference saved` });
37 const displayedLocale = InviteLocale === null ? null : getClosestLocaleCode(InviteLocale, locales);
43 <label className="text-semibold" htmlFor="invite-locale" id="label-invite-local">
45 // translator: the full sentence will be "Send invites in [LANGUAGE]", where [LANGUAGE] is a dropdown with language options. E.g. "Send invites in [ENGLISH]"
49 buttonClass="ml-2 inline-flex"
50 title={c('Info').t`Event invitations and RSVPs will be sent in this language.`}
57 aria-describedby="label-invite-local"
58 locale={displayedLocale}
60 loading={loadingInviteLocale}
61 onChange={(InviteLocale) => withLoadingInviteLocale(handleChange({ InviteLocale }))}
63 </SettingsLayoutRight>
67 <label className="text-semibold inline-block" htmlFor="auto-import-invitations">
68 <span>{c('Auto import invitations setting').jt`Add to calendar and mark as pending`}</span>
70 buttonClass="ml-2 inline-flex"
72 .t`You still need to reply to invitations for the host to see your response.`}
76 <SettingsLayoutRight isToggleContainer>
78 id="auto-import-invitations"
79 aria-describedby="auto-import-invitations"
80 loading={loadingAutoImportInvite}
81 checked={!!AutoImportInvite}
82 onChange={({ target }) =>
83 withLoadingAutoImportInvite(
85 AutoImportInvite: +target.checked,
90 </SettingsLayoutRight>
96 export default CalendarInvitationsSection;