Skip to content

Commit 3ef9424

Browse files
committed
Add spinner for AddQuestionDialog
1 parent 58a2dcb commit 3ef9424

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

frontend/src/app/(auth)/leetcode-dashboard/AddQuestionDialog.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ import { MultiSelect } from "@/components/ui/multiselect";
1515
import { Textarea } from "@/components/ui/textarea";
1616
import { QuestionDifficulty } from "@/types/find-match";
1717
import { zodResolver } from "@hookform/resolvers/zod";
18+
import { useState } from "react";
1819
import { useForm } from "react-hook-form";
1920
import Swal from "sweetalert2";
2021
import { z } from "zod";
22+
import MoonLoader from "react-spinners/MoonLoader";
2123

2224
const QUESTION_SERVICE = process.env.NEXT_PUBLIC_QUESTION_SERVICE;
2325

@@ -26,6 +28,8 @@ interface AddQuestionDialogProp {
2628
}
2729

2830
const AddQuestionDialog = ({ setClose }: AddQuestionDialogProp) => {
31+
const [isSubmitting, setIsSubmitting] = useState(false);
32+
2933
const formSchema = z.object({
3034
questionTitle: z.string().min(2, {
3135
message: "Title must be at least 2 characters.",
@@ -52,8 +56,8 @@ const AddQuestionDialog = ({ setClose }: AddQuestionDialogProp) => {
5256
});
5357

5458
async function onSubmit(values: z.infer<typeof formSchema>) {
59+
setIsSubmitting(true);
5560
const url = `${QUESTION_SERVICE}/create`;
56-
console.log("url", url);
5761
await fetch(url, {
5862
method: "POST",
5963
headers: {
@@ -84,11 +88,14 @@ const AddQuestionDialog = ({ setClose }: AddQuestionDialogProp) => {
8488
text: "Please try again later.",
8589
});
8690
})
87-
.finally(() => setClose());
91+
.finally(() => {
92+
setIsSubmitting(false);
93+
setClose();
94+
});
8895
}
8996

9097
return (
91-
<div className="bg-primary-700 p-10 w-[60vw] h-[80vh] rounded-lg">
98+
<div className="bg-primary-700 p-10 w-[60vw] rounded-lg pb-14">
9299
<div className="text-[32px] font-semibold text-yellow-500">
93100
Add Question
94101
</div>
@@ -180,7 +187,9 @@ const AddQuestionDialog = ({ setClose }: AddQuestionDialogProp) => {
180187
</FormItem>
181188
)}
182189
/>
183-
<Button type="submit">Submit</Button>
190+
<Button type="submit" className="mt-8">
191+
{isSubmitting ? <MoonLoader size="20" /> : "Submit"}
192+
</Button>
184193
</form>
185194
</Form>
186195
</div>

0 commit comments

Comments
 (0)