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';
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({});
86 const handleSelectImage = (props: ContactImageProps) => {
87 handleShowContactImageModal(props);
90 const handleResign = () => {
91 handleShowContactResignExecutionModal({});
94 const handleSignatureError = (contactID: string) => {
95 handleShowContactSignatureErrorModal({ contactID, onResign: handleResign });
98 const handleClearData = (props: ContactClearDataExecutionProps) => {
99 handleShowContactClearDataExecutionModal(props);
102 const handleClearDataConfirm = (props: ContactClearDataConfirmProps) => {
103 handleShowContactClearDataConfirmModal({ ...props, onClearData: handleClearData });
106 const handleDecryptionError = (contactID: string) => {
107 handleShowContactDecryptionErrorModal({ contactID, onClearDataConfirm: handleClearDataConfirm });
110 const handleGroupEdit = (props: ContactGroupEditProps) => {
111 handleShowContactGroupEditModal(props);
114 const handleContactLimitReached = (props: ContactGroupLimitReachedProps) => {
115 return handleShowContactGroupLimitReachedModal(props);
118 const handleEdit = (props: ContactEditProps) => {
119 handleShowContactEditModal({
122 onUpgrade: handleUpgrade,
123 onSelectImage: handleSelectImage,
124 onGroupEdit: handleGroupEdit,
125 onLimitReached: handleContactLimitReached,
129 const handleDelete = (props: ContactDeleteProps) => {
130 handleShowContactDeleteModal({
132 onDelete: (...args) => {
134 props.onDelete?.(...args);
139 const handleEmailSettings = (props: ContactEmailSettingsProps) => {
140 handleShowContactEmailSettingsModal(props);
143 const handleExport = (props: ContactExportingProps = {}) => {
144 handleShowContactExportingModal(props);
147 const handleGroupDelete = (props: ContactGroupDeleteProps) => {
148 handleShowContactGroupDeleteModal(props);
151 const handleGroupDetails = (contactGroupID: string, onCloseContactDetailsModal?: () => void) => {
152 handleShowContactGroupDetailsModal({
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
163 const handleDetails = (contactID: string) => {
164 handleShowContactDetailsModal({
168 onDelete: handleDelete,
169 onEmailSettings: handleEmailSettings,
170 onGroupDetails: handleGroupDetails,
171 onGroupEdit: handleGroupEdit,
172 onUpgrade: handleUpgrade,
173 onSignatureError: handleSignatureError,
174 onDecryptionError: handleDecryptionError,
178 const handleSelectEmails = (props: SelectEmailsProps) => {
179 return handleShowContactSelectEmailsModal(props);
184 {contactDetailsModal}
187 {contactEmailSettingsModal}
188 {contactExportingModal}
189 {contactGroupDetailsModal}
190 {contactGroupEditModal}
191 {contactGroupDeleteModal}
192 {contactUpgradeModal}
194 {contactSignatureErrorModal}
195 {contactResignExecutionModal}
196 {contactDecryptionErrorModal}
197 {contactClearDataConfirmModal}
198 {contactClearDataExecutionModal}
199 {contactSelectEmailsModal}
200 {contactGroupLimitReachedModal}
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,