Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / applications / drive / src / app / components / sections / SharedWithMe / SharedWithMeItemContextMenu.tsx
blob8eddd3358e84e1dd9530ad619ba0c3c95b753de4
1 import { ContextSeparator, useConfirmActionModal } from '@proton/components';
2 import { isPreviewAvailable } from '@proton/shared/lib/helpers/preview';
4 import { useSharedWithMeActions } from '../../../store';
5 import { useOpenInDocs } from '../../../store/_documents';
6 import type { ContextMenuProps } from '../../FileBrowser';
7 import { useDetailsModal } from '../../modals/DetailsModal';
8 import { useFilesDetailsModal } from '../../modals/FilesDetailsModal';
9 import { DetailsButton, DownloadButton, OpenInDocsButton, PreviewButton } from '../ContextMenu';
10 import { ItemContextMenu } from '../ContextMenu/ItemContextMenu';
11 import { AcceptButton } from './ContextMenuButtons/AcceptButton';
12 import { DeclineButton } from './ContextMenuButtons/DeclineButton';
13 import { OpenBookmarkButton } from './ContextMenuButtons/OpenBookmarkButton';
14 import { RemoveBookmarkButton } from './ContextMenuButtons/RemoveBookmarkButton';
15 import { RemoveMeButton } from './ContextMenuButtons/RemoveMeButton';
16 import type { SharedWithMeItem } from './SharedWithMe';
18 export function SharedWithMeContextMenu({
19     selectedBrowserItems,
20     anchorRef,
21     isOpen,
22     position,
23     open,
24     close,
25 }: ContextMenuProps & {
26     selectedBrowserItems: SharedWithMeItem[];
27 }) {
28     const selectedBrowserItem = selectedBrowserItems.at(0);
29     const isOnlyOneItem = selectedBrowserItems.length === 1 && !!selectedBrowserItem;
30     const isOnlyOneFileItem = isOnlyOneItem && selectedBrowserItem.isFile;
31     const hasPreviewAvailable =
32         isOnlyOneItem &&
33         selectedBrowserItem.isFile &&
34         selectedBrowserItem.mimeType &&
35         isPreviewAvailable(selectedBrowserItem.mimeType, selectedBrowserItem.size);
37     const [detailsModal, showDetailsModal] = useDetailsModal();
38     const [filesDetailsModal, showFilesDetailsModal] = useFilesDetailsModal();
39     const { showOpenInDocs } = useOpenInDocs(selectedBrowserItem);
40     const { removeMe } = useSharedWithMeActions();
41     const [confirmModal, showConfirmModal] = useConfirmActionModal();
43     return (
44         <>
45             <ItemContextMenu isOpen={isOpen} open={open} close={close} position={position} anchorRef={anchorRef}>
46                 {selectedBrowserItem && !selectedBrowserItem.isInvitation && !selectedBrowserItem.isBookmark && (
47                     <>
48                         {hasPreviewAvailable && (
49                             <PreviewButton
50                                 shareId={selectedBrowserItem.rootShareId}
51                                 linkId={selectedBrowserItem.linkId}
52                                 close={close}
53                             />
54                         )}
55                         {isOnlyOneFileItem && showOpenInDocs && (
56                             <OpenInDocsButton selectedBrowserItem={selectedBrowserItem} close={close} />
57                         )}
58                         <DownloadButton selectedBrowserItems={selectedBrowserItems} close={close} />
59                         <DetailsButton
60                             selectedBrowserItems={selectedBrowserItems}
61                             showDetailsModal={showDetailsModal}
62                             showFilesDetailsModal={showFilesDetailsModal}
63                             close={close}
64                         />
65                         {!!selectedBrowserItem && (
66                             <>
67                                 <ContextSeparator />
68                                 <RemoveMeButton
69                                     rootShareId={selectedBrowserItem.rootShareId}
70                                     removeMe={removeMe}
71                                     showConfirmModal={showConfirmModal}
72                                     close={close}
73                                 />
74                             </>
75                         )}
76                     </>
77                 )}
78                 {selectedBrowserItem?.isBookmark && selectedBrowserItem.bookmarkDetails && (
79                     <>
80                         <OpenBookmarkButton
81                             token={selectedBrowserItem.bookmarkDetails.token}
82                             urlPassword={selectedBrowserItem.bookmarkDetails.urlPassword}
83                             close={close}
84                         />
85                         <RemoveBookmarkButton
86                             token={selectedBrowserItem.bookmarkDetails.token}
87                             linkId={selectedBrowserItem.linkId}
88                             showConfirmModal={showConfirmModal}
89                             close={close}
90                         />
91                     </>
92                 )}
93                 {selectedBrowserItem?.invitationDetails && (
94                     <>
95                         <AcceptButton
96                             invitationId={selectedBrowserItem.invitationDetails.invitation.invitationId}
97                             close={close}
98                         />
99                         <DeclineButton
100                             invitationId={selectedBrowserItem.invitationDetails.invitation.invitationId}
101                             showConfirmModal={showConfirmModal}
102                             close={close}
103                         />
104                     </>
105                 )}
106             </ItemContextMenu>
107             {detailsModal}
108             {filesDetailsModal}
109             {confirmModal}
110         </>
111     );