"use client" import { getDashboard, DashboardResp } from "@/api/admin" import { Card, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Eye, MessageCircle, Newspaper, Users } from "lucide-react" import { useEffect, useState } from "react" import { toast } from "sonner" import Link from "next/link" import { IconType } from "@/types/icon" import { consolePath } from "@/hooks/use-route" export function Dashboard() { return (
) } function DataOverview() { const data: { key: keyof DashboardResp; label: string; icon: IconType; url: string }[] = [ { key: "totalPosts", label: "Total Posts", icon: Newspaper, url: consolePath.post }, { key: "totalUsers", label: "Total Users", icon: Users, url: consolePath.user }, { key: "totalComments", label: "Total Comments", icon: MessageCircle, url: consolePath.comment }, { key: "totalViews", label: "Total Views", icon: Eye, url: consolePath.file }, ] const [fetchData, setFetchData] = useState(null); useEffect(() => { getDashboard().then(res => { setFetchData(res.data); }).catch(err => { toast.error(err.message || "Failed to fetch dashboard data"); }); }, []) if (!fetchData) return
Loading...
return
{data.map(item => ( {item.label} {fetchData[item.key]} ))}
}