Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / packages / components / containers / security / PromptPinToggle.tsx
blob263344161673bae07ac92a7d0f271726f529c4cc
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 { updatePromptPin } from '@proton/shared/lib/api/mailSettings';
12 import { DEFAULT_MAILSETTINGS } from '@proton/shared/lib/mail/mailSettings';
14 interface Props {
15     id?: string;
18 const PromptPinToggle = ({ id }: Props) => {
19     const { createNotification } = useNotifications();
20     const { call } = useEventManager();
21     const api = useApi();
22     const [loading, withLoading] = useLoading();
23     const [{ PromptPin } = DEFAULT_MAILSETTINGS] = useMailSettings();
25     const handleChange = async ({ target }: ChangeEvent<HTMLInputElement>) => {
26         await api(updatePromptPin(+target.checked));
27         await call();
28         createNotification({ text: c('Success').t`Preference saved` });
29     };
31     return <Toggle id={id} loading={loading} checked={!!PromptPin} onChange={(e) => withLoading(handleChange(e))} />;
34 export default PromptPinToggle;