1 import { useState } from 'react';
3 import { c } from 'ttag';
5 import type { ModalStateProps } from '@proton/components';
6 import { ModalTwo, useModalTwoStatic } from '@proton/components';
7 import { useLoading } from '@proton/hooks';
9 import type { DecryptedLink } from '../../../store';
10 import { useDriveSharingFlags, useTreeForModals } from '../../../store';
11 import ModalContentLoader from '../ModalContentLoader';
12 import type { useLinkSharingModal } from '../ShareLinkModal/ShareLinkModal';
13 import { ModalContent } from './ModalContent';
17 showLinkSharingModal: ReturnType<typeof useLinkSharingModal>[1];
21 const SelectedFileToShareModal = ({
26 }: Props & ModalStateProps) => {
27 const { rootItems, toggleExpand, isLoaded: isTreeLoaded } = useTreeForModals(shareId, { rootExpanded: true });
28 const { isSharingInviteAvailable } = useDriveSharingFlags();
30 const [loading, withLoading] = useLoading();
31 const [selectedFile, setSelectedFile] = useState<DecryptedLink>();
33 const onSelect = async (link: DecryptedLink) => {
35 setSelectedFile(link);
39 const handleSubmit = async () => {
41 void showLinkSharingModal({ shareId, linkId: selectedFile.linkId });
46 const isSharingDisabled = !selectedFile || !selectedFile.parentLinkId;
48 const actionTextLEGACY = selectedFile?.shareUrl ? c('Action').t`Manage link` : c('Action').t`Create link`;
49 const actionText = c('Action').t`Share`;
54 onSubmit={(e: any) => {
56 withLoading(handleSubmit()).catch(console.error);
65 isTreeLoaded={isTreeLoaded}
67 selectedLinkId={selectedFile?.linkId}
68 isSharingDisabled={isSharingDisabled}
69 actionText={isSharingInviteAvailable ? actionText : actionTextLEGACY}
70 toggleExpand={toggleExpand}
74 <ModalContentLoader>{c('Info').t`Loading`}</ModalContentLoader>
80 export default SelectedFileToShareModal;
81 export const useFileSharingModal = () => {
82 return useModalTwoStatic(SelectedFileToShareModal);