1 import { type FC, useEffect, useState } from 'react';
2 import { useSelector } from 'react-redux';
4 import { c } from 'ttag';
6 import { type ModalProps, ModalTwoHeader } from '@proton/components';
7 import { presentListItem } from '@proton/pass/components/Item/List/utils';
8 import { SafeItemIcon } from '@proton/pass/components/Layout/Icon/ItemIcon';
9 import { PassModal } from '@proton/pass/components/Layout/Modal/PassModal';
10 import { selectItem } from '@proton/pass/store/selectors';
11 import type { MaybeNull, SecureLink } from '@proton/pass/types';
13 import { SecureLinkDetails } from './SecureLinkDetails';
14 import { SecureLinkGenerate } from './SecureLinkGenerate';
16 type SecureLinkModalProps = ModalProps & {
19 itemSecureLink?: MaybeNull<SecureLink>;
22 export const SecureLinkModal: FC<SecureLinkModalProps> = ({ itemId, shareId, itemSecureLink = null, ...props }) => {
23 const [secureLink, setSecureLink] = useState<MaybeNull<SecureLink>>(null);
24 const item = useSelector(selectItem(shareId, itemId));
27 if (itemSecureLink) setSecureLink(itemSecureLink);
28 else setTimeout(() => setSecureLink(itemSecureLink), 100); // Wait for the modal animation to finish
33 const { heading, subheading } = presentListItem(item);
36 <PassModal size="small" open enableCloseWhenClickOutside {...props} key={secureLink ? 'details' : 'create'}>
38 title={c('Action').t`Share secure link`}
40 <div className="flex flex-nowrap items-center gap-2 mt-1 mb-4">
41 <SafeItemIcon item={item} size={2.5} pill={false} />
42 <span className="text-ellipsis">
44 {subheading && ` ยท ${subheading}`}
51 <SecureLinkDetails {...secureLink} />
53 <SecureLinkGenerate itemId={itemId} shareId={shareId} onLinkGenerated={setSecureLink} />