import { useQuery } from "@tanstack/react-query"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import { useAuth } from "@/hooks/useAuth"; import { useEffect } from "react"; import { useToast } from "@/hooks/use-toast"; import { isUnauthorizedError } from "@/lib/authUtils"; export default function AdminDashboard() { const { user, isLoading } = useAuth(); const { toast } = useToast(); // Redirect if not authenticated or not admin useEffect(() => { if (!isLoading && (!user || user.role !== 'admin')) { toast({ title: "Unauthorized", description: "You don't have permission to access this page.", variant: "destructive", }); setTimeout(() => { window.location.href = "/"; }, 500); } }, [isLoading, user, toast]); const { data: analytics, isLoading: analyticsLoading, error: analyticsError } = useQuery({ queryKey: ["/api/analytics"], retry: false, }); // Handle analytics errors useEffect(() => { if (analyticsError && isUnauthorizedError(analyticsError as Error)) { toast({ title: "Unauthorized", description: "You are logged out. Logging in again...", variant: "destructive", }); setTimeout(() => { window.location.href = "/api/login"; }, 500); } }, [analyticsError, toast]); const handleLogout = () => { window.location.href = "/api/logout"; }; if (isLoading || !user || user.role !== 'admin') { return (
); } return (
{/* Header */}
S
SAPIENS • Admin Dashboard

Admin Dashboard

Manage media outlets and content

{/* Analytics Cards */}
{analyticsLoading ? ( Array.from({ length: 4 }).map((_, i) => (
)) ) : ( <>

Total Articles

{(analytics as any)?.totalArticles || 0}

Active Predictions

{(analytics as any)?.activePredictions || 0}

Live Auctions

{(analytics as any)?.liveAuctions || 0}

Revenue

${((analytics as any)?.totalRevenue || 0).toLocaleString()}

)}
{/* Admin Actions */}

Content Management

Quick Actions

Featured Article Priority

Manage article visibility

Auction Controls

Monitor active auctions

); }