"use client"; import { DashboardCommentIcon, DashboardConnectIcon, DashboardShareIcon, DashboardSpeecIcon, DashboardTopLeftPointIcon, DashboardUserIcon, } from "@/components/icons/dashboard-icon"; import { Submenu1Icon } from "@/components/icons/sidebar-icon"; import { Accordion, AccordionItem, Button, Calendar, Checkbox, CheckboxGroup, Image, Pagination, Popover, PopoverContent, PopoverTrigger, Select, SelectItem, SelectSection, Skeleton, } from "@heroui/react"; import ApexChartColumn from "./chart/column-chart"; import ApexChartDonut from "./chart/donut-chart"; import ApexChartLineArea from "./chart/line-area-chart"; import Cookies from "js-cookie"; import Link from "next/link"; import { useEffect, useState } from "react"; import { getListArticle, getListArticleAdminPage, getStatisticSummary, getTopArticles, getUserLevelDataStat, } from "@/services/article"; import { Article } from "@/types/globals"; import { convertDateFormat, convertDateFormatNoTime, convertDateFormatNoTimeV2, getUnixTimestamp, textEllipsis, } from "@/utils/global"; import { parseDate, getLocalTimeZone } from "@internationalized/date"; type ArticleData = Article & { no: number; createdAt: string; }; interface TopPages { id: number; no: number; title: string; viewCount: number; } interface PostCount { userLevelId: number; no: number; userLevelName: string; totalArticle: number; } export default function DashboardContainer() { const username = Cookies.get("username"); const fullname = Cookies.get("ufne"); const [page, setPage] = useState(1); const [totalPage, setTotalPage] = useState(1); const [topPagespage, setTopPagesPage] = useState(1); const [topPagesTotalPage, setTopPagesTotalPage] = useState(1); const [article, setArticle] = useState([]); const [analyticsView, setAnalyticView] = useState([ "comment", "view", "share", ]); const [startDateValue, setStartDateValue] = useState( parseDate(convertDateFormatNoTimeV2(new Date())) ); const [postContentDate, setPostContentDate] = useState({ startDate: parseDate( convertDateFormatNoTimeV2( new Date(new Date().setDate(new Date().getDate() - 7)) ) ), endDate: parseDate(convertDateFormatNoTimeV2(new Date())), }); const [topContentDate, setTopContentDate] = useState({ startDate: parseDate( convertDateFormatNoTimeV2( new Date(new Date().setDate(new Date().getDate() - 7)) ) ), endDate: parseDate(convertDateFormatNoTimeV2(new Date())), }); const [typeDate, setTypeDate] = useState("monthly"); const [summary, setSummary] = useState(); const [topPages, setTopPages] = useState([]); const [postCount, setPostCount] = useState([]); const [polresData, setPolresData] = useState({}); const [selectedAccordion, setSelectedAccordion] = useState(new Set([])); const roleId = Cookies.get("urie"); useEffect(() => { fetchSummary(); }, []); useEffect(() => { initState(); }, [page]); async function initState() { const req = { limit: "4", page: page, search: "", sort: "desc", timeStamp: getUnixTimestamp(), }; const res = await getListArticleAdminPage(req); setArticle(res.data?.data); setTotalPage(res?.data?.meta?.totalPage); } async function fetchSummary() { const res = await getStatisticSummary(getUnixTimestamp()); setSummary(res?.data?.data); } useEffect(() => { fetchTopPages(); }, [topPagespage, topContentDate]); const getDate = (data: any) => { if (data === null) { return ""; } else { return `${data.year}-${data.month < 10 ? `0${data.month}` : data.month}-${ data.day < 10 ? `0${data.day}` : data.day }`; } }; async function fetchTopPages() { const req = { limit: "10", page: topPagespage, search: "", sort: "desc", isPublish: true, timeStamp: getUnixTimestamp(), startDate: getDate(topContentDate.startDate), endDate: getDate(topContentDate.endDate), }; const res = await getTopArticles(req); setTopPages(getTableNumber(10, res.data?.data)); setTopPagesTotalPage(res?.data?.meta?.totalPage); } useEffect(() => { fetchPostCount(); }, [postContentDate]); async function fetchPostCount() { 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), getUnixTimestamp() ); setPostCount(getTableNumberStats(res?.data?.data)); } const getTableNumber = (limit: number, data: any) => { if (data) { const startIndex = limit * (topPagespage - 1); let iterate = 0; const newData = data.map((value: any) => { iterate++; value.no = startIndex + iterate; return value; }); return newData; } }; 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) => { return date.month + " " + date.year; }; const getMonthYearName = (date: any) => { const newDate = new Date(date); const months = [ "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember", ]; const year = newDate.getFullYear(); const month = months[newDate.getMonth()]; 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 (

{fullname}

{username}

{summary?.totalToday} Post{" "} Hari ini

{summary?.totalThisWeek} Post{" "} Minggu ini

Total post
{summary?.totalAll}
Total views
{summary?.totalViews}
Total share
{summary?.totalShares}
Total comment
{summary?.totalComments}

Rekapitulasi Post Berita Polda/Polres Pada Website

{convertDateFormatNoTime(postContentDate.startDate)} setPostContentDate({ startDate: e, endDate: postContentDate.endDate, }) } maxValue={postContentDate.endDate} /> - {convertDateFormatNoTime(postContentDate.endDate)} setPostContentDate({ startDate: postContentDate.startDate, endDate: e, }) } minValue={postContentDate.startDate} />
NO
POLDA/POLRES
JUMLAH POST BERITA
{roleId && Number(roleId) < 3 ? ( handleSelectionChange(e)} selectionMode="multiple" className="w-full" > {postCount?.map((list) => (
{list?.no}
{list?.userLevelName}
{list?.totalArticle}
} > {polresData[list?.userLevelId] ? ( polresData[list?.userLevelId]?.map( (child: any, index: number) => (
{child?.userLevelName}
{child?.totalArticle}
) ) ) : ( )} ))} ) : ( postCount?.map((list) => (
{list?.no}
{list?.userLevelName}
{list?.totalArticle}
)) )}

Recent Article

{article?.map((list: any) => (
thumbnail

{textEllipsis(list?.title, 78)}

{convertDateFormat(list?.createdAt)}

))}
setPage(page)} />
Analytics
Comment View Share Comment View Share

Top Pages

{convertDateFormatNoTime(topContentDate.startDate)} setTopContentDate({ startDate: e, endDate: topContentDate.endDate, }) } maxValue={topContentDate.endDate} /> - {convertDateFormatNoTime(topContentDate.endDate)} setTopContentDate({ startDate: topContentDate.startDate, endDate: e, }) } minValue={topContentDate.startDate} />
No
Title
Visits
{(!topPages || topPages?.length < 1) && (
Tidak ada Data
)} {topPages?.map((list) => (
{list?.no}
{list?.title}
{list?.viewCount}
))} {topPages?.length > 0 && (
setTopPagesPage(page)} />
)}
); }