1 import { c, msgid } from 'ttag';
3 import { useUser } from '@proton/account/user/hooks';
4 import { Button } from '@proton/atoms';
5 import Icon from '@proton/components/components/icon/Icon';
6 import type { ModalProps } from '@proton/components/components/modalTwo/Modal';
7 import ModalTwo from '@proton/components/components/modalTwo/Modal';
8 import Tooltip from '@proton/components/components/tooltip/Tooltip';
9 import { useContactGroups } from '@proton/mail';
10 import { useContactEmails } from '@proton/mail/contactEmails/hooks';
11 import type { Recipient } from '@proton/shared/lib/interfaces';
12 import noop from '@proton/utils/noop';
14 import ModalContent from '../../../components/modalTwo/ModalContent';
15 import ModalFooter from '../../../components/modalTwo/ModalFooter';
16 import ModalHeader from '../../../components/modalTwo/ModalHeader';
17 import type { ContactExportingProps } from '../modals/ContactExportingModal';
18 import RecipientDropdownItem from '../view/RecipientDropdownItem';
19 import type { ContactGroupDeleteProps } from './ContactGroupDeleteModal';
20 import type { ContactGroupEditProps } from './ContactGroupEditModal';
22 import './ContactGroupDetailsModal.scss';
24 export interface ContactGroupDetailsProps {
25 contactGroupID: string;
26 onEdit: (props: ContactGroupEditProps) => void;
27 onDelete: (props: ContactGroupDeleteProps) => void;
28 onExport: (props: ContactExportingProps) => void;
29 onUpgrade: () => void;
30 onCompose?: (recipients: Recipient[], attachments: File[]) => void;
31 onCloseContactDetailsModal?: () => void;
34 type Props = ContactGroupDetailsProps & ModalProps;
36 const ContactGroupDetailsModal = ({
43 onCloseContactDetailsModal,
46 const [user] = useUser();
47 const [contactGroups = [], loadingGroups] = useContactGroups();
48 const [contactEmails = [], loadingEmails] = useContactEmails();
49 const loading = loadingGroups || loadingEmails;
50 const group = contactGroups.find(({ ID }) => ID === contactGroupID);
51 const emails = contactEmails.filter(({ LabelIDs = [] }: { LabelIDs: string[] }) =>
52 LabelIDs.includes(contactGroupID)
54 const emailsCount = emails.length;
56 const handleEdit = () => {
57 if (!user.hasPaidMail) {
61 onEdit({ contactGroupID });
65 const handleDelete = () => {
66 onDelete({ groupIDs: [contactGroupID] });
70 const handleExportContactGroup = () => {
71 onExport({ contactGroupID });
74 const handleCompose = () => {
76 const recipients = emails.map((email) => ({ Name: email.Name, Address: email.Email }));
77 onCompose([...recipients], []);
79 onCloseContactDetailsModal?.();
83 const handleComposeSingle = (recipient: Recipient) => {
85 onCompose([recipient], []);
87 onCloseContactDetailsModal?.();
91 const getComposeAction = (recipient: Recipient) => {
94 <div className="mr-2">
95 <Tooltip title={c('Action').t`Compose`}>
96 <Button color="weak" shape="ghost" icon onClick={() => handleComposeSingle(recipient)}>
97 <Icon name="pen-square" alt={c('Action').t`Compose`} />
106 <ModalTwo size="large" className="contacts-modal" {...rest}>
109 <div className="flex flex-nowrap items-center gap-2">
111 style={{ backgroundColor: group?.Color ?? '', '--w-custom': '2.125rem' }}
112 className="rounded w-custom text-center shrink-0"
114 <Icon color="white" name="users" />
116 <span className="text-ellipsis" title={group?.Name}>
122 <Tooltip title={c('Action').t`Edit`}>
129 className="inline-flex ml-2"
130 data-testid="group-summary:edit"
132 <Icon name="pen" alt={c('Action').t`Edit`} />
135 <Tooltip title={c('Action').t`Export contact group`}>
140 onClick={handleExportContactGroup}
142 className="inline-flex ml-2"
143 data-testid="group-summary:export"
145 <Icon name="arrow-up-from-square" alt={c('Action').t`Export contact group`} />
148 <Tooltip title={c('Action').t`Delete`}>
153 onClick={handleDelete}
155 className="inline-flex ml-2"
156 data-testid="group-summary:delete"
158 <Icon name="trash" alt={c('Action').t`Delete`} />
164 <h4 className="mb-4 color-weak text-lg">
165 {c('Title').ngettext(
166 msgid`${emailsCount} email address`,
167 `${emailsCount} email addresses`,
171 {emails.map((email) => {
172 const recipient: Recipient = { Name: email.Name, Address: email.Email };
174 <RecipientDropdownItem
175 label={recipient.Name}
176 recipient={recipient}
177 displaySenderImage={false}
179 additionalAction={getComposeAction(recipient)}
187 <Button onClick={rest.onClose}>{c('Action').t`Close`}</Button>
191 onClick={handleCompose}
193 className="inline-flex justify-center"
195 <Icon name="pen-square" className="self-center mr-2" alt={c('Action').t`New message`} />
196 {c('Action').t`New message`}
204 export default ContactGroupDetailsModal;