Add API Dashboard ADMIN Doasi, Job, dan Voting
This commit is contained in:
@@ -19,11 +19,11 @@ const apiGetDonasiStatusCountDashboard = async ({ name }:
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
const apiGetDonasiKategoriCountDashboard = async ({ name }: { name: "Kategori" }) => {
|
||||
const apiGetDonasiKategoriCountDashboard = 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/donasi/dashboard/${name}`, {
|
||||
const response = await fetch(`/api/admin/donasi/dashboard/kategori`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
@@ -99,9 +99,7 @@ export default function AdminDonasi_Main({
|
||||
}
|
||||
async function onLoadCountKategori() {
|
||||
try {
|
||||
const response = await apiGetDonasiKategoriCountDashboard({
|
||||
name: "Kategori"
|
||||
})
|
||||
const response = await apiGetDonasiKategoriCountDashboard()
|
||||
if (response) {
|
||||
setCountKategori(response.data);
|
||||
}
|
||||
|
||||
@@ -3,20 +3,34 @@
|
||||
import { Group, Paper, SimpleGrid, Stack, Text, Title } from "@mantine/core";
|
||||
import ComponentAdminGlobal_HeaderTamplate from "../../_admin_global/header_tamplate";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
|
||||
export default function AdminJob_Main({
|
||||
countPublish,
|
||||
countReview,
|
||||
countReject,
|
||||
countArsip,
|
||||
// countPublish,
|
||||
// countReview,
|
||||
// countReject,
|
||||
// countArsip,
|
||||
}: {
|
||||
countPublish: number;
|
||||
countReview: number;
|
||||
countReject: number;
|
||||
countArsip: number
|
||||
}) {
|
||||
// countPublish: number;
|
||||
// countReview: number;
|
||||
// countReject: number;
|
||||
// countArsip: number
|
||||
}) {
|
||||
const [countPublish, setCountPublish] = useState<number | null>(null);
|
||||
const [countReview, setCountReview] = useState<number | null>(null);
|
||||
const [countReject, setCountReject] = useState<number | null>(null);
|
||||
const [countArsip, setCountArsip] = useState<number | null>(null);
|
||||
const router = useRouter();
|
||||
|
||||
async function onLoadCountPublish() {
|
||||
try {
|
||||
|
||||
} catch (error) {
|
||||
clientLogger.error("Error get count publish", error)
|
||||
}
|
||||
}
|
||||
|
||||
const listStatus = [
|
||||
{
|
||||
id: 1,
|
||||
|
||||
36
src/app_modules/admin/vote/lib/api_fetch_admin_voting.ts
Normal file
36
src/app_modules/admin/vote/lib/api_fetch_admin_voting.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
export {
|
||||
apiGetVoteStatusCountDashboard,
|
||||
apiGetVoteRiwayatCount
|
||||
}
|
||||
const apiGetVoteStatusCountDashboard = 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/voting/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 apiGetVoteRiwayatCount = 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/voting/dashboard/riwayat`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
}
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
@@ -5,49 +5,134 @@ import { useRouter } from "next/navigation";
|
||||
import ComponentAdminGlobal_HeaderTamplate from "../../_admin_global/header_tamplate";
|
||||
import { IconAlertTriangle, IconBookmark, IconHistory, IconUpload } from "@tabler/icons-react";
|
||||
import { AccentColor, AdminColor } from "@/app_modules/_global/color/color_pallet";
|
||||
import { useState } from "react";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import { apiGetVoteRiwayatCount, apiGetVoteStatusCountDashboard } from "../lib/api_fetch_admin_voting";
|
||||
import global_limit from "@/app/lib/limit";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||
|
||||
export default function AdminVote_Main() {
|
||||
const [countPublish, setCountPublish] = useState<number | null>(null);
|
||||
const [countReview, setCountReview] = useState<number | null>(null);
|
||||
const [countReject, setCountReject] = useState<number | null>(null);
|
||||
const [countRiwayat, setCountRiwayat] = useState<number | null>(null);
|
||||
|
||||
useShallowEffect(() => {
|
||||
handlerLoadData();
|
||||
}, []);
|
||||
async function handlerLoadData() {
|
||||
try {
|
||||
const listLoadData = [
|
||||
global_limit(() => onLoadCountPublish()),
|
||||
global_limit(() => onLoadCountReview()),
|
||||
global_limit(() => onLoadCountReject()),
|
||||
global_limit(() => onLoadCountRiwayat()),
|
||||
];
|
||||
const result = await Promise.all(listLoadData);
|
||||
} catch (error) {
|
||||
clientLogger.error("Error handler load data", error);
|
||||
}
|
||||
}
|
||||
async function onLoadCountPublish() {
|
||||
try {
|
||||
const response = await apiGetVoteStatusCountDashboard({
|
||||
name: "Publish",
|
||||
})
|
||||
if (response) {
|
||||
setCountPublish(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
clientLogger.error("Error get count publish", error);
|
||||
}
|
||||
}
|
||||
async function onLoadCountReview() {
|
||||
try {
|
||||
const response = await apiGetVoteStatusCountDashboard({
|
||||
name: "Review",
|
||||
})
|
||||
|
||||
if (response) {
|
||||
setCountReview(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
clientLogger.error("Error get count review", error);
|
||||
}
|
||||
}
|
||||
async function onLoadCountReject() {
|
||||
try {
|
||||
const response = await apiGetVoteStatusCountDashboard({
|
||||
name: "Reject",
|
||||
})
|
||||
if (response) {
|
||||
setCountReject(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
clientLogger.error("Error get count reject", error);
|
||||
}
|
||||
}
|
||||
async function onLoadCountRiwayat() {
|
||||
try {
|
||||
const response = await apiGetVoteRiwayatCount()
|
||||
if (response) {
|
||||
setCountRiwayat(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
clientLogger.error("Error get count riwayat", error);
|
||||
}
|
||||
}
|
||||
|
||||
export default function AdminVote_Main({
|
||||
countPublish,
|
||||
countReview,
|
||||
countDraft,
|
||||
countReject,
|
||||
countRiwayat,
|
||||
}: {
|
||||
countPublish?: number;
|
||||
countReview?: number;
|
||||
countDraft?: number;
|
||||
countReject?: number;
|
||||
countRiwayat?: number;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
|
||||
const listStatus = [
|
||||
{
|
||||
id: 1,
|
||||
name: "Publish",
|
||||
jumlah: countPublish,
|
||||
jumlah: countPublish == null ? (
|
||||
<CustomSkeleton height={40} width={40} />
|
||||
) : countPublish ? (
|
||||
countPublish
|
||||
) : (
|
||||
"-"
|
||||
),
|
||||
color: "green",
|
||||
icon: <IconUpload size={18} color="#4CAF4F"/>
|
||||
icon: <IconUpload size={18} color="#4CAF4F" />
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "Review",
|
||||
jumlah: countReview,
|
||||
jumlah: countReview == null ? (
|
||||
<CustomSkeleton height={40} width={40} />
|
||||
) : countReview ? (
|
||||
countReview
|
||||
) : (
|
||||
"-"
|
||||
),
|
||||
color: "orange",
|
||||
icon: <IconBookmark size={18} color="#FF7043" />
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: "Reject",
|
||||
jumlah: countReject,
|
||||
jumlah: countReject == null ? (
|
||||
<CustomSkeleton height={40} width={40} />
|
||||
) : countReject ? (
|
||||
countReject
|
||||
) : (
|
||||
"-"
|
||||
),
|
||||
color: "red",
|
||||
icon: <IconAlertTriangle size={18} color="#FF4B4C" />
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: "Riwayat",
|
||||
jumlah: countDraft,
|
||||
path: "",
|
||||
jumlah: countRiwayat == null ? (
|
||||
<CustomSkeleton height={40} width={40} />
|
||||
) : countRiwayat ? (
|
||||
countRiwayat
|
||||
) : (
|
||||
"-"
|
||||
),
|
||||
color: "gray",
|
||||
icon: <IconHistory size={18} color="#007CBA" />
|
||||
},
|
||||
|
||||
30
src/app_modules/job/lib/api_fetch_admin_job.ts
Normal file
30
src/app_modules/job/lib/api_fetch_admin_job.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
const apiGetJobStatuCountDashboard = 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 apiGetJobStatusCountArsip = 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);
|
||||
}
|
||||
Reference in New Issue
Block a user