Fixes: Upload document issues, Adds: proper error messages
This commit is contained in:
parent
a2a3f7d893
commit
d552b395e0
1 changed files with 28 additions and 19 deletions
|
|
@ -46,21 +46,36 @@ const SupportingDoc = ({ files, onFilesChange }: SupportingDocProps) => {
|
|||
setIsDragging(false)
|
||||
|
||||
const droppedFiles = Array.from(e.dataTransfer.files);
|
||||
|
||||
const hasPdf = files.some(file => file.type === 'application/pdf');
|
||||
|
||||
const validTypes = [
|
||||
'application/pdf',
|
||||
'text/plain',
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
];
|
||||
|
||||
const invalidFiles = droppedFiles.filter(file => !validTypes.includes(file.type));
|
||||
if (invalidFiles.length > 0) {
|
||||
toast({
|
||||
title: 'Invalid file type',
|
||||
description: 'Please upload only PDF, TXT, PPTX, or DOCX files',
|
||||
variant: 'destructive',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasPdf && droppedFiles.some(file => file.type === 'application/pdf')) {
|
||||
toast({
|
||||
title: 'Multiple PDF files are not allowed',
|
||||
description: 'Please select only one PDF file',
|
||||
variant: 'destructive',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const validFiles = droppedFiles.filter(file => {
|
||||
const validTypes = [
|
||||
'application/pdf',
|
||||
// 'image/webp',
|
||||
// 'image/png',
|
||||
// 'image/x-raw',
|
||||
// 'image/jpeg',
|
||||
'text/plain',
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
];
|
||||
return validTypes.includes(file.type) && !(hasPdf && file.type === 'application/pdf');
|
||||
return !(hasPdf && file.type === 'application/pdf');
|
||||
});
|
||||
|
||||
if (validFiles.length > 0) {
|
||||
|
|
@ -71,12 +86,6 @@ const SupportingDoc = ({ files, onFilesChange }: SupportingDocProps) => {
|
|||
title: 'Files selected',
|
||||
description: `${validFiles.length} file(s) have been added`,
|
||||
})
|
||||
} else {
|
||||
toast({
|
||||
title: 'Multiple PDF files are not allowed',
|
||||
description: 'Please select only one PDF file',
|
||||
variant: 'destructive',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +154,7 @@ const SupportingDoc = ({ files, onFilesChange }: SupportingDocProps) => {
|
|||
|
||||
<input
|
||||
type="file"
|
||||
accept=".pdf,.webp,.png,.raw,.jpeg,.txt,.pptx,.docx"
|
||||
accept=".pdf,.txt,.pptx,.docx"
|
||||
onChange={handleFileInput}
|
||||
className="hidden"
|
||||
id="file-upload"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue