diff --git a/frontend/app/admin/page.tsx b/frontend/app/admin/page.tsx
index 9a5aa66c..119d245c 100644
--- a/frontend/app/admin/page.tsx
+++ b/frontend/app/admin/page.tsx
@@ -12,6 +12,7 @@ import { CubeIcon, FlagIcon, UserCircleIcon } from "@heroicons/react/24/solid";
import Link from "next/link";
import { HttpCodes } from "@/types/HttpCodes";
import { set } from "react-hook-form";
+import { report } from "process";
axios.defaults.withCredentials = true;
@@ -77,22 +78,22 @@ const AdminHomepage = () => {
fetchReports();
}, []);
-
- const closeReport = async ( reportId: string ) => {
+ const closeReport = async (reportId: string) => {
setMessage("Loading");
- try {
- const response = await axios.post(siteConfig.server_url + "/report/close",
- {
- reportId: reportId as string
- }
- );
- fetchReports();
- setMessage("");
-
- } catch (err: any) {
- setError(err.response.data.message || "Error closing report:" + err);
- }
+ try {
+ const response = await axios.post(siteConfig.server_url + "/report/close",
+ {
+ reportId: reportId as string
+ }
+ );
+ fetchReports();
+ setMessage("");
+
+ } catch (err: any) {
+ setError(err.response.data.message || "Error closing report:" + err);
+ }
}
+
const banUser = async (usermail: string) => {
setMessage("Loading...")
try {
@@ -103,7 +104,7 @@ const AdminHomepage = () => {
}
fetchUsers();
setMessage("");
-
+
} catch (error: any) {
setError(error.response.data.message || "Error occured");
setMessage("")
@@ -196,27 +197,21 @@ const AdminHomepage = () => {
- {users.length}
+ {reports.length}
- {users.filter(user => user.role == "user").length}
-
-
Pending
-
-
-
- {users.filter(user => user.role == "admin").length}
+ {reports.filter(report => report.status == "open").length}
-
Completed
+
Open
- {users.filter(user => user.role == "banned").length}
+ {reports.filter(report => report.status == "closed").length}
-
Irrelevant
+
Closed
@@ -314,15 +309,15 @@ const AdminHomepage = () => {
{u.postId}
{u.reason}
-
+
))}
-
+
)
diff --git a/frontend/app/report/create/page.tsx b/frontend/app/report/create/page.tsx
index db45b836..44cd0d8c 100644
--- a/frontend/app/report/create/page.tsx
+++ b/frontend/app/report/create/page.tsx
@@ -8,50 +8,25 @@ import { Button } from "@nextui-org/button";
import { siteConfig } from "@/config/site";
import axios from "axios";
+type FormData = {
+ reason: string
+}
+
export default function CreateReport() {
- const { register, formState: { errors }, control, reset } = useForm()
- const [postId, setPostId] = useState("");
- useEffect(() => {
- // Check if window is available before accessing it
- if (typeof window !== 'undefined') {
- const params = new URLSearchParams(window.location.search);
- const postIdFound = params.get('value') as string ;
- if(postIdFound) {
- setPostId(postIdFound);
- }
- // Do something with postId
+ const { register, formState: { errors }, control, reset } = useForm()
+ const [postId, setPostId] = useState("");
+
+ useEffect(() => {
+ // Check if window is available before accessing it
+ if (typeof window !== 'undefined') {
+ const params = new URLSearchParams(window.location.search);
+ const postIdFound = params.get('value') as string;
+ if (postIdFound) {
+ setPostId(postIdFound);
+ }
+ }
+ }, []);
- // const onSubmit = async (reason: string) => {
- // try {
- // const res = await axios.post(siteConfig.server_url + "/report/create", {
- // reason: reason,
- // postId: postId
- // }, {
- // withCredentials: true,
- // headers: {
- // 'Content-Type': 'application/json'
- // }
- // });
-
- // if (res.status == 201) {
- // setError(null)
- // setMessage("Report created successfully.")
- // window.location.href = "/post/details/" + res.data.data.postId
- // reset()
- // } else if (res.status == 401) {
- // window.location.href = "/"
- // }
- // else {
- // setError(res.data.error || "There was an error creating your report.")
- // }
- // }
- // catch (err: any) {
- // setError(err.response.data.message || "There was an error creating your report.")
- // }
- // }
-
- }
- }, []);
const [message, setMessage] = useState(null)
const [error, setError] = useState(null)
@@ -59,7 +34,7 @@ export default function CreateReport() {
try {
const res = await axios.post(siteConfig.server_url + "/report/create", {
reason: reason as string,
- postId: postId
+ postId: postId
}, {
withCredentials: true,
headers: {
@@ -80,7 +55,7 @@ export default function CreateReport() {
}
}
catch (err: any) {
- setError( "There was an error creating your report.")
+ setError("There was an error creating your report.")
}
}
@@ -96,10 +71,10 @@ export default function CreateReport() {