Add API Dashboard Forum & Job
This commit is contained in:
44
src/app/api/admin/forum/dashboard/publish/route.ts
Normal file
44
src/app/api/admin/forum/dashboard/publish/route.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
41
src/app/api/admin/forum/dashboard/report_komentar/route.ts
Normal file
41
src/app/api/admin/forum/dashboard/report_komentar/route.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
41
src/app/api/admin/forum/dashboard/report_posting/route.ts
Normal file
41
src/app/api/admin/forum/dashboard/report_posting/route.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,9 @@ export default async function Page() {
|
||||
return (
|
||||
<>
|
||||
<AdminForum_Main
|
||||
countPublish={countPublish}
|
||||
countLaporanPosting={countLaporanPosting}
|
||||
countLaporanKomentar={countLaporanKomentar}
|
||||
// countPublish={countPublish}
|
||||
// countLaporanPosting={countLaporanPosting}
|
||||
// countLaporanKomentar={countLaporanKomentar}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
56
src/app_modules/admin/forum/lib/api_fetch_admin_forum.ts
Normal file
56
src/app_modules/admin/forum/lib/api_fetch_admin_forum.ts
Normal 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);
|
||||
}
|
||||
@@ -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" />
|
||||
},
|
||||
|
||||
39
src/app_modules/admin/job/lib/api_fetch_admin_job.ts
Normal file
39
src/app_modules/admin/job/lib/api_fetch_admin_job.ts
Normal 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)
|
||||
|
||||
};
|
||||
@@ -8,6 +8,10 @@ import { clientLogger } from "@/util/clientLogger";
|
||||
import { IconAlertTriangle, IconArchive, IconBookmark, IconUpload } from "@tabler/icons-react";
|
||||
import { AccentColor } from "@/app_modules/_global/color";
|
||||
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({
|
||||
// countPublish,
|
||||
@@ -26,29 +30,102 @@ export default function AdminJob_Main({
|
||||
const [countArsip, setCountArsip] = useState<number | null>(null);
|
||||
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() {
|
||||
try {
|
||||
|
||||
const response = await apiGetJobStatusCountDashboard({
|
||||
name: "Publish",
|
||||
})
|
||||
if (response) {
|
||||
setCountPublish(response.data);
|
||||
}
|
||||
} catch (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 = [
|
||||
{
|
||||
id: 1,
|
||||
name: "Publish",
|
||||
jumlah: countPublish,
|
||||
jumlah: countPublish == null ? (
|
||||
<CustomSkeleton height={40} width={40} />
|
||||
) : countPublish ? (
|
||||
countPublish
|
||||
) : (
|
||||
"-"
|
||||
),
|
||||
color: "green",
|
||||
text_color: "white",
|
||||
icon: <IconUpload size={18} color="#4CAF4F" />
|
||||
|
||||
|
||||
|
||||
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "Review",
|
||||
jumlah: countReview,
|
||||
jumlah: countReview == null ? (
|
||||
<CustomSkeleton height={40} width={40} />
|
||||
) : countReview ? (
|
||||
countReview
|
||||
) : (
|
||||
"-"
|
||||
),
|
||||
color: "orange",
|
||||
text_color: "white",
|
||||
icon: <IconBookmark size={18} color="#FF7043" />
|
||||
@@ -56,7 +133,13 @@ export default function AdminJob_Main({
|
||||
{
|
||||
id: 3,
|
||||
name: "Reject",
|
||||
jumlah: countReject,
|
||||
jumlah: countReject == null ? (
|
||||
<CustomSkeleton height={40} width={40} />
|
||||
) : countReject ? (
|
||||
countReject
|
||||
) : (
|
||||
"-"
|
||||
),
|
||||
color: "red",
|
||||
text_color: "white",
|
||||
icon: <IconAlertTriangle size={18} color="#FF4B4C" />
|
||||
@@ -64,7 +147,13 @@ export default function AdminJob_Main({
|
||||
{
|
||||
id: 4,
|
||||
name: "Arsip",
|
||||
jumlah: countArsip,
|
||||
jumlah: countArsip == null ? (
|
||||
<CustomSkeleton height={40} width={40} />
|
||||
) : countArsip ? (
|
||||
countArsip
|
||||
) : (
|
||||
"-"
|
||||
),
|
||||
color: "gray",
|
||||
text_color: "white",
|
||||
icon: <IconArchive size={18} color="#007CBA" />
|
||||
|
||||
@@ -42,6 +42,7 @@ const middlewareConfig: MiddlewareConfig = {
|
||||
// "/api/admin/donasi/dashboard/*",
|
||||
// "/api/admin/voting/dashboard/*",
|
||||
// "/api/admin/job/dashboard/*",
|
||||
// "/api/admin/forum/dashboard/*",
|
||||
|
||||
|
||||
// Akses awal
|
||||
|
||||
Reference in New Issue
Block a user