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,44 @@
import { prisma } from "@/app/lib";
import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export async function GET(request: Request, { params }: {
params: { status: string }
}) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed",
},
{ status: 405 }
)
}
try {
let fixData;
fixData = await prisma.forum_Posting.count({
where: {
isActive: true,
}
})
return NextResponse.json({
success: true,
message: "Success get data forum dashboard",
data: fixData,
},
{ status: 200 }
);
} catch (error) {
backendLogger.error("Error get data forum dashboard", error);
return NextResponse.json({
success: false,
message: "Error get data forum dashboard",
reason: (error as Error).message
},
{ status: 500 }
)
} finally {
await prisma.$disconnect();
}
}

View File

@@ -0,0 +1,41 @@
import { prisma } from "@/app/lib";
import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export async function GET(request: Request) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed",
},
{ status: 405 }
)
}
try {
let fixData;
fixData = await prisma.forum_ReportKomentar.count({
where: {
isActive: true,
}
})
return NextResponse.json({
success: true,
message: "Success get data forum dashboard",
data: fixData,
},
{ status: 200 }
);
} catch (error) {
backendLogger.error("Error get data forum dashboard", error);
return NextResponse.json({
success: false,
message: "Error get data forum dashboard",
reason: (error as Error).message
},
{ status: 500 }
)
} finally {
await prisma.$disconnect();
}
}

View File

@@ -0,0 +1,41 @@
import { prisma } from "@/app/lib";
import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export async function GET(request: Request) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed",
},
{ status: 405 }
)
}
try {
let fixData;
fixData = await prisma.forum_ReportPosting.count({
where: {
isActive: true,
}
})
return NextResponse.json({
success: true,
message: "Success get data forum dashboard",
data: fixData,
},
{ status: 200 }
);
} catch (error) {
backendLogger.error("Error get data forum dashboard", error);
return NextResponse.json({
success: false,
message: "Error get data forum dashboard",
reason: (error as Error).message
},
{ status: 500 }
)
} finally {
await prisma.$disconnect();
}
}

View File

@@ -14,9 +14,9 @@ export default async function Page() {
return ( return (
<> <>
<AdminForum_Main <AdminForum_Main
countPublish={countPublish} // countPublish={countPublish}
countLaporanPosting={countLaporanPosting} // countLaporanPosting={countLaporanPosting}
countLaporanKomentar={countLaporanKomentar} // countLaporanKomentar={countLaporanKomentar}
/> />
</> </>
); );

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 { IconFlag, IconMessageReport, IconUpload } from "@tabler/icons-react";
import { AccentColor } from "@/app_modules/_global/color"; import { AccentColor } from "@/app_modules/_global/color";
import { AdminColor } from "@/app_modules/_global/color/color_pallet"; 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({ export default function AdminForum_Main() {
countPublish,
countLaporanPosting,
countLaporanKomentar,
}: {
countPublish: number;
countLaporanPosting: number;
countLaporanKomentar: number;
}) {
return ( return (
<> <>
<Stack> <Stack>
<ComponentAdminGlobal_HeaderTamplate name="Forum" /> <ComponentAdminGlobal_HeaderTamplate name="Forum" />
<ForumMain <ForumMain
countPublish={countPublish} // countPublish={countPublish}
countLaporanPosting={countLaporanPosting} // countLaporanPosting={countLaporanPosting}
countLaporanKomentar={countLaporanKomentar} // countLaporanKomentar={countLaporanKomentar}
/> />
</Stack> </Stack>
</> </>
); );
} }
function ForumMain({ function ForumMain() {
countPublish, const [countPublish, setCountPublish] = useState<number | null>(null);
countLaporanPosting, const [countLaporanPosting, setCountLaporanPosting] = useState<number | null>(null);
countLaporanKomentar, const [countLaporanKomentar, setCountLaporanKomentar] = useState<number | null>(null);
}: {
countPublish: number;
countLaporanPosting: number; useShallowEffect(() => {
countLaporanKomentar: number; 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 = [ const listBox = [
{ {
id: 1, id: 1,
name: "Publish", name: "Publish",
jumlah: countPublish, jumlah: countPublish == null ? (
<CustomSkeleton width={40} height={40} />
) : countPublish ? (
countPublish
) : (
"-"
),
color: "green", color: "green",
icon: <IconUpload size={18} color="#4CAF4F" /> icon: <IconUpload size={18} color="#4CAF4F" />
}, },
{ {
id: 2, id: 2,
name: "Report Posting", name: "Report Posting",
jumlah: countLaporanPosting, jumlah: countLaporanPosting == null ? (
<CustomSkeleton width={40} height={40} />
) : countLaporanPosting ? (
countLaporanPosting
) : (
"-"
),
color: "orange", color: "orange",
icon: <IconFlag size={18} color="#FF9800" /> icon: <IconFlag size={18} color="#FF9800" />
}, },
{ {
id: 3, id: 3,
name: "Report Komentar", name: "Report Komentar",
jumlah: countLaporanKomentar, jumlah: countLaporanKomentar == null ? (
<CustomSkeleton width={40} height={40} />
) : countLaporanKomentar ? (
countLaporanKomentar
) : (
"-"
),
color: "red", color: "red",
icon: <IconMessageReport size={18} color="#F44336" /> icon: <IconMessageReport size={18} color="#F44336" />
}, },

View File

@@ -0,0 +1,39 @@
export {
apiGetJobStatusCountDashboard,
apiGetJobArsipCount
}
const apiGetJobStatusCountDashboard = async ({ name }: {
name: "Publish" | "Review" | "Reject";
}) => {
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/job/dashboard/${name}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
});
return await response.json().catch(() => null)
}
const apiGetJobArsipCount = 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/job/dashboard/arsip`, {
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

@@ -8,6 +8,10 @@ import { clientLogger } from "@/util/clientLogger";
import { IconAlertTriangle, IconArchive, IconBookmark, IconUpload } from "@tabler/icons-react"; import { IconAlertTriangle, IconArchive, IconBookmark, IconUpload } from "@tabler/icons-react";
import { AccentColor } from "@/app_modules/_global/color"; import { AccentColor } from "@/app_modules/_global/color";
import { AdminColor } from "@/app_modules/_global/color/color_pallet"; import { AdminColor } from "@/app_modules/_global/color/color_pallet";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import global_limit from "@/app/lib/limit";
import { useShallowEffect } from "@mantine/hooks";
import { apiGetJobArsipCount, apiGetJobStatusCountDashboard } from "../lib/api_fetch_admin_job";
export default function AdminJob_Main({ export default function AdminJob_Main({
// countPublish, // countPublish,
@@ -26,29 +30,102 @@ export default function AdminJob_Main({
const [countArsip, setCountArsip] = useState<number | null>(null); const [countArsip, setCountArsip] = useState<number | null>(null);
const router = useRouter(); const router = useRouter();
useShallowEffect(() => {
handlerLoadData();
}, []);
async function handlerLoadData() {
try {
const listLoadData = [
global_limit(() => onLoadCountPublish()),
global_limit(() => onLoadCountReview()),
global_limit(() => onLoadCountReject()),
global_limit(() => onLoadCountArsip()),
]
} catch (error) {
clientLogger.error("Error handler load data", error)
}
}
async function onLoadCountPublish() { async function onLoadCountPublish() {
try { try {
const response = await apiGetJobStatusCountDashboard({
name: "Publish",
})
if (response) {
setCountPublish(response.data);
}
} catch (error) { } catch (error) {
clientLogger.error("Error get count publish", error) clientLogger.error("Error get count publish", error)
} }
} }
async function onLoadCountReview() {
try {
const response = await apiGetJobStatusCountDashboard({
name: "Review",
})
if (response) {
setCountReview(response.data);
}
} catch (error) {
clientLogger.error("Error get count review", error)
}
}
async function onLoadCountReject() {
try {
const response = await apiGetJobStatusCountDashboard({
name: "Reject",
})
if (response) {
setCountReject(response.data);
}
} catch (error) {
clientLogger.error("Error get count reject", error)
}
}
async function onLoadCountArsip() {
try {
const response = await apiGetJobArsipCount()
if (response) {
setCountArsip(response.data);
}
} catch (error) {
clientLogger.error("Error get count arsip", error)
}
}
const listStatus = [ const listStatus = [
{ {
id: 1, id: 1,
name: "Publish", name: "Publish",
jumlah: countPublish, jumlah: countPublish == null ? (
<CustomSkeleton height={40} width={40} />
) : countPublish ? (
countPublish
) : (
"-"
),
color: "green", color: "green",
text_color: "white", text_color: "white",
icon: <IconUpload size={18} color="#4CAF4F" /> icon: <IconUpload size={18} color="#4CAF4F" />
}, },
{ {
id: 2, id: 2,
name: "Review", name: "Review",
jumlah: countReview, jumlah: countReview == null ? (
<CustomSkeleton height={40} width={40} />
) : countReview ? (
countReview
) : (
"-"
),
color: "orange", color: "orange",
text_color: "white", text_color: "white",
icon: <IconBookmark size={18} color="#FF7043" /> icon: <IconBookmark size={18} color="#FF7043" />
@@ -56,7 +133,13 @@ export default function AdminJob_Main({
{ {
id: 3, id: 3,
name: "Reject", name: "Reject",
jumlah: countReject, jumlah: countReject == null ? (
<CustomSkeleton height={40} width={40} />
) : countReject ? (
countReject
) : (
"-"
),
color: "red", color: "red",
text_color: "white", text_color: "white",
icon: <IconAlertTriangle size={18} color="#FF4B4C" /> icon: <IconAlertTriangle size={18} color="#FF4B4C" />
@@ -64,7 +147,13 @@ export default function AdminJob_Main({
{ {
id: 4, id: 4,
name: "Arsip", name: "Arsip",
jumlah: countArsip, jumlah: countArsip == null ? (
<CustomSkeleton height={40} width={40} />
) : countArsip ? (
countArsip
) : (
"-"
),
color: "gray", color: "gray",
text_color: "white", text_color: "white",
icon: <IconArchive size={18} color="#007CBA" /> icon: <IconArchive size={18} color="#007CBA" />

View File

@@ -42,6 +42,7 @@ const middlewareConfig: MiddlewareConfig = {
// "/api/admin/donasi/dashboard/*", // "/api/admin/donasi/dashboard/*",
// "/api/admin/voting/dashboard/*", // "/api/admin/voting/dashboard/*",
// "/api/admin/job/dashboard/*", // "/api/admin/job/dashboard/*",
// "/api/admin/forum/dashboard/*",
// Akses awal // Akses awal