1 import { useMemo } from 'react';
3 import { c } from 'ttag';
5 import { useAddresses } from '@proton/account/addresses/hooks';
6 import { useUserKeys } from '@proton/account/userKeys/hooks';
7 import { Button } from '@proton/atoms';
8 import Loader from '@proton/components/components/loader/Loader';
9 import type { ModalProps } from '@proton/components/components/modalTwo/Modal';
10 import ModalTwo from '@proton/components/components/modalTwo/Modal';
11 import ModalTwoContent from '@proton/components/components/modalTwo/ModalContent';
12 import ModalTwoFooter from '@proton/components/components/modalTwo/ModalFooter';
13 import ModalTwoHeader from '@proton/components/components/modalTwo/ModalHeader';
14 import useContactList from '@proton/components/containers/contacts/hooks/useContactList';
15 import { useContactGroups } from '@proton/mail';
16 import { useContact } from '@proton/mail/contacts/contactHooks';
17 import { toMap } from '@proton/shared/lib/helpers/object';
18 import type { ContactEmail } from '@proton/shared/lib/interfaces/contacts';
19 import noop from '@proton/utils/noop';
21 import useVCardContact from '../hooks/useVCardContact';
22 import ContactView from '../view/ContactView';
24 export interface ContactMergeDetailsModalProps {
28 type Props = ContactMergeDetailsModalProps & ModalProps;
30 const ContactMergeDetailsModal = ({ contactID, ...rest }: Props) => {
31 const [userKeysList] = useUserKeys();
32 const [contact] = useContact(contactID);
33 const { vCardContact, isLoading, errors } = useVCardContact({ contact, userKeysList });
34 const { loading: loadingContactEmails, contactEmailsMap } = useContactList({});
36 const [addresses = [], loadingAddresses] = useAddresses();
37 const ownAddresses = useMemo(() => addresses.map(({ Email }) => Email), [addresses]);
39 const [contactGroups = [], loadingContactGroups] = useContactGroups();
40 const contactGroupsMap = useMemo(() => toMap(contactGroups), [contactGroups]);
42 if (!isLoading && !vCardContact && vCardContact === undefined) {
47 <ModalTwo size="large" className="contacts-modal" {...rest}>
48 <ModalTwoHeader title={c('Title').t`Contact Details`} />
50 {isLoading || loadingContactEmails || loadingAddresses || loadingContactGroups ? (
54 vCardContact={vCardContact!}
58 contactEmails={contactEmailsMap[contactID] as ContactEmail[]}
59 contactGroupsMap={contactGroupsMap}
60 ownAddresses={ownAddresses}
63 onEmailSettings={noop}
67 onSignatureError={noop}
68 onDecryptionError={noop}
73 <Button color="norm" className="ml-auto" onClick={rest.onClose}>{c('Action').t`Close`}</Button>
79 export default ContactMergeDetailsModal;