Merge branch 'DRVDOC-1260' into 'main'
[ProtonMail-WebClient.git] / packages / components / containers / addresses / DeleteAddressPrompt.tsx
blob8dae79531e56b5733f074d9d54a559fa1d3a9e3f
1 import type { PropsWithChildren } from 'react';
3 import { c } from 'ttag';
5 import { Button } from '@proton/atoms';
6 import type { ModalProps } from '@proton/components/components/modalTwo/Modal';
7 import Prompt from '@proton/components/components/prompt/Prompt';
8 import { useLoading } from '@proton/hooks';
10 interface Props extends ModalProps, PropsWithChildren {
11     onDeleteAddress: () => Promise<void>;
12     email: string;
13     type?: 'permanent';
16 const DeleteAddressPrompt = ({ title, email, onDeleteAddress, children, type, ...rest }: Props) => {
17     const [loading, withLoading] = useLoading();
19     const address = (
20         <strong key="address" className="text-break">
21             {email}
22         </strong>
23     );
25     return (
26         <Prompt
27             title={
28                 type === 'permanent'
29                     ? c('Delete address prompt').t`Delete address permanently?`
30                     : c('Delete address prompt').t`Delete address?`
31             }
32             open={rest.open}
33             onClose={rest.onClose}
34             buttons={[
35                 <Button
36                     onClick={() => {
37                         withLoading(onDeleteAddress().then(rest.onClose));
38                     }}
39                     loading={loading}
40                     color="danger"
41                 >{c('Delete address prompt').t`Delete address`}</Button>,
42                 <Button onClick={rest.onClose} disabled={loading}>{c('Action').t`Cancel`}</Button>,
43             ]}
44         >
45             {(() => {
46                 if (type === 'permanent') {
47                     return (
48                         <>
49                             {c('Delete address prompt')
50                                 .jt`Once deleted, this address ${address} can't be used again by anyone else.`}
51                             <br />
52                             <br />
53                             {c('Delete address prompt').t`You can only delete 1 address per year.`}
54                         </>
55                     );
56                 }
57                 return (
58                     <>
59                         {c('Delete address prompt')
60                             .jt`Please note that if you delete this address ${address}, you will no longer be able to send or receive emails using this address.`}
61                         <br />
62                         <br />
63                         {c('Delete address prompt').t`Are you sure you want to delete this address?`}
64                     </>
65                 );
66             })()}
67             {type === 'permanent'}
68             {children}
69         </Prompt>
70     );
73 export default DeleteAddressPrompt;