Remove payments API routing initialization
[ProtonMail-WebClient.git] / packages / components / containers / contacts / hooks / useContactModals.tsx
blob54dccc64d1a3426fce64dca0a7b06b5d82816511
1 import { useModalTwo, useModalTwoStatic } from '@proton/components/components/modalTwo/useModalTwo';
2 import type { Recipient } from '@proton/shared/lib/interfaces';
3 import noop from '@proton/utils/noop';
5 import type { ContactEditProps } from '../edit/ContactEditModal';
6 import ContactEditModal from '../edit/ContactEditModal';
7 import type { ContactEmailSettingsProps } from '../email/ContactEmailSettingsModal';
8 import ContactEmailSettingsModal from '../email/ContactEmailSettingsModal';
9 import type { ContactGroupDeleteProps } from '../group/ContactGroupDeleteModal';
10 import ContactGroupDeleteModal from '../group/ContactGroupDeleteModal';
11 import ContactGroupDetailsModal from '../group/ContactGroupDetailsModal';
12 import type { ContactGroupEditProps } from '../group/ContactGroupEditModal';
13 import ContactGroupEditModal from '../group/ContactGroupEditModal';
14 import type { ContactClearDataConfirmProps } from '../modals/ContactClearDataConfirmModal';
15 import ContactClearDataConfirmModal from '../modals/ContactClearDataConfirmModal';
16 import type { ContactClearDataExecutionProps } from '../modals/ContactClearDataExecutionModal';
17 import ContactClearDataExecutionModal from '../modals/ContactClearDataExecutionModal';
18 import ContactDecryptionErrorModal from '../modals/ContactDecryptionErrorModal';
19 import type { ContactDeleteProps } from '../modals/ContactDeleteModal';
20 import ContactDeleteModal from '../modals/ContactDeleteModal';
21 import type { ContactExportingProps } from '../modals/ContactExportingModal';
22 import ContactExportingModal from '../modals/ContactExportingModal';
23 import type { ContactGroupLimitReachedProps } from '../modals/ContactGroupLimitReachedModal';
24 import ContactGroupLimitReachedModal from '../modals/ContactGroupLimitReachedModal';
25 import type { ContactImageProps } from '../modals/ContactImageModal';
26 import ContactImageModal from '../modals/ContactImageModal';
27 import ContactResignExecutionModal from '../modals/ContactResignExecutionModal';
28 import ContactSignatureErrorModal from '../modals/ContactSignatureErrorModal';
29 import ContactUpgradeModal from '../modals/ContactUpgradeModal';
30 import type { SelectEmailsProps } from '../modals/SelectEmailsModal';
31 import SelectEmailsModal from '../modals/SelectEmailsModal';
32 import ContactDetailsModal from '../view/ContactDetailsModal';
34 interface Props {
35     onMailTo?: (email: string) => void;
36     onCompose?: (recipients: Recipient[], attachments: File[]) => void;
37     onChange?: () => void;
40 export const useContactModals = ({ onMailTo = noop, onCompose, onChange }: Props = {}) => {
41     const [contactDetailsModal, handleShowContactDetailsModal] = useModalTwoStatic(ContactDetailsModal);
43     const [contactEditModal, handleShowContactEditModal] = useModalTwoStatic(ContactEditModal);
45     const [contactDeleteModal, handleShowContactDeleteModal] = useModalTwoStatic(ContactDeleteModal);
47     const [contactEmailSettingsModal, handleShowContactEmailSettingsModal] =
48         useModalTwoStatic(ContactEmailSettingsModal);
50     const [contactExportingModal, handleShowContactExportingModal] = useModalTwoStatic(ContactExportingModal);
52     const [contactGroupDeleteModal, handleShowContactGroupDeleteModal] = useModalTwoStatic(ContactGroupDeleteModal);
54     const [contactGroupEditModal, handleShowContactGroupEditModal] = useModalTwoStatic(ContactGroupEditModal);
56     const [contactGroupDetailsModal, handleShowContactGroupDetailsModal] = useModalTwoStatic(ContactGroupDetailsModal);
58     const [contactUpgradeModal, handleShowContactUpgradeModal] = useModalTwoStatic(ContactUpgradeModal);
60     const [contactImageModal, handleShowContactImageModal] = useModalTwoStatic(ContactImageModal);
62     const [contactSignatureErrorModal, handleShowContactSignatureErrorModal] =
63         useModalTwoStatic(ContactSignatureErrorModal);
65     const [contactResignExecutionModal, handleShowContactResignExecutionModal] =
66         useModalTwoStatic(ContactResignExecutionModal);
68     const [contactDecryptionErrorModal, handleShowContactDecryptionErrorModal] =
69         useModalTwoStatic(ContactDecryptionErrorModal);
71     const [contactClearDataConfirmModal, handleShowContactClearDataConfirmModal] =
72         useModalTwoStatic(ContactClearDataConfirmModal);
74     const [contactClearDataExecutionModal, handleShowContactClearDataExecutionModal] =
75         useModalTwoStatic(ContactClearDataExecutionModal);
77     const [contactSelectEmailsModal, handleShowContactSelectEmailsModal] = useModalTwo(SelectEmailsModal);
79     const [contactGroupLimitReachedModal, handleShowContactGroupLimitReachedModal] =
80         useModalTwoStatic(ContactGroupLimitReachedModal);
82     const handleUpgrade = () => {
83         handleShowContactUpgradeModal({});
84     };
86     const handleSelectImage = (props: ContactImageProps) => {
87         handleShowContactImageModal(props);
88     };
90     const handleResign = () => {
91         handleShowContactResignExecutionModal({});
92     };
94     const handleSignatureError = (contactID: string) => {
95         handleShowContactSignatureErrorModal({ contactID, onResign: handleResign });
96     };
98     const handleClearData = (props: ContactClearDataExecutionProps) => {
99         handleShowContactClearDataExecutionModal(props);
100     };
102     const handleClearDataConfirm = (props: ContactClearDataConfirmProps) => {
103         handleShowContactClearDataConfirmModal({ ...props, onClearData: handleClearData });
104     };
106     const handleDecryptionError = (contactID: string) => {
107         handleShowContactDecryptionErrorModal({ contactID, onClearDataConfirm: handleClearDataConfirm });
108     };
110     const handleGroupEdit = (props: ContactGroupEditProps) => {
111         handleShowContactGroupEditModal(props);
112     };
114     const handleContactLimitReached = (props: ContactGroupLimitReachedProps) => {
115         return handleShowContactGroupLimitReachedModal(props);
116     };
118     const handleEdit = (props: ContactEditProps) => {
119         handleShowContactEditModal({
120             ...props,
121             onChange,
122             onUpgrade: handleUpgrade,
123             onSelectImage: handleSelectImage,
124             onGroupEdit: handleGroupEdit,
125             onLimitReached: handleContactLimitReached,
126         });
127     };
129     const handleDelete = (props: ContactDeleteProps) => {
130         handleShowContactDeleteModal({
131             ...props,
132             onDelete: (...args) => {
133                 onChange?.();
134                 props.onDelete?.(...args);
135             },
136         });
137     };
139     const handleEmailSettings = (props: ContactEmailSettingsProps) => {
140         handleShowContactEmailSettingsModal(props);
141     };
143     const handleExport = (props: ContactExportingProps = {}) => {
144         handleShowContactExportingModal(props);
145     };
147     const handleGroupDelete = (props: ContactGroupDeleteProps) => {
148         handleShowContactGroupDeleteModal(props);
149     };
151     const handleGroupDetails = (contactGroupID: string, onCloseContactDetailsModal?: () => void) => {
152         handleShowContactGroupDetailsModal({
153             contactGroupID,
154             onEdit: handleGroupEdit,
155             onDelete: handleGroupDelete,
156             onExport: handleExport,
157             onUpgrade: handleUpgrade,
158             onCompose: onCompose,
159             onCloseContactDetailsModal, // We want to close the contact details modal onCompose if we opened group details modal from contact details modal
160         });
161     };
163     const handleDetails = (contactID: string) => {
164         handleShowContactDetailsModal({
165             contactID,
166             onMailTo,
167             onEdit: handleEdit,
168             onDelete: handleDelete,
169             onEmailSettings: handleEmailSettings,
170             onGroupDetails: handleGroupDetails,
171             onGroupEdit: handleGroupEdit,
172             onUpgrade: handleUpgrade,
173             onSignatureError: handleSignatureError,
174             onDecryptionError: handleDecryptionError,
175         });
176     };
178     const handleSelectEmails = (props: SelectEmailsProps) => {
179         return handleShowContactSelectEmailsModal(props);
180     };
182     const modals = (
183         <>
184             {contactDetailsModal}
185             {contactEditModal}
186             {contactDeleteModal}
187             {contactEmailSettingsModal}
188             {contactExportingModal}
189             {contactGroupDetailsModal}
190             {contactGroupEditModal}
191             {contactGroupDeleteModal}
192             {contactUpgradeModal}
193             {contactImageModal}
194             {contactSignatureErrorModal}
195             {contactResignExecutionModal}
196             {contactDecryptionErrorModal}
197             {contactClearDataConfirmModal}
198             {contactClearDataExecutionModal}
199             {contactSelectEmailsModal}
200             {contactGroupLimitReachedModal}
201         </>
202     );
204     return {
205         modals,
206         onEdit: handleEdit,
207         onDetails: handleDetails,
208         onDelete: handleDelete,
209         onEmailSettings: handleEmailSettings,
210         onExport: handleExport,
211         onGroupDetails: handleGroupDetails,
212         onGroupEdit: handleGroupEdit,
213         onGroupDelete: handleGroupDelete,
214         onUpgrade: handleUpgrade,
215         onSignatureError: handleSignatureError,
216         onDecryptionError: handleDecryptionError,
217         onSelectEmails: handleSelectEmails,
218         onLimitReached: handleContactLimitReached,
219     };