Remove payments API routing initialization
[ProtonMail-WebClient.git] / packages / components / containers / recovery / ConfirmDisableSessionRecoveryModal.tsx
blob3c926087ed1a2d73c3601b4833227a2f2294a3a3
1 import { c } from 'ttag';
3 import { Button } from '@proton/atoms';
4 import Prompt from '@proton/components/components/prompt/Prompt';
5 import useApi from '@proton/components/hooks/useApi';
6 import useEventManager from '@proton/components/hooks/useEventManager';
7 import useLoading from '@proton/hooks/useLoading';
8 import metrics, { observeApiError } from '@proton/metrics';
9 import { updateSessionAccountRecovery } from '@proton/shared/lib/api/sessionRecovery';
10 import noop from '@proton/utils/noop';
12 interface Props {
13     onClose: () => void;
14     open: boolean;
17 const ConfirmDisableSessionRecoveryModal = ({ open, onClose }: Props) => {
18     const api = useApi();
19     const { call } = useEventManager();
21     const [submitting, withSubmitting] = useLoading();
23     const handleDisableSessionRecoveryToggle = async () => {
24         try {
25             await api(updateSessionAccountRecovery({ SessionAccountRecovery: 0 }));
26             await call();
27             onClose();
28             metrics.core_session_recovery_settings_update_total.increment({
29                 status: 'success',
30             });
31         } catch (error) {
32             observeApiError(error, (status) =>
33                 metrics.core_session_recovery_settings_update_total.increment({
34                     status,
35                 })
36             );
37         }
38     };
40     const handleClose = submitting ? noop : onClose;
42     return (
43         <Prompt
44             open={open}
45             onClose={handleClose}
46             title={c('session_recovery:disable:title').t`Disable password reset?`}
47             buttons={[
48                 <Button
49                     color="danger"
50                     loading={submitting}
51                     onClick={() => {
52                         void withSubmitting(handleDisableSessionRecoveryToggle());
53                     }}
54                 >
55                     {c('session_recovery:disable:action').t`Disable password reset`}
56                 </Button>,
57                 <Button onClick={onClose} disabled={submitting}>{c('Action').t`Cancel`}</Button>,
58             ]}
59         >
60             <p>
61                 {c('session_recovery:disable:info')
62                     .t`You will no longer be able to request a password reset from your account settings.`}
63             </p>
64             <p>{c('session_recovery:disable:info').t`Make sure you have access to a recovery method.`}</p>
65         </Prompt>
66     );
69 export default ConfirmDisableSessionRecoveryModal;