From 1fd2e27df7c9ded56fc031e2a92cfa33a24098a5 Mon Sep 17 00:00:00 2001 From: Stixx Date: Tue, 7 Jan 2025 21:26:53 +0100 Subject: [PATCH] feat: handling of opening a SIGIT without retrievable files --- src/components/PDFView/PdfMarking.tsx | 45 ++++++++++++++++++----- src/components/PDFView/index.tsx | 4 ++ src/components/UsersDetails.tsx/index.tsx | 11 +++--- src/pages/sign/index.tsx | 9 +++++ src/pages/verify/index.tsx | 20 +++++++++- 5 files changed, 74 insertions(+), 15 deletions(-) diff --git a/src/components/PDFView/PdfMarking.tsx b/src/components/PDFView/PdfMarking.tsx index cbd3907..71dfdd9 100644 --- a/src/components/PDFView/PdfMarking.tsx +++ b/src/components/PDFView/PdfMarking.tsx @@ -20,10 +20,13 @@ import { faFileDownload, faPen } from '@fortawesome/free-solid-svg-icons' +import { Typography } from '@mui/material' +import styles from '../UsersDetails.tsx/style.module.scss' interface PdfMarkingProps { currentUserMarks: CurrentUserMark[] files: CurrentUserFile[] + noFiles?: boolean handleExport: () => void handleEncryptedExport: () => void handleSign: () => void @@ -42,6 +45,7 @@ interface PdfMarkingProps { const PdfMarking = (props: PdfMarkingProps) => { const { files, + noFiles, currentUserMarks, setCurrentUserMarks, setUpdatedMarks, @@ -131,6 +135,18 @@ const PdfMarking = (props: PdfMarkingProps) => { setSelectedMarkValue(value) } + const renderRightColumn = () => { + if (meta !== null) return + + return ( +
+
+ No meta found +
+
+ ) + } + return ( <> @@ -148,7 +164,7 @@ const PdfMarking = (props: PdfMarkingProps) => { )} } - right={meta !== null && } + right={renderRightColumn()} leftIcon={faFileDownload} centerIcon={faPen} rightIcon={faCircleInfo} @@ -156,21 +172,32 @@ const PdfMarking = (props: PdfMarkingProps) => { + {noFiles ? ( + + We were not able to retrieve the files. + + ) : ( + '' + )} - + + {!noFiles && ( + + )} ) diff --git a/src/components/PDFView/index.tsx b/src/components/PDFView/index.tsx index 95d577e..8fcaaeb 100644 --- a/src/components/PDFView/index.tsx +++ b/src/components/PDFView/index.tsx @@ -10,6 +10,7 @@ interface PdfViewProps { currentFile: CurrentUserFile | null currentUserMarks: CurrentUserMark[] files: CurrentUserFile[] + noFiles?: boolean handleMarkClick: (id: number) => void otherUserMarks: Mark[] selectedMark: CurrentUserMark | null @@ -21,6 +22,7 @@ interface PdfViewProps { */ const PdfView = ({ files, + noFiles, currentUserMarks, handleMarkClick, selectedMarkValue, @@ -76,6 +78,8 @@ const PdfView = ({ , curr ]) + ) : noFiles ? ( + '' ) : ( )} diff --git a/src/components/UsersDetails.tsx/index.tsx b/src/components/UsersDetails.tsx/index.tsx index 9b08b94..ebdbb6c 100644 --- a/src/components/UsersDetails.tsx/index.tsx +++ b/src/components/UsersDetails.tsx/index.tsx @@ -292,11 +292,12 @@ export const UsersDetails = ({ meta }: UsersDetailsProps) => {

File Servers

- {zipUrls.map((url) => ( - - {getBaseUrl(url)} - - ))} + {zipUrls && + zipUrls.map((url) => ( + + {getBaseUrl(url)} + + ))}
) : undefined diff --git a/src/pages/sign/index.tsx b/src/pages/sign/index.tsx index f9427cd..79297f9 100644 --- a/src/pages/sign/index.tsx +++ b/src/pages/sign/index.tsx @@ -89,6 +89,7 @@ export const SignPage = () => { } const [files, setFiles] = useState<{ [filename: string]: SigitFile }>({}) + const [noFiles, setNoFiles] = useState(false) const [isLoading, setIsLoading] = useState(true) const [loadingSpinnerDesc, setLoadingSpinnerDesc] = useState('') @@ -290,6 +291,13 @@ export const SignPage = () => { const { zipUrls, encryptionKey } = res + if (!zipUrls || zipUrls.length === 0) { + toast.warning('No zip files found in the zipUrls') + setIsLoading(false) + setNoFiles(true) + return + } + for (let i = 0; i < zipUrls.length; i++) { const zipUrl = zipUrls[i] const isLastZipUrl = i === zipUrls.length - 1 @@ -875,6 +883,7 @@ export const SignPage = () => { handleEncryptedExport={handleEncryptedExport} otherUserMarks={otherUserMarks} meta={meta} + noFiles={noFiles} /> ) } diff --git a/src/pages/verify/index.tsx b/src/pages/verify/index.tsx index 0da3171..8080315 100644 --- a/src/pages/verify/index.tsx +++ b/src/pages/verify/index.tsx @@ -65,6 +65,7 @@ import { MarkRender } from '../../components/MarkTypeStrategy/MarkRender.tsx' interface PdfViewProps { files: CurrentUserFile[] + noFiles?: boolean currentFile: CurrentUserFile | null parsedSignatureEvents: { [signer: `npub1${string}`]: DocSignatureEvent @@ -73,6 +74,7 @@ interface PdfViewProps { const SlimPdfView = ({ files, + noFiles, currentFile, parsedSignatureEvents }: PdfViewProps) => { @@ -162,6 +164,8 @@ const SlimPdfView = ({ ) }) + ) : noFiles ? ( + '' ) : ( )} @@ -404,9 +408,15 @@ export const VerifyPage = () => { setIsLoading(true) // We have multiple zipUrls, we should fetch one by one and take the first one which successfully decrypts - // If file is altered decrytption will fail + // If a file is altered decrytption will fail setLoadingSpinnerDesc('Fetching file from file server') + if (!zipUrls || zipUrls.length === 0) { + toast.warning('No zip files found in the zipUrls') + setIsLoading(false) + return + } + for (let i = 0; i < zipUrls.length; i++) { const zipUrl = zipUrls[i] const isLastZipUrl = i === zipUrls.length - 1 @@ -789,7 +799,15 @@ export const VerifyPage = () => { currentFile={currentFile} files={getCurrentUserFiles(files, currentFileHashes, fileHashes)} parsedSignatureEvents={parsedSignatureEvents} + noFiles={!zipUrls || zipUrls.length === 0} /> + {!zipUrls || zipUrls.length === 0 ? ( + + We were not able to retrieve the files. + + ) : ( + '' + )} )}