Skip to content

Commit e66823a

Browse files
committed
Fix modal background issue
1 parent 36f7de9 commit e66823a

File tree

6 files changed

+113
-43
lines changed

6 files changed

+113
-43
lines changed

frontend/package-lock.json

Lines changed: 41 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"react-dom": "^18",
3333
"react-hook-form": "^7.53.0",
3434
"react-icons": "^5.3.0",
35+
"react-modal": "^3.16.1",
3536
"react-pro-sidebar": "^1.1.0",
3637
"react-spinners": "^0.14.1",
3738
"sweetalert2": "^11.14.1",
@@ -50,4 +51,4 @@
5051
"tailwindcss": "^3.4.1",
5152
"typescript": "^5"
5253
}
53-
}
54+
}

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
import { topicsList } from "@/app/(auth)/match/page";
44
import { Button } from "@/components/ui/button";
5-
import {
6-
DialogClose,
7-
DialogContent,
8-
DialogHeader,
9-
} from "@/components/ui/dialog";
105
import {
116
Form,
127
FormControl,
@@ -26,7 +21,11 @@ import { z } from "zod";
2621

2722
const QUESTION_SERVICE = process.env.NEXT_PUBLIC_QUESTION_SERVICE;
2823

29-
const AddQuestionDialog = () => {
24+
interface AddQuestionDialogProp {
25+
setClose: () => void;
26+
}
27+
28+
const AddQuestionDialog = ({ setClose }: AddQuestionDialogProp) => {
3029
const formSchema = z.object({
3130
questionTitle: z.string().min(2, {
3231
message: "Title must be at least 2 characters.",
@@ -66,30 +65,33 @@ const AddQuestionDialog = () => {
6665
category: values.questionTopics,
6766
complexity: values.questionDifficulty,
6867
}),
69-
}).then((response) => {
70-
if (response.ok) {
68+
})
69+
.then((response) => {
70+
if (response.ok) {
71+
Swal.fire({
72+
icon: "success",
73+
title: "Question Added",
74+
text: "Question has been added successfully.",
75+
});
76+
}
77+
78+
return response.json();
79+
})
80+
.catch((error) => {
7181
Swal.fire({
72-
icon: "success",
73-
title: "Question Added",
74-
text: "Question has been added successfully.",
82+
icon: "error",
83+
title: "Question Add Failed",
84+
text: "Please try again later.",
7585
});
76-
}
77-
78-
return response.json();
79-
}).catch((error) => {
80-
Swal.fire({
81-
icon: "error",
82-
title: "Question Add Failed",
83-
text: "Please try again later.",
8486
})
85-
});
87+
.finally(() => setClose());
8688
}
8789

8890
return (
89-
<DialogContent className="bg-primary-700 h-80%">
90-
<DialogHeader className="text-[32px] font-semibold text-yellow-500">
91+
<div className="bg-primary-700 p-10 w-[40vw] h-[80vh] rounded-lg">
92+
<div className="text-[32px] font-semibold text-yellow-500">
9193
Add Question
92-
</DialogHeader>
94+
</div>
9395
<Form {...form}>
9496
<form
9597
onSubmit={form.handleSubmit(onSubmit)} // Ensure form.handleSubmit is used correctly
@@ -177,12 +179,10 @@ const AddQuestionDialog = () => {
177179
</FormItem>
178180
)}
179181
/>
180-
<DialogClose>
181-
<Button type="submit">Submit</Button>
182-
</DialogClose>
182+
<Button type="submit">Submit</Button>
183183
</form>
184184
</Form>
185-
</DialogContent>
185+
</div>
186186
);
187187
};
188188

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const EditQuestionDialog = ({ id }: { id: string }) => {
8585
return (
8686
<DialogContent className="bg-primary-700 h-80%">
8787
<DialogHeader className="text-[32px] font-semibold text-yellow-500">
88-
Add Question
88+
Edit Question
8989
</DialogHeader>
9090
<Form {...form}>
9191
<form

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import { FaRegTrashAlt } from "react-icons/fa";
2525
import { getLeetcodeDashboardData } from "@/api/leetcode-dashboard";
2626
import { QuestionMinified } from "@/types/find-match";
2727
import MoonLoader from "react-spinners/MoonLoader";
28+
import { Dialog, DialogTrigger } from "@/components/ui/dialog";
29+
import EditQuestionDialog from "@/app/(auth)/leetcode-dashboard/EditQuestionDialog";
2830

2931
const Cell = ({
3032
className,
@@ -66,12 +68,15 @@ export const columns: ColumnDef<QuestionMinified>[] = [
6668
{
6769
accessorKey: "actions",
6870
header: () => <Cell>Actions</Cell>,
69-
cell: ({}) => {
71+
cell: ({ row }) => {
7072
return (
7173
<Cell>
72-
<Button variant={"ghost"}>
73-
<HiOutlinePencil />
74-
</Button>
74+
<Dialog>
75+
<DialogTrigger>
76+
<HiOutlinePencil />
77+
<EditQuestionDialog />
78+
</DialogTrigger>
79+
</Dialog>
7580
<Button variant={"ghost"}>
7681
<FaRegTrashAlt />
7782
</Button>

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

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
"use client";
22

3+
import AddQuestionDialog from "@/app/(auth)/leetcode-dashboard/AddQuestionDialog";
34
import { LeetcodeDashboardTable } from "@/app/(auth)/leetcode-dashboard/LeetcodeDashboardTable";
5+
import { Button } from "@/components/ui/button";
46
import Container from "@/components/ui/Container";
57
import { PlusIcon } from "lucide-react";
6-
import { Dialog, DialogTrigger } from "@/components/ui/dialog";
7-
import AddQuestionDialog from "@/app/(auth)/leetcode-dashboard/AddQuestionDialog";
8+
import { useState } from "react";
9+
import Modal from "react-modal";
810

911
const LeetcodeDashboardHeader = () => {
1012
return (
@@ -22,17 +24,39 @@ const LeetcodeDashboardHeader = () => {
2224
};
2325

2426
const LeetcodeDashboard = () => {
27+
const [modalIsOpen, setIsOpen] = useState(false);
28+
29+
function openModal() {
30+
setIsOpen(true);
31+
}
32+
33+
function closeModal() {
34+
setIsOpen(false);
35+
}
36+
2537
return (
2638
<Container>
2739
<LeetcodeDashboardHeader />
2840
<div className="flex justify-end mb-4">
29-
<Dialog>
30-
{/* Unable to reuse Button as cannot render Button inside DialogTrigger (causes hydration error) */}
31-
<DialogTrigger className="bg-yellow-500 text-primary-foreground hover:bg-yellow-300 rounded flex text-primary-900 p-3">
32-
<PlusIcon /> Add A Question
33-
</DialogTrigger>
34-
<AddQuestionDialog />
35-
</Dialog>
41+
<Button
42+
onClick={openModal}
43+
className="bg-yellow-500 hover:bg-yellow-300 text-black hover:text-primary-800 flex flex-row gap-2"
44+
>
45+
<PlusIcon />
46+
Add a Question
47+
</Button>
48+
<Modal
49+
isOpen={modalIsOpen}
50+
onRequestClose={closeModal}
51+
className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
52+
style={{
53+
overlay: {
54+
backgroundColor: "rgba(29, 36, 51, 0.8)",
55+
},
56+
}}
57+
>
58+
<AddQuestionDialog setClose={closeModal} />
59+
</Modal>
3660
</div>
3761
<LeetcodeDashboardTable />
3862
</Container>

0 commit comments

Comments
 (0)