1 import type { ChangeEvent } from 'react';
3 import { c } from 'ttag';
5 import Toggle from '@proton/components/components/toggle/Toggle';
6 import useApi from '@proton/components/hooks/useApi';
7 import useEventManager from '@proton/components/hooks/useEventManager';
8 import useNotifications from '@proton/components/hooks/useNotifications';
9 import useLoading from '@proton/hooks/useLoading';
10 import { useMailSettings } from '@proton/mail/mailSettings/hooks';
11 import { updateKT } from '@proton/shared/lib/api/mailSettings';
12 import { DEFAULT_MAILSETTINGS } from '@proton/shared/lib/mail/mailSettings';
18 const KTToggle = ({ id }: Props) => {
19 const { createNotification } = useNotifications();
20 const { call } = useEventManager();
22 const [loading, withLoading] = useLoading();
23 const [{ KT } = DEFAULT_MAILSETTINGS] = useMailSettings();
25 const handleChange = async ({ target }: ChangeEvent<HTMLInputElement>) => {
26 await api(updateKT(+target.checked));
28 createNotification({ text: c('Success').t`Preference saved` });
31 return <Toggle id={id} loading={loading} checked={!!KT} onChange={(e) => withLoading(handleChange(e))} />;
34 export default KTToggle;