@@ -45,7 +45,6 @@ const Page = () => {
45
45
( file ) =>
46
46
file . size > maxFileSize || ! allowedFileTypes . includes ( file . type ) ,
47
47
) ;
48
-
49
48
if ( invalidFiles . length > 0 ) {
50
49
toast . error (
51
50
`Some files are invalid. Ensure each file is below 5MB and of an allowed type (PDF, JPEG, PNG, GIF).` ,
@@ -56,15 +55,17 @@ const Page = () => {
56
55
return ;
57
56
}
58
57
59
- const isPdf =
60
- acceptedFiles . length === 1 &&
61
- acceptedFiles [ 0 ] ?. type === "application/pdf" ;
58
+ const isPdf = acceptedFiles . reduce (
59
+ ( reducer , file ) => file . type === "application/pdf" || reducer ,
60
+ false ,
61
+ ) ;
62
62
if ( isPdf && acceptedFiles . length > 1 ) {
63
63
toast . error ( "PDFs must be uploaded separately" , {
64
64
id : toastId ,
65
65
} ) ;
66
66
return ;
67
67
}
68
+
68
69
const orderedFiles = acceptedFiles . sort ( ( a , b ) => {
69
70
return a . lastModified - b . lastModified ;
70
71
} ) ;
@@ -85,7 +86,7 @@ const Page = () => {
85
86
files . forEach ( ( file ) => {
86
87
formData . append ( "files" , file ) ;
87
88
} ) ;
88
-
89
+
89
90
// formData.append("exam", exam);
90
91
formData . append ( "campus" , campus ) ;
91
92
@@ -97,14 +98,12 @@ const Page = () => {
97
98
await toast . promise (
98
99
async ( ) => {
99
100
try {
100
- await axios . post < APIResponse > (
101
- "/api/ai-upload" ,
102
- formData ,
103
- ) ;
101
+ await axios . post < APIResponse > ( "/api/ai-upload" , formData ) ;
104
102
} catch ( error ) {
105
- if ( error instanceof AxiosError && error . response ?. data ) {
103
+ if ( error instanceof AxiosError && error . response ?. data ) {
106
104
const errorData = error . response . data as APIResponse ;
107
- const errorMessage = errorData . message || "Failed to upload papers" ;
105
+ const errorMessage =
106
+ errorData . message || "Failed to upload papers" ;
108
107
throw new Error ( errorMessage ) ;
109
108
}
110
109
throw new Error ( "Failed to upload papers" ) ;
@@ -167,7 +166,7 @@ const Page = () => {
167
166
) }
168
167
</ Dropzone >
169
168
< label className = "mx-2 -mr-2 block text-center text-xs font-medium text-gray-700" >
170
- Only Images and PDFs are allowed
169
+ Only Images and PDF are allowed
171
170
< sup className = "text-red-500" > *</ sup >
172
171
</ label >
173
172
</ div >
0 commit comments