1 import { useMemo } from 'react';
3 import { c } from 'ttag';
5 import { useAddresses } from '@proton/account/addresses/hooks';
6 import { Button } from '@proton/atoms';
7 import Loader from '@proton/components/components/loader/Loader';
8 import ModalTwoContent from '@proton/components/components/modalTwo/ModalContent';
9 import ModalTwoFooter from '@proton/components/components/modalTwo/ModalFooter';
10 import ModalTwoHeader from '@proton/components/components/modalTwo/ModalHeader';
11 import { useContactGroups } from '@proton/mail';
12 import { toMap } from '@proton/shared/lib/helpers/object';
13 import type { ContactEmail } from '@proton/shared/lib/interfaces/contacts';
14 import type { VCardContact } from '@proton/shared/lib/interfaces/contacts/VCard';
15 import noop from '@proton/utils/noop';
17 import useContactList from '../hooks/useContactList';
18 import ContactView from '../view/ContactView';
21 contact?: VCardContact;
23 beMergedIDs: string[];
28 const ContactMergeViewContent = ({ contact, loading: loadingContact, beMergedIDs, onSubmit, onClose }: Props) => {
29 const [addresses = [], loadingAddresses] = useAddresses();
30 const ownAddresses = useMemo(() => addresses.map(({ Email }) => Email), [addresses]);
32 const { loading: loadingContacts, contactEmailsMap } = useContactList({});
33 const contactEmails = beMergedIDs.flatMap((contactID) => contactEmailsMap[contactID] as ContactEmail[]);
35 const [contactGroups = [], loadingContactGroups] = useContactGroups();
36 const contactGroupsMap = useMemo(() => toMap(contactGroups), [contactGroups]);
38 const loading = loadingContact || loadingAddresses || loadingContacts || loadingContactGroups;
42 <ModalTwoHeader title={c('Title').t`Contact Details`} />
48 vCardContact={contact as VCardContact}
50 contactEmails={contactEmails}
51 contactGroupsMap={contactGroupsMap}
52 ownAddresses={ownAddresses}
55 onEmailSettings={noop}
59 onSignatureError={noop}
60 onDecryptionError={noop}
66 <Button onClick={onClose}>{c('Action').t`Close`}</Button>
67 <Button color="norm" disabled={!contact} onClick={onSubmit}>
68 {c('Action').t`Merge`}
75 export default ContactMergeViewContent;