Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add notification for inaccessible documents #698

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/components/Documents/DocumentTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Box from '@mui/material/Box';
import { useMediaQuery } from '@mui/material';
// Context Imports
import { DocumentListContext } from '@contexts';
import { useSession } from '@hooks';
import { useNotification, useSession } from '@hooks';
// Utility Imports
import { getBlobFromSolid } from '@utils';
// Theme Imports
Expand All @@ -35,6 +35,7 @@ import DocumentsDesktop from './DocumentsDesktop';
const DocumentTable = ({ handleAclPermissionsModal, handleSelectDeleteDoc }) => {
const { session } = useSession();
const { documentListObject, loadingDocuments } = useContext(DocumentListContext);
const { addNotification } = useNotification();

const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
const isSmallScreenHeight = useMediaQuery('(max-height: 600px)');
Expand All @@ -59,10 +60,21 @@ const DocumentTable = ({ handleAclPermissionsModal, handleSelectDeleteDoc }) =>
* @returns {Promise<Blob>} A promise that resolves with the Blob of the document.
* @throws {Error} Throws an error if there is an issue fetching the document blob.
*/
const urlFileBlob = await getBlobFromSolid(session, urlToOpen);
try {
const urlFileBlob = await getBlobFromSolid(session, urlToOpen);

// Open a new window to display the document using the blob URL
window.open(urlFileBlob);
// Open a new window to display the document using the blob URL
window.open(urlFileBlob);
} catch (e) {
if (e?.statusCode === 403) {
addNotification('error', 'You do not have permission to view this document');
} else {
addNotification(
'error',
`Document preview failed. Reason: ${e?.message || 'Unknown error'}`
);
}
}
};

// Maps raw document types to user-friendly display names using `DOC_TYPES`
Expand Down
Loading