"use client"; import { useEffect, useState } from "react"; import { useParams } from "next/navigation"; import { Mail, UserCog, Clock, Plus } from "lucide-react"; import { api } from "@/lib/api"; const LIFECYCLE = ["active", "grace", "archived", "deleted"]; export default function OrgDetail() { const { org_id } = useParams<{ org_id: string }>(); const [d, setD] = useState(null); const [hist, setHist] = useState(null); const [notes, setNotes] = useState([]); const [note, setNote] = useState(""); const [toast, setToast] = useState(""); function load() { api(`/admin/organizations/${org_id}`).then(setD).catch(() => {}); api(`/admin/organizations/${org_id}/history`).then(setHist).catch(() => {}); api(`/admin/organizations/${org_id}/notes`).then(setNotes).catch(() => setNotes([])); } useEffect(() => { load(); }, [org_id]); async function addNote() { if (!note.trim()) return; await api(`/admin/organizations/${org_id}/notes`, { method: "POST", body: JSON.stringify({ note }) }); setNote(""); load(); } async function sendReminder() { const r = await api(`/admin/organizations/${org_id}/send-reminder`, { method: "POST" }); setToast(`Reminder sent to ${r.to}`); setTimeout(() => setToast(""), 2500); } async function extend() { await api(`/admin/organizations/${org_id}/subscription`, { method: "PUT", body: JSON.stringify({ extend_days: 30 }) }); setToast("Subscription extended 30 days"); load(); setTimeout(() => setToast(""), 2500); } async function impersonate() { const r = await api(`/admin/organizations/${org_id}/impersonate`, { method: "POST" }); setToast(r.message); setTimeout(() => setToast(""), 2500); } if (!d) return
Loading…
; const curStage = LIFECYCLE.indexOf(d.subscription_status); return (
{toast &&
{toast}
}

{d.name}

{d.plan} · {d.subscription_status}

{/* Lifecycle timeline */}

Subscription Lifecycle

{LIFECYCLE.map((stage, i) => (
{i + 1}
{stage}
{i < LIFECYCLE.length - 1 && (
)}
))}
{/* Utilization */}
{/* Admins */}

Admin Users

{(d.admins ?? []).map((a: any, i: number) => (
{a.name} ({a.email}) {a.last_login ? new Date(a.last_login).toLocaleDateString() : "never"}
))} {(!d.admins || d.admins.length === 0) &&

No admins.

}
{/* History */} {hist && (

Invoices

{hist.invoices.map((i: any, k: number) => (
{i.invoice_number} ₹{i.total} · {i.status}
))} {hist.invoices.length === 0 &&

No invoices.

}

Plan History

{hist.plan_history.map((h: any, k: number) => (
{h.from ?? "—"} → {h.to} {new Date(h.at).toLocaleDateString()}
))} {hist.plan_history.length === 0 &&

No changes.

}
)} {/* Support notes */}

Internal Support Notes

setNote(e.target.value)} placeholder="Add an internal note…" className="flex-1 px-3 py-2 rounded-lg border border-slate-200 text-sm" />
{notes.map((n) => (
{n.note}
{n.author} · {new Date(n.at).toLocaleString()}
))} {notes.length === 0 &&

No notes yet.

}
); } function UtilBar({ label, used, limit }: { label: string; used: number; limit: number | null }) { const pct = limit == null ? 8 : Math.min(100, Math.round((used / limit) * 100)); return (
{label} {used} / {limit ?? "∞"}
); } function Stat({ label, value }: any) { return (
{label}
{value}
); }