"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, CheckboxIcon, DateRangePicker, Image, Modal, ModalBody, ModalContent, ModalHeader, Pagination, Popover, PopoverContent, PopoverTrigger, Select, SelectItem, SelectSection, Skeleton, useDisclosure, } 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 { Fragment, useEffect, useState } from "react"; import { getListArticle, getListArticleAdminPage, getRecapArticleData, getStatisticSummary, getTopArticles, getUserLevelDataStat, } from "@/services/article"; import { Article } from "@/types/globals"; import { convertDateFormat, convertDateFormatNoTime, convertDateFormatNoTimeV2, textEllipsis, } from "@/utils/global"; import { parseDate, getLocalTimeZone, parseZonedDateTime, parseAbsoluteToLocal, } from "@internationalized/date"; import { Input } from "@heroui/input"; import { ChevronLeftIcon, ChevronRightIcon, EyeIconMdi, SearchIcons, } from "@/components/icons"; import { format } from "date-fns"; import ApexChartColumnVisitors from "./chart/visitor-chart"; import { IndonesiaMap } from "@/components/ui/maps-charts"; type ArticleData = Article & { no: number; createdAt: string; }; interface TopPages { id: number; no: number; title: string; viewCount: number; } const colors = [ "#38bdf8", "#155e75", "#0e7490", "#0284c7", "#0ea5e9", "#38bdf8", "#7dd3fc", ]; interface PostCount { userLevelId: number; no: number; userLevelName: string; totalArticle: number; } const months = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ]; const dummyData = [ { name: "DI. ACEH", value: 10, id: 1 }, { name: "SUMATERA UTARA", value: 20, id: 2 }, { name: "DKI JAKARTA", value: 100, id: 3 }, { name: "JAWA BARAT", value: 30, id: 4 }, { name: "IRIAN JAYA TIMUR", value: 20, id: 5 }, ]; const getTotalData: number[] = []; dummyData.map((list) => { getTotalData.push(list.value); }); export default function DashboardContainer() { const { isOpen, onOpen, onOpenChange } = useDisclosure(); 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 [selectedCategory, setSelectedCategory] = useState("polda"); const [analyticsView, setAnalyticView] = useState([ "comment", "view", "share", ]); const [startDateValue, setStartDateValue] = useState( parseDate(convertDateFormatNoTimeV2(new Date())) ); const [postContentDate, setPostContentDate] = useState({ start: parseZonedDateTime( `${convertDateFormatNoTimeV2( new Date(new Date().setDate(new Date().getDate() - 7)) )}T00:00[Asia/Jakarta]` ), end: parseZonedDateTime( `${convertDateFormatNoTimeV2(new Date())}T23:59[Asia/Jakarta]` ), }); const [topContentDate, setTopContentDate] = useState({ startDate: parseDate( convertDateFormatNoTimeV2( new Date(new Date().setDate(new Date().getDate() - 7)) ) ), endDate: parseDate(convertDateFormatNoTimeV2(new Date())), }); const [summary, setSummary] = useState(); const [topPages, setTopPages] = useState([]); const [postCount, setPostCount] = useState([]); const [polresData, setPolresData] = useState({}); const [selectedAccordion, setSelectedAccordion] = useState(new Set([])); const [recapArticleList, setRecapArticleList] = useState([]); const [selectedUnit, setSelectedUnit] = useState<{ id: number; name: string; }>(); const roleId = Cookies.get("urie"); const today = new Date(); const [recapArticlePage, setRecapArticlePage] = useState(1); const [recapArticleTotalPage, setRecapArticleTotalPage] = useState(1); const [typeDate, setTypeDate] = useState("daily"); const [year, setYear] = useState(today.getFullYear()); const [selectedMonth, setSelectedMonth] = useState(today); const [viewsDailyDate, setViewsDailyDate] = useState({ start: parseDate(convertDateFormatNoTimeV2(today)), end: parseDate(convertDateFormatNoTimeV2(today)), }); const [typeDateVisitor, setTypeDateVisitor] = useState("daily"); const [visitorYear, setVisitorYear] = useState(today.getFullYear()); const [visitorSelectedMonth, setVisitorSelectedMonth] = useState( today ); const [visitorDailyDate, setVisitorDailyDate] = useState({ start: parseDate(convertDateFormatNoTimeV2(today)), end: parseDate(convertDateFormatNoTimeV2(today)), }); const handleMonthClick = (monthIndex: number) => { setSelectedMonth(new Date(year, monthIndex, 1)); }; const handleMonthClickVisitor = (monthIndex: number) => { setVisitorSelectedMonth(new Date(year, monthIndex, 1)); }; useEffect(() => { fetchSummary(); }, []); useEffect(() => { initState(); }, [page]); async function initState() { const req = { limit: "4", page: page, search: "", sort: "desc", }; const res = await getListArticleAdminPage(req); setArticle(res.data?.data); setTotalPage(res?.data?.meta?.totalPage); } async function fetchSummary() { const res = await getStatisticSummary(); 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", startDate: getDate(topContentDate.startDate), endDate: getDate(topContentDate.endDate), }; const res = await getTopArticles(req); setTopPages(getTableNumber(10, res.data?.data, "topPages")); setTopPagesTotalPage(res?.data?.meta?.totalPage); } useEffect(() => { fetchPostCount(); }, [selectedCategory]); 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.start), getDate(postContentDate.end), `${getTime(postContentDate.start.hour)}:${getTime( postContentDate.start.minute )}:00`, `${getTime(postContentDate.end.hour)}:${getTime( postContentDate.end.minute )}:00`, selectedCategory === "polda" ? "" : selectedCategory ); setPostCount(getTableNumberStats(res?.data?.data)); } const getTableNumber = (limit: number, data: any, type: string) => { if (data) { const startIndex = limit * (type == "topPages" ? topPagespage - 1 : recapArticlePage - 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; } }; useEffect(() => { const temp = Array.from(selectedAccordion); console.log("selecette", temp); if (temp.length > 0) { for (const element of temp) { getPolresData(Number(element)); } } }, [postContentDate]); const getTime = (time: number) => { return time < 10 ? `0${time}` : String(time); }; 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.start), getDate(postContentDate.end), `${getTime(postContentDate.start.hour)}:${getTime( postContentDate.start.minute )}:00`, `${getTime(postContentDate.end.hour)}:${getTime( postContentDate.end.minute )}:00`, "", 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); } }; useEffect(() => { getRecapArticle(); }, [recapArticlePage]); const getRecapArticle = async (userLevelId?: number) => { const req = { id: userLevelId || selectedUnit?.id, page: recapArticlePage, startDate: getDate(postContentDate.start), endDate: getDate(postContentDate.end), startTime: `${getTime(postContentDate.start.hour)}:${getTime( postContentDate.start.minute )}:00`, endTime: `${getTime(postContentDate.end.hour)}:${getTime( postContentDate.end.minute )}:00`, }; const res = await getRecapArticleData(req); setRecapArticleList(getTableNumber(10, res.data?.data, "recapArticle")); setRecapArticleTotalPage(res?.data?.meta?.totalPage); }; const openModalArticle = async (userLevelId: number) => { setRecapArticlePage(1); getRecapArticle(userLevelId); onOpen(); }; 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

{ e && setPostContentDate(e); }} label="Tanggal dan Waktu" visibleMonths={2} hourCycle={24} className="w-fit text-sm self-end" classNames={{ timeInputLabel: "text-xs", innerWrapper: "text-xs", inputWrapper: "border-1", }} size="sm" variant="bordered" endContent={ fetchPostCount()} > } />
NO
{Number(roleId) < 3 ? ( ) : ( "POLDA/POLRES" )}
JUMLAH POST BERITA
{roleId && Number(roleId) < 3 && selectedCategory == "polda" ? ( 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) => ( ) ) ) : ( )} ))} ) : ( postCount?.map((list) => ( )) )}

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)} />
)}
Engagement Analytics
Comment View Share Comment View Share
{typeDate === "monthly" ? (
{year}
{months.map((month, idx) => ( ))}
) : (
e !== null && setViewsDailyDate(e)} label="" />
)}
Visitor Analytics
{typeDateVisitor === "monthly" ? (
{year}
{months.map((month, idx) => ( ))}
) : (
e !== null && setViewsDailyDate(e)} label="" />
)}
{roleId && Number(roleId) < 3 && (
{dummyData.map((list) => (

{list.name}

{" "}

{list.value}

))}
)}
{(onClose) => ( <> {selectedUnit?.name} List Content
No
Judul
Dibuat
{recapArticleList?.length > 0 && recapArticleList?.map((list: any) => (
{list.no}
{textEllipsis(list.title, 80)}
{convertDateFormat(list?.createdAt)}
))}
{recapArticleList?.length > 0 && (
setRecapArticlePage(page)} />
)}
)}
); }