Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / applications / drive / src / app / components / modals / FilesRecoveryModal / FilesRecoveryModal.tsx
blob91d6b4c4a69e70bcf8a871c7d939167beb4a45ca
1 import { c } from 'ttag';
3 import type { ModalStateProps } from '@proton/components';
4 import { ModalTwo, useModalTwoStatic, useNotifications } from '@proton/components';
5 import { useLoading } from '@proton/hooks';
7 import { useLockedVolume } from '../../../store';
8 import FilesRecoveryState from './FilesRecoveryState';
10 const FilesRecoveryModal = ({ onClose, ...modalProps }: ModalStateProps) => {
11     const { restoreVolumes } = useLockedVolume();
12     const [recovering, withRecovering] = useLoading();
13     const { createNotification } = useNotifications();
15     const handleRecoveryClick = async () => {
16         await withRecovering(
17             restoreVolumes(new AbortController().signal)
18                 .then(() => {
19                     createNotification({
20                         text: c('Success').t`Recovery has started`,
21                     });
22                 })
23                 .catch(() => onClose?.())
24         );
26         onClose?.();
27     };
29     return (
30         <ModalTwo onClose={onClose} {...modalProps}>
31             <FilesRecoveryState recovering={recovering} onRecovery={handleRecoveryClick} onClose={onClose} />
32         </ModalTwo>
33     );
36 export default FilesRecoveryModal;
38 export const useFilesRecoveryModal = () => {
39     return useModalTwoStatic(FilesRecoveryModal);