web-humas-fe/components/landing/drawer.tsx

149 lines
4.9 KiB
TypeScript
Raw Normal View History

2025-03-14 08:45:40 +00:00
"use client";
2025-02-26 08:34:45 +00:00
import { Button } from "@heroui/button";
2025-04-17 13:04:04 +00:00
2025-02-26 08:34:45 +00:00
import {
Drawer,
2025-04-17 13:04:04 +00:00
DrawerBody,
2025-02-26 08:34:45 +00:00
DrawerContent,
DrawerHeader,
2025-04-17 13:04:04 +00:00
useDisclosure,
} from "@heroui/react";
2025-02-26 08:34:45 +00:00
import { ChevronDownIcon, LandingAnalyticIcon, UserIcon } from "../icons";
import { MasterUsersIcon } from "../icons/sidebar-icon";
import Image from "next/image";
2025-04-21 06:21:05 +00:00
import { useEffect, useState } from "react";
2025-05-04 07:14:12 +00:00
import { getActivity } from "@/services/activity-log";
2025-04-21 06:21:05 +00:00
interface Activity {
totalVisitorAllTime: number;
totalVisitorToday: number;
totalViewAllTime: number;
}
2025-02-26 08:34:45 +00:00
export default function AnalyticDrawer() {
const { isOpen, onOpen, onOpenChange } = useDisclosure();
2025-04-21 06:21:05 +00:00
const [activity, setActivity] = useState<Activity>({
totalVisitorAllTime: 0,
totalVisitorToday: 0,
totalViewAllTime: 0,
});
useEffect(() => {
initFetch();
}, []);
const initFetch = async () => {
const res = await getActivity();
if (res?.error) {
return false;
}
setActivity(res?.data?.data);
return false;
};
2025-02-26 08:34:45 +00:00
return (
<>
<div className="fixed bottom-1/3 -translate-y-1/2 right-4 lg:right-9 z-50">
<Button
2025-03-11 10:19:37 +00:00
className="lg:hidden rotate-90 origin-right rounded-b-md rounded-t-none flex flex-row items-center gap-2 text-white bg-red-600 font-semibold"
onPress={onOpen}
size="sm"
>
<div className="bg-red-950 p-1 rounded-full">
<ChevronDownIcon size={12} />
</div>{" "}
Statistik Kunjungan
</Button>
<Button
className="hidden lg:flex rotate-90 origin-right rounded-b-md rounded-t-none flex-row items-center gap-2 text-white bg-red-600 font-semibold"
2025-02-26 08:34:45 +00:00
onPress={onOpen}
>
<div className="bg-red-950 p-1 rounded-full">
<ChevronDownIcon size={12} />
</div>{" "}
Statistik Kunjungan
</Button>
</div>
<Drawer
isOpen={isOpen}
onOpenChange={onOpenChange}
motionProps={{
variants: {
enter: {
opacity: 1,
x: 0,
},
exit: {
x: 100,
opacity: 0,
},
},
}}
className="h-[540px] bg-[#BE0106] text-white"
size="sm"
>
<DrawerContent>
{(onClose) => (
<>
<DrawerHeader className="flex flex-col gap-1 ">
<p className="text-xl font-semibold"> Statistik Kunjungan</p>
<p className="text-sm font-light">
Perhitungan jumlah kunjugan website
</p>
</DrawerHeader>
<DrawerBody className="flex flex-col gap-3">
<div className="flex flex-col gap-3 pl-10 pr-4 py-4 bg-[#671B1D] rounded-lg">
<div className="flex justify-between items-center">
<div className="flex flex-col gap-2">
<div className="bg-[#BE0106] rounded-md w-fit py-1 px-1.5">
<MasterUsersIcon size={14} />
</div>
<p className="font-light">Total visitor</p>
</div>
<Image
src="/tribrata.png"
width={360}
height={360}
alt="logo"
className="w-[80px] opacity-30"
/>
</div>
<p className="text-5xl font-semibold leading-0 tracking-wide">
2025-04-21 06:21:05 +00:00
{activity.totalVisitorAllTime}
2025-02-26 08:34:45 +00:00
</p>
<div className="flex flex-row gap-3 bg-[#BE0106] py-1 px-2 rounded-md items-center w-fit text-sm font-light">
<div className="w-2 h-2 bg-success-600 rounded-full"></div>
2025-04-21 06:21:05 +00:00
<p>{activity.totalVisitorToday} Online</p>
2025-02-26 08:34:45 +00:00
</div>
</div>
<div className="flex flex-col gap-3 pl-10 pr-4 pt-4 pb-10 bg-[#671B1D] rounded-lg">
<div className="flex justify-between items-center">
<div className="flex flex-col gap-2">
<div className="bg-[#BE0106] rounded-md w-fit py-1 px-1.5">
<LandingAnalyticIcon size={14} />
</div>
<p className="font-light">Total View</p>
</div>
<Image
src="/tribrata.png"
width={360}
height={360}
alt="logo"
className="w-[80px] opacity-30"
/>
</div>
<p className="text-5xl font-semibold leading-0 tracking-wide">
2025-04-21 06:21:05 +00:00
{activity.totalViewAllTime}
2025-02-26 08:34:45 +00:00
</p>
</div>
</DrawerBody>
</>
)}
</DrawerContent>
</Drawer>
</>
);
}