1 import type { MouseEvent, ReactNode } from 'react';
3 import { c } from 'ttag';
5 import Copy from '@proton/components/components/button/Copy';
6 import ProtonBadgeType from '@proton/components/components/protonBadge/ProtonBadgeType';
7 import ContactImage from '@proton/components/containers/contacts/ContactImage';
8 import useNotifications from '@proton/components/hooks/useNotifications';
9 import { getInitials } from '@proton/shared/lib/helpers/string';
10 import type { Recipient } from '@proton/shared/lib/interfaces';
15 bimiSelector?: string;
16 closeDropdown: () => void;
17 displaySenderImage: boolean;
19 additionalAction?: ReactNode;
22 const RecipientDropdownItem = ({
31 const { createNotification } = useNotifications();
33 // Label value can contain :
34 // - Contact Name if the recipient is a contact, or Recipient Name or Recipient Address on PM
35 // - Recipient Name or Recipient Address on EO
36 // Recipient might not have a Name or a Contact Name, and by default we put the Address
37 // In this case, we don't want to display the Address field twice
38 const hasName = label !== '' && label !== recipient.Address;
40 const handleCopyEmail = () => {
43 text: c('Success').t`Email address copied to clipboard`,
49 // Prevent closing dropdown if click inside the recipient info
50 const handleClick = (e: MouseEvent) => {
55 <div className="flex flex-nowrap items-center p-2" onClick={handleClick}>
56 <span className="item-icon flex shrink-0 rounded mx-2" aria-hidden="true">
57 <span className="m-auto">
59 <>{getInitials(label)}</>
62 email={recipient.Address}
65 bimiSelector={bimiSelector}
66 displaySenderImage={displaySenderImage}
71 <div className="flex flex-column flex-1 px-2" data-testid="recipient:dropdown-item--contact-name">
72 <span className="text-ellipsis inline-block max-w-full user-select" title={label}>
74 {!simple && recipient && <ProtonBadgeType recipient={recipient} />}
77 <span className="color-weak text-ellipsis inline-block max-w-full user-select">{`<${recipient.Address}>`}</span>
82 value={recipient.Address}
83 className="mr-2 shrink-0"
84 onCopy={handleCopyEmail}
85 tooltipText={c('Action').t`Copy email to clipboard`}
87 data-testid="recipient:dropdown-item--copy-address-button"
93 export default RecipientDropdownItem;