From c61e7d0adb16f4f069c194539819f362b3cd602c Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Wed, 18 Jun 2025 09:32:56 +0700 Subject: [PATCH] fix:dashboard recap --- components/form/login.tsx | 2 +- components/landing/HeaderNews.tsx | 2 +- .../main/dashboard/dashboard-container.tsx | 44 ++++++++++++------- services/article.ts | 9 ++++ 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/components/form/login.tsx b/components/form/login.tsx index 7c22aee..d4d792f 100644 --- a/components/form/login.tsx +++ b/components/form/login.tsx @@ -93,7 +93,7 @@ export default function Login() { } // login tanpa otp - loading(); + // loading(); // const response = await postSignIn(data); // if (response?.error) { // error("Username / Password Tidak Sesuai"); diff --git a/components/landing/HeaderNews.tsx b/components/landing/HeaderNews.tsx index 141f9fd..6cc1948 100644 --- a/components/landing/HeaderNews.tsx +++ b/components/landing/HeaderNews.tsx @@ -292,7 +292,7 @@ export default function HeaderNews() { src={ newsItem?.thumbnailUrl === "" ? "/no-image.jpg" - : newsItem?.thumbnailUrl + : newsItem?.thumbnailUrl + "?isBanner=true" } className={`!object-cover !rounded-none ${ portraitMap[index] diff --git a/components/main/dashboard/dashboard-container.tsx b/components/main/dashboard/dashboard-container.tsx index 0d689b1..3d9376f 100644 --- a/components/main/dashboard/dashboard-container.tsx +++ b/components/main/dashboard/dashboard-container.tsx @@ -41,6 +41,7 @@ import { Fragment, useEffect, useState } from "react"; import { getListArticle, getListArticleAdminPage, + getRecapArticleData, getStatisticSummary, getTopArticles, getUserLevelDataStat, @@ -128,7 +129,10 @@ export default function DashboardContainer() { const [polresData, setPolresData] = useState({}); const [selectedAccordion, setSelectedAccordion] = useState(new Set([])); const [recapArticleList, setRecapArticleList] = useState([]); - const [selectedUnit, setSelectedUnit] = useState(""); + const [selectedUnit, setSelectedUnit] = useState<{ + id: number; + name: string; + }>(); const roleId = Cookies.get("urie"); const [recapArticlePage, setRecapArticlePage] = useState(1); @@ -328,23 +332,27 @@ export default function DashboardContainer() { getRecapArticle(); }, [recapArticlePage]); - const getRecapArticle = async () => { + const getRecapArticle = async (userLevelId?: number) => { const req = { - limit: `10`, + id: userLevelId || selectedUnit?.id, page: recapArticlePage, - search: "", - sort: "desc", - startDate: getDate(topContentDate.startDate), - endDate: getDate(topContentDate.endDate), + 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 getTopArticles(req); + const res = await getRecapArticleData(req); setRecapArticleList(getTableNumber(10, res.data?.data, "recapArticle")); setRecapArticleTotalPage(res?.data?.meta?.totalPage); }; - const openModalArticle = async () => { + const openModalArticle = async (userLevelId: number) => { setRecapArticlePage(1); - getRecapArticle(); + getRecapArticle(userLevelId); onOpen(); }; @@ -509,8 +517,11 @@ export default function DashboardContainer() { { if (list?.totalArticle !== 0) { - setSelectedUnit(child?.userLevelName); - openModalArticle(); + setSelectedUnit({ + name: child?.userLevelName, + id: child.userLevelId, + }); + openModalArticle(child.userLevelId); } }} className={`w-[10%] text-start cursor-pointer flex flex-row gap-1 items-center justify-end ${ @@ -546,8 +557,11 @@ export default function DashboardContainer() { { if (list?.totalArticle !== 0) { - setSelectedUnit(list?.userLevelName); - openModalArticle(); + setSelectedUnit({ + name: list?.userLevelName, + id: list.userLevelId, + }); + openModalArticle(list.userLevelId); } }} className={`w-[10%] text-start cursor-pointer flex flex-row gap-1 items-center justify-end ${ @@ -794,7 +808,7 @@ export default function DashboardContainer() { {(onClose) => ( <> - {selectedUnit} List Content + {selectedUnit?.name} List Content
diff --git a/services/article.ts b/services/article.ts index db5c71d..5bac455 100644 --- a/services/article.ts +++ b/services/article.ts @@ -129,6 +129,15 @@ export async function getArticleById(id: any) { }; return await httpGet(`/articles/${id}`, headers); } +export async function getRecapArticleData(data: any) { + const headers = { + "content-type": "application/json", + }; + return await httpGet( + `/articles?page=${data.page}&userLevelId=${data.id}&startDate=${data.startDate}&endDate=${data.endDate}&startTime=${data.startTime}&endTime=${data.endTime}`, + headers + ); +} // export async function deleteArticle(id: string) { // const headers = {