Skip to content

Commit ab26737

Browse files
fix:validation
1 parent c0ae2d7 commit ab26737

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/app/upload/page.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,26 @@ const Page = () => {
4646
];
4747
const files = fileInputRef.current?.files as FileList | null;
4848

49-
if (!slot || !subject || !exam || !year || !files || files.length === 0) {
50-
toast.error("All fields are required.");
49+
if (!slot) {
50+
toast.error("Slot is required");
5151
return;
5252
}
53-
54-
if (files.length > 5) {
53+
if (!subject) {
54+
toast.error("Subject is required");
55+
return;
56+
}
57+
if (!exam) {
58+
toast.error("Exam is required");
59+
return;
60+
}
61+
if (!year) {
62+
toast.error("Year is required");
63+
return;
64+
}
65+
if (!files || files.length === 0) {
66+
toast.error("No files selected");
67+
return;
68+
} else if (files.length > 5) {
5569
toast.error("More than 5 files selected");
5670
return;
5771
}
@@ -99,7 +113,7 @@ const Page = () => {
99113
void toast.promise(
100114
(async () => {
101115
try {
102-
await axios.post("/api/upload", formData);
116+
const response = await axios.post("/api/upload", formData);
103117

104118
setSlot("");
105119
setSubject("");

src/components/searchbarSubjectList.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"use client";
12
import { useState, useCallback, useRef, useEffect } from "react";
23
import { Search } from "lucide-react";
34
import debounce from "debounce";
@@ -82,8 +83,8 @@ function SearchbarSubjectList({
8283
}, [resetSearch]);
8384

8485
return (
85-
<div className="mx-4 md:mx-0">
86-
<form className=" my-2 ml-2 w-full max-w-xl">
86+
<div className="mx-0">
87+
<form className="my-2 ml-2 w-full max-w-xl">
8788
<div className="relative">
8889
<Input
8990
type="text"

0 commit comments

Comments
 (0)