From f0bd7e251327cd837eb5fd801ca9018e2cae0113 Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Tue, 17 Jun 2025 18:44:26 +0700 Subject: [PATCH 1/3] fix:comment article, dashboard recap data --- .../admin/comment/review/[id]/page.tsx | 3 + .../main/dashboard/dashboard-container.tsx | 320 ++++++++++-------- components/main/detail/comment.tsx | 2 + services/article.ts | 4 +- 4 files changed, 183 insertions(+), 146 deletions(-) diff --git a/app/(admin)/admin/comment/review/[id]/page.tsx b/app/(admin)/admin/comment/review/[id]/page.tsx index 62adf39..beea333 100644 --- a/app/(admin)/admin/comment/review/[id]/page.tsx +++ b/app/(admin)/admin/comment/review/[id]/page.tsx @@ -21,6 +21,7 @@ import { import { getArticleById } from "@/services/article"; import Link from "next/link"; import { postArticleComment } from "@/services/master-user"; +import Cookies from "js-cookie"; interface DetailComments { id: number; @@ -98,6 +99,8 @@ export default function ReviewComment() { const sendComment = async () => { const data = { + commentFromEmail: "ppid@polri.go.id", + commentFromName: "Mabes Polri", articleId: detailData?.articleId, isPublic: true, message: replyValue, diff --git a/components/main/dashboard/dashboard-container.tsx b/components/main/dashboard/dashboard-container.tsx index 7cf43fc..857140e 100644 --- a/components/main/dashboard/dashboard-container.tsx +++ b/components/main/dashboard/dashboard-container.tsx @@ -16,6 +16,7 @@ import { Checkbox, CheckboxGroup, CheckboxIcon, + DateRangePicker, Image, Modal, ModalBody, @@ -51,8 +52,14 @@ import { convertDateFormatNoTimeV2, textEllipsis, } from "@/utils/global"; -import { parseDate, getLocalTimeZone } from "@internationalized/date"; +import { + parseDate, + getLocalTimeZone, + parseZonedDateTime, + parseAbsoluteToLocal, +} from "@internationalized/date"; import { Input } from "@heroui/input"; +import { EyeIconMdi } from "@/components/icons"; type ArticleData = Article & { no: number; @@ -94,12 +101,14 @@ export default function DashboardContainer() { ); const [postContentDate, setPostContentDate] = useState({ - startDate: parseDate( - convertDateFormatNoTimeV2( + 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]` ), - endDate: parseDate(convertDateFormatNoTimeV2(new Date())), }); const [topContentDate, setTopContentDate] = useState({ @@ -119,10 +128,12 @@ export default function DashboardContainer() { const [polresData, setPolresData] = useState({}); const [selectedAccordion, setSelectedAccordion] = useState(new Set([])); const [recapArticleList, setRecapArticleList] = useState([]); - const [timeValue, setTimeValue] = useState("--:--"); const [selectedUnit, setSelectedUnit] = useState(""); const roleId = Cookies.get("urie"); + const [recapArticlePage, setRecapArticlePage] = useState(1); + const [recapArticleTotalPage, setRecapArticleTotalPage] = useState(1); + useEffect(() => { fetchSummary(); }, []); @@ -172,7 +183,7 @@ export default function DashboardContainer() { endDate: getDate(topContentDate.endDate), }; const res = await getTopArticles(req); - setTopPages(getTableNumber(10, res.data?.data)); + setTopPages(getTableNumber(10, res.data?.data, "topPages")); setTopPagesTotalPage(res?.data?.meta?.totalPage); } @@ -187,15 +198,22 @@ export default function DashboardContainer() { }`; }; const res = await getUserLevelDataStat( - getDate(postContentDate.startDate), - getDate(postContentDate.endDate) + getDate(postContentDate.start), + getDate(postContentDate.end), + `${getTime(postContentDate.start.hour)}:${getTime( + postContentDate.start.minute + )}:00`, + `${getTime(postContentDate.end.hour)}:${getTime( + postContentDate.end.minute + )}:00` ); setPostCount(getTableNumberStats(res?.data?.data)); } - const getTableNumber = (limit: number, data: any) => { + const getTableNumber = (limit: number, data: any, type: string) => { if (data) { - const startIndex = limit * (topPagespage - 1); + const startIndex = + limit * (type == "topPages" ? topPagespage - 1 : recapArticlePage - 1); let iterate = 0; const newData = data.map((value: any) => { iterate++; @@ -259,15 +277,26 @@ export default function DashboardContainer() { } }, [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.startDate), - getDate(postContentDate.endDate), + 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); @@ -293,18 +322,27 @@ export default function DashboardContainer() { } }; - const openModalArticle = async (limit: number) => { + useEffect(() => { + getRecapArticle(); + }, [recapArticlePage]); + + const getRecapArticle = async () => { const req = { - limit: `${limit}`, - page: topPagespage, + limit: `10`, + page: recapArticlePage, search: "", sort: "desc", startDate: getDate(topContentDate.startDate), endDate: getDate(topContentDate.endDate), }; const res = await getTopArticles(req); - setRecapArticleList(getTableNumber(10, res.data?.data)); - // setTopPagesTotalPage(res?.data?.meta?.totalPage); + setRecapArticleList(getTableNumber(10, res.data?.data, "recapArticle")); + setRecapArticleTotalPage(res?.data?.meta?.totalPage); + }; + + const openModalArticle = async () => { + setRecapArticlePage(1); + getRecapArticle(); onOpen(); }; @@ -365,75 +403,28 @@ export default function DashboardContainer() {
-
-

+

+

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} - /> - - - - - - } - classNames={{ - inputWrapper: [ - "border-none rounded-lg !h-[30px] lg:h-[40px]", - "dark:group-data-[focused=false]:bg-transparent border-none", - ], - }} - /> -
+ { + 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" + />
NO
@@ -469,73 +460,93 @@ export default function DashboardContainer() {
{roleId && Number(roleId) < 3 ? ( - handleSelectionChange(e)} - selectionMode="multiple" - className="w-full" - > - {postCount?.map((list) => ( - -
{list?.no}
-
{list?.userLevelName}
+ selectedCategory === "polda" ? ( + handleSelectionChange(e)} + selectionMode="multiple" + className="w-full" + > + {postCount?.map((list) => ( + - {list?.totalArticle} -
-
- } - > - {polresData[list?.userLevelId] ? ( - polresData[list?.userLevelId]?.map( - (child: any, index: number) => ( +
{list?.no}
+
{list?.userLevelName}
+
+ } + > + {polresData[list?.userLevelId] ? ( + polresData[list?.userLevelId]?.map( + (child: any, index: number) => ( + +
+
+ {child?.userLevelName} +
+ { + if (list?.totalArticle !== 0) { + setSelectedUnit(child?.userLevelName); + openModalArticle(); + } + }} + className={`w-[10%] text-start cursor-pointer flex flex-row gap-1 items-center justify-end ${ + list?.totalArticle === 0 && + "bg-red-600 text-white cursor-default " + }`} + > + {child?.totalArticle} + + +
+ ) ) - ) - ) : ( - - )} - - ))} - + ) : ( + + )} + + ))} + + ) : ( + + ) ) : ( postCount?.map((list) => (
{selectedUnit} List Content - +
No
Judul
@@ -814,6 +825,25 @@ export default function DashboardContainer() { ))}
+ {recapArticleList?.length > 0 && ( +
+ setRecapArticlePage(page)} + /> +
+ )} )} diff --git a/components/main/detail/comment.tsx b/components/main/detail/comment.tsx index d475ea3..23a0007 100644 --- a/components/main/detail/comment.tsx +++ b/components/main/detail/comment.tsx @@ -91,6 +91,8 @@ export default function Comment(props: { id: string | null }) { } const data = { + commentFromName: values.name, + commentFromEmail: values.email, articleId: Number(id), isPublic: false, message: values.comment, diff --git a/services/article.ts b/services/article.ts index a1bd358..3d71e8a 100644 --- a/services/article.ts +++ b/services/article.ts @@ -191,6 +191,8 @@ export async function deleteArticleFiles(id: number) { export async function getUserLevelDataStat( startDate: string, endDate: string, + startTime: string, + endTime: string, levelId?: number ) { // const headers = { @@ -198,7 +200,7 @@ export async function getUserLevelDataStat( // Authorization: `Bearer ${token}`, // }; return await httpGetInterceptor( - `/articles/statistic/user-levels?startDate=${startDate}&endDate=${endDate}&userLevelId=${ + `/articles/statistic/user-levels?startDate=${startDate}&endDate=${endDate}&startTime=${startTime}&endTime=${endTime}&userLevelId=${ levelId || "" }` ); From 77178d87fe50a84e09720df1bf379c7a6a0c448c Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Tue, 17 Jun 2025 23:55:17 +0700 Subject: [PATCH 2/3] fix:dashboard filter --- components/form/login.tsx | 2 +- .../main/dashboard/dashboard-container.tsx | 165 +++++++++--------- services/article.ts | 3 +- 3 files changed, 84 insertions(+), 86 deletions(-) diff --git a/components/form/login.tsx b/components/form/login.tsx index d4d792f..7c22aee 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/main/dashboard/dashboard-container.tsx b/components/main/dashboard/dashboard-container.tsx index 857140e..0d689b1 100644 --- a/components/main/dashboard/dashboard-container.tsx +++ b/components/main/dashboard/dashboard-container.tsx @@ -189,7 +189,7 @@ export default function DashboardContainer() { useEffect(() => { fetchPostCount(); - }, [postContentDate]); + }, [postContentDate, selectedCategory]); async function fetchPostCount() { const getDate = (data: any) => { @@ -205,7 +205,8 @@ export default function DashboardContainer() { )}:00`, `${getTime(postContentDate.end.hour)}:${getTime( postContentDate.end.minute - )}:00` + )}:00`, + selectedCategory === "polda" ? "" : selectedCategory ); setPostCount(getTableNumberStats(res?.data?.data)); } @@ -294,9 +295,10 @@ export default function DashboardContainer() { `${getTime(postContentDate.start.hour)}:${getTime( postContentDate.start.minute )}:00`, - `${getTime(postContentDate.end.hour)}-${getTime( + `${getTime(postContentDate.end.hour)}:${getTime( postContentDate.end.minute )}:00`, + "", id ); const polresNowData = getTableNumberStats(res?.data?.data); @@ -459,94 +461,75 @@ export default function DashboardContainer() {
- {roleId && Number(roleId) < 3 ? ( - selectedCategory === "polda" ? ( - handleSelectionChange(e)} - selectionMode="multiple" - className="w-full" - > - {postCount?.map((list) => ( - handleSelectionChange(e)} + selectionMode="multiple" + className="w-full" + > + {postCount?.map((list) => ( + +
{list?.no}
+
{list?.userLevelName}
-
{list?.no}
-
{list?.userLevelName}
+ {list?.totalArticle} +
+
+ } + > + {polresData[list?.userLevelId] ? ( + polresData[list?.userLevelId]?.map( + (child: any, index: number) => (
- {list?.totalArticle} -
- - } - > - {polresData[list?.userLevelId] ? ( - polresData[list?.userLevelId]?.map( - (child: any, index: number) => ( -
+
+ {child?.userLevelName} +
+ { + if (list?.totalArticle !== 0) { + setSelectedUnit(child?.userLevelName); + openModalArticle(); + } + }} + className={`w-[10%] text-start cursor-pointer flex flex-row gap-1 items-center justify-end ${ + list?.totalArticle === 0 && + "bg-red-600 text-white cursor-default " }`} > -
-
- {child?.userLevelName} -
-
{ - if (list?.totalArticle !== 0) { - setSelectedUnit(child?.userLevelName); - openModalArticle(); - } - }} - className={`w-[10%] text-start cursor-pointer flex flex-row gap-1 items-center justify-end ${ - list?.totalArticle === 0 && - "bg-red-600 text-white cursor-default " - }`} - > - {child?.totalArticle} - - - - ) + {child?.totalArticle} + + + ) - ) : ( - - )} - - ))} - - ) : ( - - ) + ) + ) : ( + + )} + + ))} + ) : ( postCount?.map((list) => ( )) diff --git a/services/article.ts b/services/article.ts index 3d71e8a..db5c71d 100644 --- a/services/article.ts +++ b/services/article.ts @@ -193,6 +193,7 @@ export async function getUserLevelDataStat( endDate: string, startTime: string, endTime: string, + levelType: string, levelId?: number ) { // const headers = { @@ -200,7 +201,7 @@ export async function getUserLevelDataStat( // Authorization: `Bearer ${token}`, // }; return await httpGetInterceptor( - `/articles/statistic/user-levels?startDate=${startDate}&endDate=${endDate}&startTime=${startTime}&endTime=${endTime}&userLevelId=${ + `/articles/statistic/user-levels?startDate=${startDate}&endDate=${endDate}&startTime=${startTime}&endTime=${endTime}&levelType=${levelType}&userLevelId=${ levelId || "" }` ); From c61e7d0adb16f4f069c194539819f362b3cd602c Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Wed, 18 Jun 2025 09:32:56 +0700 Subject: [PATCH 3/3] 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 = {