From 8ecf1e7146acafa545cb6e616801e3794a175ad3 Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Mon, 21 Apr 2025 13:21:05 +0700 Subject: [PATCH] feat:landing stats --- components/landing/drawer.tsx | 36 ++++++++++++++++++++++++++++++++--- service/activity-log.ts | 6 ++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/components/landing/drawer.tsx b/components/landing/drawer.tsx index 4ae2fbd..a50318c 100644 --- a/components/landing/drawer.tsx +++ b/components/landing/drawer.tsx @@ -11,8 +11,38 @@ import { import { ChevronDownIcon, LandingAnalyticIcon, UserIcon } from "../icons"; import { MasterUsersIcon } from "../icons/sidebar-icon"; import Image from "next/image"; +import { useEffect, useState } from "react"; +import { getActivity } from "@/service/activity-log"; + +interface Activity { + totalVisitorAllTime: number; + totalVisitorToday: number; + totalViewAllTime: number; +} + export default function AnalyticDrawer() { const { isOpen, onOpen, onOpenChange } = useDisclosure(); + const [activity, setActivity] = useState({ + totalVisitorAllTime: 0, + totalVisitorToday: 0, + totalViewAllTime: 0, + }); + + useEffect(() => { + initFetch(); + }, []); + + const initFetch = async () => { + const res = await getActivity(); + if (res?.error) { + return false; + } + + setActivity(res?.data?.data); + console.log("ress", res); + + return false; + }; return ( <> @@ -82,11 +112,11 @@ export default function AnalyticDrawer() { />

- 199.295 + {activity.totalVisitorAllTime}

-

9 Online

+

{activity.totalVisitorToday} Online

@@ -106,7 +136,7 @@ export default function AnalyticDrawer() { />

- 1.199.295 + {activity.totalViewAllTime}

diff --git a/service/activity-log.ts b/service/activity-log.ts index 903a240..2056d6f 100644 --- a/service/activity-log.ts +++ b/service/activity-log.ts @@ -13,3 +13,9 @@ export async function saveActivity(data: any, token?: string) { const pathUrl = `/activity-logs`; return await httpPost(pathUrl, headers, data); } + +export async function getActivity() { + const headers = { "content-type": "application/json" }; + const pathUrl = `/activity-logs/statistics`; + return await httpGet(pathUrl, headers); +}