'use client'; import { useEffect, useState } from 'react'; import { useSuperAdmin } from '../../_lib/super-admin-context'; import { useRouter } from 'next/navigation'; import Link from 'next/link'; export default function TenantsPage() { const { admin, loading } = useSuperAdmin(); const router = useRouter(); const [tenants, setTenants] = useState([]); async function load() { const res = await fetch('/api/admin/tenants'); if (res.ok) setTenants(await res.json()); } useEffect(() => { if (loading) return; if (!admin) { router.replace('/admin/login'); return; } void load(); }, [admin, loading, router]); async function toggleActive(id: string, current: boolean) { await fetch(`/api/admin/tenants/${id}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ isActive: !current }), }); void load(); } async function togglePaused(id: string, current: boolean) { await fetch(`/api/admin/tenants/${id}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ isForwardingPaused: !current }), }); void load(); } if (loading) return

Loading...

; if (!admin) return null; return (

Tenants

{tenants.map((t: any) => ( ))}
Name Slug Bot Groups Messages Active Paused
{t.name} {t.slug} {t.bot ? {t.bot.jid?.slice(0, 20)}... : } {t.stats.groups} {t.stats.messages}
{tenants.length === 0 &&

No tenants yet.

}
); }