1 import type { FC } from 'react';
2 import { useEffect } from 'react';
3 import type { RouteComponentProps } from 'react-router-dom';
4 import { useLocation } from 'react-router-dom';
6 import { Loader } from '@proton/components';
7 import { isProtonDocument } from '@proton/shared/lib/helpers/mimetype';
9 import useNavigate from '../hooks/drive/useNavigate';
10 import { useDocumentActions } from '../store/_documents';
11 import { useVolumeLinkView } from '../store/_views/useVolumeLinkView';
13 export const VolumeLinkContainer: FC<RouteComponentProps<{ volumeId: string; linkId: string }>> = ({ match }) => {
14 const { search } = useLocation();
15 const searchParams = new URLSearchParams(search);
16 const invitationId = searchParams.get('invitation');
17 const externalInvitationId = searchParams.get('externalInvitationID');
18 const { volumeId, linkId } = match.params;
19 const { handleRedirectOrAcceptInvitation, handleConvertExternalInvitation } = useVolumeLinkView();
20 const { navigateToSharedWithMe, navigateToSharedByMe, navigateToLink, navigateToNoAccess } = useNavigate();
21 const { openDocument } = useDocumentActions();
27 const abortController = new AbortController();
28 void handleRedirectOrAcceptInvitation(abortController.signal, {
34 if (linkInfo && isProtonDocument(linkInfo?.mimeType)) {
36 shareId: linkInfo.shareId,
37 linkId: linkInfo.linkId,
38 openBehavior: 'redirect',
40 } else if (linkInfo?.shareId) {
41 navigateToLink(linkInfo.shareId, linkInfo.linkId, linkInfo.isFile, '/shared-with-me');
47 navigateToSharedWithMe();
49 // No cleanup/abort function, allowing the action to continue in the background
50 }, [invitationId, volumeId, linkId]);
53 if (!externalInvitationId) {
56 const abortController = new AbortController();
57 void handleConvertExternalInvitation(abortController.signal, {
61 navigateToSharedByMe();
63 // No cleanup/abort function, allowing the action to continue in the background
64 }, [externalInvitationId]);
65 // This is a temporary solution until we have proper view to accept/decline screens
66 return <Loader size="medium" className="absolute inset-center" />;