Skip to content

Commit a953b33

Browse files
bugfix: show pdf must be uploaded seperately toast
1 parent ad3f462 commit a953b33

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/app/upload/page.tsx

+11-12
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ const Page = () => {
4545
(file) =>
4646
file.size > maxFileSize || !allowedFileTypes.includes(file.type),
4747
);
48-
4948
if (invalidFiles.length > 0) {
5049
toast.error(
5150
`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 = () => {
5655
return;
5756
}
5857

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+
);
6262
if (isPdf && acceptedFiles.length > 1) {
6363
toast.error("PDFs must be uploaded separately", {
6464
id: toastId,
6565
});
6666
return;
6767
}
68+
6869
const orderedFiles = acceptedFiles.sort((a, b) => {
6970
return a.lastModified - b.lastModified;
7071
});
@@ -85,7 +86,7 @@ const Page = () => {
8586
files.forEach((file) => {
8687
formData.append("files", file);
8788
});
88-
89+
8990
// formData.append("exam", exam);
9091
formData.append("campus", campus);
9192

@@ -97,14 +98,12 @@ const Page = () => {
9798
await toast.promise(
9899
async () => {
99100
try {
100-
await axios.post<APIResponse>(
101-
"/api/ai-upload",
102-
formData,
103-
);
101+
await axios.post<APIResponse>("/api/ai-upload", formData);
104102
} catch (error) {
105-
if (error instanceof AxiosError && error.response?.data ) {
103+
if (error instanceof AxiosError && error.response?.data) {
106104
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";
108107
throw new Error(errorMessage);
109108
}
110109
throw new Error("Failed to upload papers");
@@ -167,7 +166,7 @@ const Page = () => {
167166
)}
168167
</Dropzone>
169168
<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
171170
<sup className="text-red-500">*</sup>
172171
</label>
173172
</div>

0 commit comments

Comments
 (0)