fix:dashboard stats

This commit is contained in:
Rama Priyanto 2025-06-13 17:03:42 +07:00
commit 413f28599f
5 changed files with 162 additions and 24 deletions

View File

@ -258,6 +258,9 @@ export default function Login() {
Cookies.set("urie", profile?.userRoleId, { Cookies.set("urie", profile?.userRoleId, {
expires: 1, expires: 1,
}); });
// Cookies.set("roleName", profile?.roleName, {
// expires: 1,
// });
// Cookies.set("masterPoldaId", profile?.masterPoldaId, { // Cookies.set("masterPoldaId", profile?.masterPoldaId, {
// expires: 1, // expires: 1,
// }); // });

View File

@ -296,7 +296,7 @@ export default function HeaderNews() {
className={`!object-cover !rounded-none ${ className={`!object-cover !rounded-none ${
portraitMap[index] portraitMap[index]
? "!w-auto object-cover mx-auto" ? "!w-auto object-cover mx-auto"
: "w-full" : "!w-full"
} !h-[500px]`} } !h-[500px]`}
/> />

View File

@ -220,7 +220,7 @@ export default function BannerHumasNew() {
return ( return (
<div className="h-fit relative text-white overflow-hidden"> <div className="h-fit relative text-white overflow-hidden">
<div <div
className="flex w-full h-[45vh] lg:h-[93vh] transition-transform duration-700 ease-in-out" className="flex w-full h-[60vh] lg:h-[93vh] transition-transform duration-700 ease-in-out"
style={{ transform: `translateX(-${currentIndex * 100}%)` }} style={{ transform: `translateX(-${currentIndex * 100}%)` }}
> >
{jumbotronList?.length > 0 ? ( {jumbotronList?.length > 0 ? (
@ -237,7 +237,9 @@ export default function BannerHumasNew() {
: img?.contentFileUrl : img?.contentFileUrl
} }
alt={`humasbanner-${index}`} alt={`humasbanner-${index}`}
className="w-screen h-[45vh] lg:h-[93vh] object-cover object-center opacity-[25] dark:opacity-70 rounded-none" width={1960}
height={1080}
className="w-screen h-[60vh] lg:h-[93vh] object-cover object-center opacity-[25] dark:opacity-70 rounded-none"
/> />
</Link> </Link>
)) ))

View File

@ -9,6 +9,8 @@ import {
} from "@/components/icons/dashboard-icon"; } from "@/components/icons/dashboard-icon";
import { Submenu1Icon } from "@/components/icons/sidebar-icon"; import { Submenu1Icon } from "@/components/icons/sidebar-icon";
import { import {
Accordion,
AccordionItem,
Button, Button,
Calendar, Calendar,
Checkbox, Checkbox,
@ -21,6 +23,7 @@ import {
Select, Select,
SelectItem, SelectItem,
SelectSection, SelectSection,
Skeleton,
} from "@heroui/react"; } from "@heroui/react";
import ApexChartColumn from "./chart/column-chart"; import ApexChartColumn from "./chart/column-chart";
import ApexChartDonut from "./chart/donut-chart"; import ApexChartDonut from "./chart/donut-chart";
@ -104,6 +107,10 @@ export default function DashboardContainer() {
const [topPages, setTopPages] = useState<TopPages[]>([]); const [topPages, setTopPages] = useState<TopPages[]>([]);
const [postCount, setPostCount] = useState<PostCount[]>([]); const [postCount, setPostCount] = useState<PostCount[]>([]);
const [polresData, setPolresData] = useState<any>({});
const [selectedAccordion, setSelectedAccordion] = useState<any>(new Set([]));
const roleId = Cookies.get("urie");
useEffect(() => { useEffect(() => {
fetchSummary(); fetchSummary();
@ -176,7 +183,7 @@ export default function DashboardContainer() {
getDate(postContentDate.endDate), getDate(postContentDate.endDate),
getUnixTimestamp() getUnixTimestamp()
); );
setPostCount(getTableNumber(10, res?.data?.data)); setPostCount(getTableNumberStats(res?.data?.data));
} }
const getTableNumber = (limit: number, data: any) => { const getTableNumber = (limit: number, data: any) => {
@ -192,6 +199,23 @@ export default function DashboardContainer() {
} }
}; };
const getTableNumberStats = (data: any) => {
if (data) {
let iterate = 0;
const newData = data
.filter(
(value: any) =>
value.userLevelName !== "SATWIL" && value.userLevelName !== "SATKER"
)
.map((value: any) => {
iterate++;
value.no = iterate;
return value;
});
return newData;
}
};
const getMonthYear = (date: any) => { const getMonthYear = (date: any) => {
return date.month + " " + date.year; return date.month + " " + date.year;
}; };
@ -218,6 +242,50 @@ export default function DashboardContainer() {
return month + " " + year; return month + " " + year;
}; };
useEffect(() => {
const temp = Array.from(selectedAccordion);
console.log("selecette", temp);
if (temp.length > 0) {
for (const element of temp) {
getPolresData(Number(element));
}
}
}, [postContentDate]);
const getPolresData = async (id: number) => {
const getDate = (data: any) => {
return `${data.year}-${data.month < 10 ? `0${data.month}` : data.month}-${
data.day < 10 ? `0${data.day}` : data.day
}`;
};
const res = await getUserLevelDataStat(
getDate(postContentDate.startDate),
getDate(postContentDate.endDate),
id
);
const polresNowData = getTableNumberStats(res?.data?.data);
setPolresData((prev: any) => ({
...prev,
[id]: polresNowData,
}));
};
const handleSelectionChange = (e: any) => {
const prev = selectedAccordion;
const current = e;
const currentArray = Array.from(current);
const added = Number(currentArray.filter((item) => !prev.has(item))[0]);
setSelectedAccordion(current);
if (added) {
getPolresData(added);
}
};
return ( return (
<div className="px-2 lg:p-8 flex justify-center"> <div className="px-2 lg:p-8 flex justify-center">
<div className="w-full flex flex-col gap-6"> <div className="w-full flex flex-col gap-6">
@ -335,7 +403,70 @@ export default function DashboardContainer() {
</div> </div>
</div> </div>
<div className="flex flex-col gap-1 lg:h-[500px] overflow-y-auto"> <div className="flex flex-col gap-1 lg:h-[500px] overflow-y-auto">
{roleId && Number(roleId) < 3 ? (
<Accordion
selectedKeys={selectedAccordion}
onSelectionChange={(e) => handleSelectionChange(e)}
selectionMode="multiple"
className="w-full"
>
{postCount?.map((list) => ( {postCount?.map((list) => (
<AccordionItem
key={list.userLevelId}
aria-label={list.userLevelName}
title={
<div
key={list.userLevelId}
className="flex flex-row gap-1 py-1"
>
<div className="w-[5%]">{list?.no}</div>
<div className="w-[85%]">{list?.userLevelName}</div>
<div
className={`w-[10%] text-center ${
list?.totalArticle === 0 &&
"bg-red-600 text-white"
}`}
>
{list?.totalArticle}
</div>
</div>
}
>
{polresData[list?.userLevelId] ? (
polresData[list?.userLevelId]?.map(
(child: any, index: number) => (
<div
key={child.userLevelId}
className={`flex flex-row gap-1 py-1 ${
index ===
polresData[list?.userLevelId].length - 1
? ""
: "border-b-1"
}`}
>
<div className="w-[5%]"></div>
<div className="w-[85%]">
{child?.userLevelName}
</div>
<div
className={`w-[10%] text-start ${
list?.totalArticle === 0 &&
"bg-red-600 text-white"
}`}
>
{child?.totalArticle}
</div>
</div>
)
)
) : (
<Skeleton className="h-3 w-full rounded-lg" />
)}
</AccordionItem>
))}
</Accordion>
) : (
postCount?.map((list) => (
<div <div
key={list.userLevelId} key={list.userLevelId}
className="flex flex-row border-b-1 gap-1 py-1" className="flex flex-row border-b-1 gap-1 py-1"
@ -350,7 +481,8 @@ export default function DashboardContainer() {
{list?.totalArticle} {list?.totalArticle}
</div> </div>
</div> </div>
))} ))
)}
</div> </div>
</div> </div>
<div className="flex flex-col w-full lg:w-[45%] gap-6 shadow-md bg-white dark:bg-[#18181b] rounded-lg p-8 text-sm"> <div className="flex flex-col w-full lg:w-[45%] gap-6 shadow-md bg-white dark:bg-[#18181b] rounded-lg p-8 text-sm">

View File

@ -2,10 +2,9 @@ import { PaginationRequest } from "@/types/globals";
import { httpGet, httpPost, httpPut } from "./http-config/axios-base-service"; import { httpGet, httpPost, httpPut } from "./http-config/axios-base-service";
import Cookies from "js-cookie"; import Cookies from "js-cookie";
import { stat } from "fs"; import { stat } from "fs";
import axiosInterceptorInstanceHumas from "./http-config/konten-humas-base-service";
import { import {
httpDeleteInterceptor,
httpGetInterceptor, httpGetInterceptor,
httpPostInterceptor,
} from "./http-config/http-interceptor-services"; } from "./http-config/http-interceptor-services";
const token = Cookies.get("access_token"); const token = Cookies.get("access_token");
@ -191,14 +190,16 @@ export async function deleteArticleFiles(id: number) {
export async function getUserLevelDataStat( export async function getUserLevelDataStat(
startDate: string, startDate: string,
endDate: string, endDate: string,
timeStamp: number levelId?: number
) { ) {
const headers = { // const headers = {
"content-type": "application/json", // "content-type": "application/json",
Authorization: `Bearer ${token}`, // Authorization: `Bearer ${token}`,
}; // };
return await httpGetInterceptor( return await httpGetInterceptor(
`/articles/statistic/user-levels?startDate=${startDate}&endDate=${endDate}&timeStamp=${timeStamp}` `/articles/statistic/user-levels?startDate=${startDate}&endDate=${endDate}&userLevelId=${
levelId || ""
}`
); );
} }
export async function getStatisticMonthly(year: string, timeStamp: number) { export async function getStatisticMonthly(year: string, timeStamp: number) {