"use client"; import { DashboardCommentIcon, DashboardConnectIcon, DashboardShareIcon, DashboardSpeecIcon, DashboardUserIcon, } from "@/components/icons/dashboard-icon"; import Cookies from "js-cookie"; import Link from "next/link"; import { useEffect, useState } from "react"; import { Article } from "@/types/globals"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { getListArticle, getStatisticSummary, getTopArticles, getUserLevelDataStat, } from "@/service/article"; import { Button } from "@/components/ui/button"; import Image from "next/image"; import { convertDateFormat, convertDateFormatNoTime, textEllipsis, } from "@/utils/global"; import DatePicker from "react-datepicker"; import "react-datepicker/dist/react-datepicker.css"; import { Checkbox } from "@/components/ui/checkbox"; import { Label } from "@/components/ui/label"; import { Calendar } from "@/components/ui/calendar"; import ApexChartColumn from "@/components/main/dashboard/chart/column-chart"; import CustomPagination from "@/components/layout/custom-pagination"; 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 [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 [startDateValue, setStartDateValue] = useState(new Date()); const [analyticsView, setAnalyticView] = useState([]); const options = [ { label: "Comment", value: "comment" }, { label: "View", value: "view" }, { label: "Share", value: "share" }, ]; const handleChange = (value: string, checked: boolean) => { if (checked) { setAnalyticView([...analyticsView, value]); } else { setAnalyticView(analyticsView.filter((v) => v !== value)); } }; const [postContentDate, setPostContentDate] = useState({ startDate: new Date(new Date().setDate(new Date().getDate() - 7)), endDate: new Date(), }); const [typeDate, setTypeDate] = useState("monthly"); const [summary, setSummary] = useState(); const [topPages, setTopPages] = useState([]); const [postCount, setPostCount] = useState([]); useEffect(() => { fetchSummary(); }, []); useEffect(() => { initState(); }, [page]); async function initState() { const req = { limit: "4", page: page, search: "", }; const res = await getListArticle(req); setArticle(res.data?.data); setTotalPage(res?.data?.meta?.totalPage); } async function fetchSummary() { const res = await getStatisticSummary(); setSummary(res?.data?.data); } useEffect(() => { fetchTopPages(); }, [page]); async function fetchTopPages() { const req = { limit: "10", page: page, search: "", }; 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) ); setPostCount(getTableNumber(10, res?.data?.data)); } const getTableNumber = (limit: number, data: any) => { if (data) { const startIndex = limit * (page - 1); let iterate = 0; const newData = data.map((value: any) => { iterate++; value.no = startIndex + 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; }; return (
{/*

Dashboard

Dashboard

*/}

{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)} { if (date) { setPostContentDate((prev) => ({ ...prev, startDate: date, })); } }} maxDate={postContentDate.endDate} inline /> - {convertDateFormatNoTime(postContentDate.endDate)} { if (date) { setPostContentDate((prev) => ({ ...prev, endDateDate: date, })); } }} maxDate={postContentDate.endDate} inline />
NO
POLDA/POLRES
JUMLAH POST BERITA
{postCount?.map((list) => (
{list?.no}
{list?.userLevelName}
{list?.totalArticle}
))}

Recent Article

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

{textEllipsis(list?.title, 78)}

{convertDateFormat(list?.createdAt)}

))}
{/* {Array.from({ length: totalPage }).map((_, i) => ( setPage(i + 1)}> {i + 1} ))} */} setPage(data)} />
Analytics
{/* Checkbox Group */}
{options.map((option) => (
handleChange(option.value, Boolean(checked)) } />
))}
{/* setStartDateValue(e)} inputClassName="z-50 w-full text-xs lg:text-sm bg-transparent border-1 border-gray-200 px-2 py-[6px] rounded-sm lg:rounded-lg h-[30px] lg:h-[40px] text-gray-600 dark:text-gray-300" /> */} { if (day) setStartDateValue(day); }} mode="single" className="rounded-md border" />{" "}

Top Pages

No
Title
Visits
{topPages?.map((list) => (
{list?.no}
{list?.title}
{list?.viewCount}
))}
{/* {Array.from({ length: totalPage }).map((_, i) => ( setPage(i + 1)}> {i + 1} ))} */} setPage(data)} />
); }