diff --git a/src/components/File/File.tsx b/src/components/File/File.tsx
index b553024e..ab2e82c8 100644
--- a/src/components/File/File.tsx
+++ b/src/components/File/File.tsx
@@ -5,7 +5,7 @@ import {
StyledFileWrapper,
StyledIconWrapper,
} from './style';
-import { Button as MuiButton } from '@mui/material';
+import { Button as MuiButton, Tooltip } from '@mui/material';
import DeleteOutlineOutlinedIcon from '@mui/icons-material/DeleteOutlineOutlined';
import FileDownloadOutlinedIcon from '@mui/icons-material/FileDownloadOutlined';
import { Document } from '../../services/apiTypes';
@@ -27,67 +27,70 @@ export const File = ({ doc, file, handleFileRemoval, downloadButton }: FileProps
}
if (doc) {
const downloadLink = document.createElement('a');
- downloadLink.download = `${doc.name}`;
+ downloadLink.download = `${fileName}`;
downloadLink.href = `data:${doc.contentType};base64,${doc.bytes}`;
downloadLink.click();
}
};
const maxLength = 14;
+ const fileName = doc?.fileName ? doc.fileName : doc?.name;
return (
-
-
+
+ {doc?.fileName
+ ? doc.fileName.length > maxLength
+ ? `${doc.fileName.substring(0, maxLength)}...`
+ : doc.fileName
+ : doc?.name}
+
+
+
);
};
diff --git a/src/components/Upload/Upload.tsx b/src/components/Upload/Upload.tsx
index e73f7392..4b032839 100644
--- a/src/components/Upload/Upload.tsx
+++ b/src/components/Upload/Upload.tsx
@@ -21,6 +21,7 @@ import { useGetDocumentsByItemId } from '../../services/hooks/documents/useGetDo
import { useUploadDocumentToItem } from '../../services/hooks/documents/useUploadDocumentToItem';
import { COLORS } from '../../style/GlobalStyles';
import { File } from '../File/File';
+import { CustomDialog } from '../CustomDialog/CustomDialog';
type UploadProps = {
itemId: string;
@@ -35,7 +36,9 @@ export const ExampleUpload = ({ itemId }: UploadProps) => {
const [openDocumentTypeDialog, setOpenDocumentTypeDialog] = useState(false);
const [chosenDocumentType, setChosenDocumentType] = useState(null);
const [file, setFile] = useState(null);
-
+ const [isDeleteConfirmationOpen, setIsDeleteConfirmationOpen] = useState(false);
+ const [documentIdToDelete, setDocumentIdToDelete] = useState('');
+ const [documentNameToDelete, setDocumentNameToDelete] = useState('');
const handleFileUpload = () => {
setOpenDocumentTypeDialog(false);
if (file) {
@@ -49,16 +52,32 @@ export const ExampleUpload = ({ itemId }: UploadProps) => {
setChosenDocumentType(null);
};
- const handleFileDelete = (documentId: string) => {
- deleteDocument(documentId);
- };
-
const handleCancel = () => {
setOpenDocumentTypeDialog(false);
setFile(null);
setChosenDocumentType(null);
};
+ const handleClose = () => {
+ setIsDeleteConfirmationOpen(false);
+ setDocumentNameToDelete('');
+ };
+
+ const handleFileDeleteConfirmation = (documentId: string, documentName?: string) => {
+ setDocumentIdToDelete(documentId);
+ if (documentName) {
+ setDocumentNameToDelete(documentName);
+ }
+ setIsDeleteConfirmationOpen(true);
+ };
+
+ const handleFileToDelete = () => {
+ if (documentIdToDelete) {
+ deleteDocument(documentIdToDelete);
+ }
+ setIsDeleteConfirmationOpen(false);
+ };
+
return (
+
+ Are you sure you want to permanently delete "
+ {documentNameToDelete ? documentNameToDelete : 'No file name'}
+ "?
+
{
border: `1px dashed ${COLORS.black}`,
boxSizing: 'border-box',
minHeight: '200px',
+ overflowX: 'auto',
}}
>
{isLoading ? (
) : (
- documents?.map((document) => (
- handleFileDelete(document.id)}
- downloadButton={true}
- />
- ))
+ documents?.map((document) => {
+ return (
+
+ handleFileDeleteConfirmation(
+ document.id,
+ document?.fileName ? document.fileName : document.name
+ )
+ }
+ downloadButton={true}
+ />
+ );
+ })
)}
diff --git a/src/pages/addItem/hooks/itemValidator.ts b/src/pages/addItem/hooks/itemValidator.ts
index 54b62fc6..f0a0e497 100644
--- a/src/pages/addItem/hooks/itemValidator.ts
+++ b/src/pages/addItem/hooks/itemValidator.ts
@@ -14,7 +14,7 @@ const templateSchema = z.object({
productNumber: z.string().min(1, 'Product number is required'),
description: z.string().min(1, 'Description is required'),
createdById: z.string(),
- revision: z.string().min(1, 'Revision is required'),
+ revision: z.string().min(3, 'Revision is required, must be at least 3 characters'),
});
export const itemSchema = z.object({