1 import { useState } from 'react';
3 import { c } from 'ttag';
5 import { Button } from '@proton/atoms';
6 import { useCalendarUserSettings } from '@proton/calendar/calendarUserSettings/hooks';
7 import { Checkbox, Prompt, useApi, useEventManager, useNotifications } from '@proton/components';
8 import { useLoading } from '@proton/hooks';
9 import { updateCalendarUserSettings } from '@proton/shared/lib/api/calendars';
17 const AskUpdateTimezoneModal = ({ localTzid, onClose, isOpen }: Props) => {
19 const { call } = useEventManager();
20 const { createNotification } = useNotifications();
21 const [calendarUserSettings] = useCalendarUserSettings();
23 const [updating, withUpdating] = useLoading();
24 const [cancelling, withCancelling] = useLoading();
26 const [autoDetectPrimaryTimezone, setAutoDetectPrimaryTimezone] = useState<boolean>(
27 !!calendarUserSettings?.AutoDetectPrimaryTimezone
30 const handleUpdateTimezone = async () => {
32 updateCalendarUserSettings({
33 PrimaryTimezone: localTzid,
34 AutoDetectPrimaryTimezone: +autoDetectPrimaryTimezone,
39 createNotification({ text: c('Success').t`Preference saved` });
42 const handleCancel = async () => {
43 if (autoDetectPrimaryTimezone !== !!calendarUserSettings?.AutoDetectPrimaryTimezone) {
45 updateCalendarUserSettings({
46 AutoDetectPrimaryTimezone: +autoDetectPrimaryTimezone,
50 createNotification({ text: c('Success').t`Preference saved` });
56 const timezone = <b key={0}>{localTzid}</b>;
62 title={c('Modal title').t`Time zone changed`}
67 void withUpdating(handleUpdateTimezone());
71 {c('Action').t`Update`}
76 void withCancelling(handleCancel());
79 {c('Action').t`Keep current time zone`}
84 id="autodetect-primary-timezone"
86 checked={!autoDetectPrimaryTimezone}
88 onChange={() => setAutoDetectPrimaryTimezone(!autoDetectPrimaryTimezone)}
90 {c("Don't ask to update timezone checkbox label").t`Don't ask again`}
96 .jt`Your system time zone seems to have changed to ${timezone}. Do you want to update your time zone preference?`}
102 export default AskUpdateTimezoneModal;