1 import { c } from 'ttag';
3 import { useCalendarUserSettings } from '@proton/calendar/calendarUserSettings/hooks';
8 DrawerAppScrollContainer,
13 PrimaryTimezoneSelector,
14 QuickSettingsButtonSection,
15 QuickSettingsSectionRow,
16 SecondaryTimezoneSelector,
17 ShowSecondaryTimezoneToggle,
19 ViewPreferenceSelector,
22 useConfirmActionModal,
25 } from '@proton/components';
26 import { useLoading } from '@proton/hooks';
27 import { updateCalendarUserSettings } from '@proton/shared/lib/api/calendars';
28 import { DEFAULT_CALENDAR_USER_SETTINGS } from '@proton/shared/lib/calendar/calendar';
29 import type { CalendarUserSettings } from '@proton/shared/lib/interfaces/calendar';
31 import NukeSearchIndexButton from '../../containers/calendar/confirmationModals/NukeSearchIndexButton';
34 onBackFromSearch: () => void;
37 const CalendarQuickSettings = ({ onBackFromSearch }: Props) => {
39 const { call } = useEventManager();
40 const { createNotification } = useNotifications();
42 const [calendarUserSettings = DEFAULT_CALENDAR_USER_SETTINGS, loadingCalendarUserSettings] =
43 useCalendarUserSettings();
45 const [loadingWeekNumberDisplay, withLoadingWeekNumberDisplay] = useLoading();
46 const [loadingView, withLoadingView] = useLoading();
48 const [confirmModal, showConfirmModal] = useConfirmActionModal();
50 const handleChange = async (data: Partial<CalendarUserSettings>) => {
51 await api(updateCalendarUserSettings(data));
53 createNotification({ text: c('Success').t`Preference saved` });
56 const handleChangeShowWeekNumbers = async (show: number) => {
57 await api(updateCalendarUserSettings({ DisplayWeekNumber: show }));
59 createNotification({ text: c('Success').t`Preference saved` });
62 if (loadingCalendarUserSettings) {
67 <DrawerAppScrollContainer>
68 <DrawerAllSettingsView />
69 <DrawerDownloadApps />
72 <QuickSettingsSectionRow
73 label={c('Label').t`Default view`}
74 labelInfo={<Info title={c('Info').t`Week and month views only apply to desktop.`} />}
76 <ViewPreferenceSelector
78 view={calendarUserSettings.ViewPreference}
80 onChange={(ViewPreference) => withLoadingView(handleChange({ ViewPreference }))}
81 className="quickSettingsSectionRow-select w-auto"
87 <QuickSettingsSectionRow
88 label={c('Label').t`Week start`}
90 <WeekStartSelector className="quickSettingsSectionRow-select w-auto" unstyledSelect shortText />
94 <QuickSettingsSectionRow
95 label={c('Label').t`Show week numbers`}
98 id="week-numbers-display"
99 aria-describedby="week-numbers-display"
100 checked={!!calendarUserSettings.DisplayWeekNumber}
101 loading={loadingWeekNumberDisplay}
102 onChange={({ target: { checked } }) =>
103 withLoadingWeekNumberDisplay(handleChangeShowWeekNumbers(+checked))
111 <DrawerAppHeadline>{c('Label').t`Time zone`}</DrawerAppHeadline>
113 <QuickSettingsSectionRow
114 // translator: As in Primary time zone
115 label={c('Label').t`Primary`}
117 <PrimaryTimezoneSelector
118 id="primary-timezone"
119 calendarUserSettings={calendarUserSettings}
121 abbreviatedTimezone="city"
123 selectMaxHeight="20rem"
124 data-testid="quick-settings/primary-time-zone:dropdown"
130 <QuickSettingsSectionRow
131 // translator: As in "Show secondary time zone"
132 label={c('Label').t`Secondary time zone`}
133 action={<ShowSecondaryTimezoneToggle calendarUserSettings={calendarUserSettings} />}
136 {!!calendarUserSettings.DisplaySecondaryTimezone && (
137 <QuickSettingsSectionRow
138 // translator: As in secondary time zone
139 label={c('Label').t`Secondary`}
141 <SecondaryTimezoneSelector
142 id="secondary-timezone"
143 calendarUserSettings={calendarUserSettings}
145 abbreviatedTimezone="city"
147 selectMaxHeight="20rem"
148 data-testid="quick-settings/secondary-time-zone:dropdown"
155 <DefaultQuickSettings />
156 <QuickSettingsButtonSection>
157 <NukeSearchIndexButton showConfirmModal={showConfirmModal} onBackFromSearch={onBackFromSearch} />
158 </QuickSettingsButtonSection>
160 </DrawerAppScrollContainer>
164 export default CalendarQuickSettings;