import { motion } from "framer-motion"; import { 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, CheckCircle, XCircle, AlertTriangle, ExternalLink } from "lucide-react"; export default function AdminSites() { const { user, logout } = useAuth(); const [, setLocation] = useLocation(); const [editingSite, setEditingSite] = useState(null); const [showForm, setShowForm] = useState(false); const [formLoading, setFormLoading] = useState(false); const [formError, setFormError] = useState(null); const [formSuccess, setFormSuccess] = useState(null); const { data: sites, isLoading, refetch } = useQuery({ queryKey: ["sites"], queryFn: async () => { const res = await fetch("/api/sites"); if (!res.ok) throw new Error("Failed to fetch sites"); return res.json(); }, }); // Add or update site const handleFormSubmit = async (e: React.FormEvent) => { e.preventDefault(); setFormLoading(true); setFormError(null); setFormSuccess(null); const form = e.currentTarget; const formData = new FormData(form); const payload: any = Object.fromEntries(formData.entries()); try { let res; if (editingSite) { res = await fetch(`/api/sites/${editingSite.id}`, { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), }); } else { res = await fetch("/api/sites", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), }); } if (!res.ok) throw new Error("Failed to save site"); setFormSuccess(editingSite ? "Site updated!" : "Site created!"); setShowForm(false); setEditingSite(null); form.reset(); await refetch(); } catch (err: any) { setFormError(err.message || "Error"); } finally { setFormLoading(false); } }; // Delete site const handleDelete = async (id: string) => { if (!window.confirm("Delete this site?")) return; setFormLoading(true); setFormError(null); try { const res = await fetch(`/api/sites/${id}`, { method: "DELETE" }); if (!res.ok) throw new Error("Failed to delete site"); await refetch(); } catch (err: any) { setFormError(err.message || "Error"); } finally { setFormLoading(false); } }; const handleLogout = async () => { await logout(); setLocation("/"); }; const getStatusColor = (status: string) => { switch (status?.toLowerCase()) { case 'online': case 'operational': return 'text-green-500'; case 'degraded': case 'warning': return 'text-yellow-500'; case 'offline': case 'down': return 'text-destructive'; default: return 'text-muted-foreground'; } }; const getStatusIcon = (status: string) => { switch (status?.toLowerCase()) { case 'online': case 'operational': return ; case 'degraded': case 'warning': return ; case 'offline': case 'down': return ; default: return ; } }; return (

AeThex Sites

{sites?.length || 0} monitored sites

{formError &&
{formError}
} {formSuccess &&
{formSuccess}
} {showForm && (

{editingSite ? "Edit Site" : "Add Site"}

)}
{isLoading ? (
Loading sites...
) : sites?.length === 0 ? (

No Sites Configured

Site monitoring will display here once sites are added to your Supabase database. Add entries to the "sites" table to track uptime and performance.

) : ( sites?.map((site: any) => (

{site.name}

{getStatusIcon(site.status)} {site.status || 'unknown'}
{site.url && ( {site.url} )}
Uptime
{site.uptime || 0}%
Response
{site.response_time || 0}ms
Users
{site.users || 0}
Requests
{site.requests || 0}
{site.last_check && (
Last check: {new Date(site.last_check).toLocaleString()}
)}
)) )}
); } 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}
); }