Add API Dashboard Forum & Job

This commit is contained in:
2025-02-03 14:01:30 +08:00
parent 91f61f99c5
commit e5f56772ee
9 changed files with 408 additions and 34 deletions

View File

@@ -0,0 +1,56 @@
export {
apiGetAdminForumPublishCountDasboard,
apiGetAdminForumReportPosting,
apiGetAdminForumReportKomentar
}
const apiGetAdminForumPublishCountDasboard = async () => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/admin/forum/dashboard/publish`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
})
return await response.json().catch(() => null);
}
const apiGetAdminForumReportPosting = async () => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/admin/forum/dashboard/report_posting`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
})
return await response.json().catch(() => null);
}
const apiGetAdminForumReportKomentar = async () => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/admin/forum/dashboard/report_komentar`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
})
return await response.json().catch(() => null);
}

View File

@@ -5,58 +5,121 @@ import ComponentAdminGlobal_HeaderTamplate from "../../_admin_global/header_tamp
import { IconFlag, IconMessageReport, IconUpload } from "@tabler/icons-react";
import { AccentColor } from "@/app_modules/_global/color";
import { AdminColor } from "@/app_modules/_global/color/color_pallet";
import { useShallowEffect } from "@mantine/hooks";
import { clientLogger } from "@/util/clientLogger";
import global_limit from "@/app/lib/limit";
import { apiGetAdminForumPublishCountDasboard } from "../lib/api_fetch_admin_forum";
import { useState } from "react";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
export default function AdminForum_Main({
countPublish,
countLaporanPosting,
countLaporanKomentar,
}: {
countPublish: number;
countLaporanPosting: number;
countLaporanKomentar: number;
}) {
export default function AdminForum_Main() {
return (
<>
<Stack>
<ComponentAdminGlobal_HeaderTamplate name="Forum" />
<ForumMain
countPublish={countPublish}
countLaporanPosting={countLaporanPosting}
countLaporanKomentar={countLaporanKomentar}
// countPublish={countPublish}
// countLaporanPosting={countLaporanPosting}
// countLaporanKomentar={countLaporanKomentar}
/>
</Stack>
</>
);
}
function ForumMain({
countPublish,
countLaporanPosting,
countLaporanKomentar,
}: {
countPublish: number;
countLaporanPosting: number;
countLaporanKomentar: number;
}) {
function ForumMain() {
const [countPublish, setCountPublish] = useState<number | null>(null);
const [countLaporanPosting, setCountLaporanPosting] = useState<number | null>(null);
const [countLaporanKomentar, setCountLaporanKomentar] = useState<number | null>(null);
useShallowEffect(() => {
handlerLoadData();
}, [])
async function handlerLoadData() {
try {
const listLoadData = [
global_limit(() => onLoadCountPublish()),
global_limit(() => onLoadCountReportPosting()),
global_limit(() => onLoadCountReportKomentar()),
]
const result = await Promise.all(listLoadData);
} catch (error) {
clientLogger.error("Error handler load data", error);
}
}
async function onLoadCountPublish() {
try {
const response = await apiGetAdminForumPublishCountDasboard()
if (response) {
setCountPublish(response.data)
}
} catch (error) {
clientLogger.error("Error get count publish", error);
}
}
async function onLoadCountReportPosting() {
try {
const response = await apiGetAdminForumPublishCountDasboard()
if (response) {
setCountLaporanPosting(response.data)
}
} catch (error) {
clientLogger.error("Error get count publish", error);
}
}
async function onLoadCountReportKomentar() {
try {
const response = await apiGetAdminForumPublishCountDasboard()
if (response) {
setCountLaporanKomentar(response.data)
}
} catch (error) {
clientLogger.error("Error get count publish", error);
}
}
const listBox = [
{
id: 1,
name: "Publish",
jumlah: countPublish,
jumlah: countPublish == null ? (
<CustomSkeleton width={40} height={40} />
) : countPublish ? (
countPublish
) : (
"-"
),
color: "green",
icon: <IconUpload size={18} color="#4CAF4F" />
},
{
id: 2,
name: "Report Posting",
jumlah: countLaporanPosting,
jumlah: countLaporanPosting == null ? (
<CustomSkeleton width={40} height={40} />
) : countLaporanPosting ? (
countLaporanPosting
) : (
"-"
),
color: "orange",
icon: <IconFlag size={18} color="#FF9800" />
},
{
id: 3,
name: "Report Komentar",
jumlah: countLaporanKomentar,
jumlah: countLaporanKomentar == null ? (
<CustomSkeleton width={40} height={40} />
) : countLaporanKomentar ? (
countLaporanKomentar
) : (
"-"
),
color: "red",
icon: <IconMessageReport size={18} color="#F44336" />
},