import { useEffect, useState } from "react"; import { Link, useLocation } from "wouter"; import { useQuery } from "@tanstack/react-query"; import { useAuth } from "@/lib/auth"; import { Users, FileCode, Shield, Activity, LogOut, BarChart3, User, Globe, Award, Key, Inbox, Circle, Clock, TrendingUp, Wifi } from "lucide-react"; interface ActivityEvent { id: string; type: string; user: string; action: string; timestamp: Date; details?: string; } export default function AdminActivity() { const { user, logout } = useAuth(); const [, setLocation] = useLocation(); const [liveEvents, setLiveEvents] = useState([]); const [lastRefresh, setLastRefresh] = useState(new Date()); const [seenEventIds, setSeenEventIds] = useState>(new Set()); const { data: profiles } = useQuery({ queryKey: ["profiles"], queryFn: async () => { const res = await fetch("/api/profiles", { credentials: "include" }); if (!res.ok) return []; return res.json(); }, refetchInterval: 10000, }); const { data: authLogs } = useQuery({ queryKey: ["auth-logs"], queryFn: async () => { const res = await fetch("/api/auth-logs", { credentials: "include" }); if (!res.ok) return []; return res.json(); }, refetchInterval: 5000, }); const { data: metrics } = useQuery({ queryKey: ["metrics"], queryFn: async () => { const res = await fetch("/api/metrics", { credentials: "include" }); return res.json(); }, refetchInterval: 5000, }); useEffect(() => { if (authLogs && authLogs.length > 0) { const newEvents: ActivityEvent[] = []; const newIds = new Set(seenEventIds); for (const log of authLogs.slice(0, 30)) { const eventId = log.id || `log-${log.created_at}`; if (!newIds.has(eventId)) { newIds.add(eventId); newEvents.push({ id: eventId, type: log.event_type?.includes('success') ? 'login' : log.event_type?.includes('fail') ? 'failed' : 'auth', user: log.username || log.user_id || 'Unknown', action: log.event_type || 'Activity', timestamp: new Date(log.created_at), details: log.ip_address, }); } } if (newEvents.length > 0) { setLiveEvents(prev => [...newEvents, ...prev].slice(0, 50)); setSeenEventIds(newIds); } setLastRefresh(new Date()); } }, [authLogs]); const handleLogout = async () => { await logout(); setLocation("/"); }; const onlineProfiles = profiles?.filter((p: any) => p.status === 'online') || []; const recentlyActive = profiles?.filter((p: any) => { if (!p.last_seen) return false; const lastSeen = new Date(p.last_seen); const fiveMinutesAgo = new Date(Date.now() - 5 * 60 * 1000); return lastSeen > fiveMinutesAgo; }) || []; return (

Real-Time Activity

Live monitoring of user activity across the platform

Last updated: {lastRefresh.toLocaleTimeString()}
Live
Online Now
{metrics?.onlineUsers || 0}
Active users
Total Architects
{metrics?.totalProfiles || 0}
Registered
Auth Events
{authLogs?.length || 0}
Last 100
Verified Users
{metrics?.verifiedUsers || 0}
Certified

Online Users ({onlineProfiles.length})

{onlineProfiles.length === 0 ? (
No users currently online
) : ( onlineProfiles.map((profile: any) => (
{profile.username || profile.display_name}
Level {profile.level || 1}
Online
)) )}

Live Activity Feed

{liveEvents.length === 0 ? (
No recent activity
) : ( liveEvents.map((event) => (
{event.user} — {event.action}
{event.timestamp.toLocaleTimeString()}
)) )}
); } function Sidebar({ user, onLogout, active }: { user: any; onLogout: () => void; active: string }) { return (

AeThex

Command Center

{user?.username}
{user?.isAdmin ? "Administrator" : "Member"}
); } function NavItem({ icon, label, href, active = false }: { icon: React.ReactNode; label: string; href: string; active?: boolean }) { return (
{icon} {label}
); }