Node-page picker and the admin Add form now show, per voice channel, whether
a radio bot can stream there, from S3's voice-check routes:
- Badge per channel: Ready / Needs fix (names the missing permission) /
Couldn't check / Bots busy / No radio bot / Not a voice channel / Limit N.
- The chosen channel shows "<bot> can't Speak in #dispatch: <what removed it>"
plus c2-core's fix sentence, and an expandable per-bot list.
- Footer: "Permissions checked 40s ago · Re-check" (refresh=1, rate limited
server-side; a limited re-check says so). Invite links when no bot fits.
- Start is disabled only on a definite refusal (needs_fix, bad_channel);
unknown fails open. A channel this system already plays in is judged by
the bot that carries it, so Update/move is never blocked by the other bots.
- Admin Add form disables bots that are definitely denied in the bot list.
- 409 refusals (missing_permissions, preferred_busy, preferred_other_node,
bad_channel) are shown verbatim, multi-line.
Org owners (owner decision Q2) get "Radio bot per system" on
Settings > Organization: their own systems, their own BYO bots, set/clear
through S3's PUT /tokens/{id}/prefer/{system}. New GET /tokens/org/preferred
lists only the caller org's systems and bots (no pool bots, no token
strings; a pool bot an admin chose is flagged, not named).
The prefer route now drops the 5-minute doc_get_cached entry for every
system it rewrites, so a new preference applies to the next start.
Stacked on feat/225-s3-perm-check: must merge after S3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
141 lines
5.1 KiB
TypeScript
141 lines
5.1 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
import Link from "next/link";
|
|
import { c2api } from "@/lib/c2api";
|
|
import { useAuth } from "@/components/AuthProvider";
|
|
import { useNodes } from "@/lib/useNodes";
|
|
import { getCurrentSubscription, getPlan, type Subscription } from "@/lib/billing";
|
|
import { Card, CardHeader } from "@/components/ui/Card";
|
|
import { Badge } from "@/components/ui/Badge";
|
|
import { Button } from "@/components/ui/Button";
|
|
import { Skeleton } from "@/components/ui/Skeleton";
|
|
import { DiscordServersCard } from "@/components/DiscordServersCard";
|
|
import { PreferredBotsCard } from "@/components/discord/PreferredBotsCard";
|
|
|
|
function StatTile({ label, value }: { label: string; value: string | number }) {
|
|
return (
|
|
<div>
|
|
<p className="text-xs text-gray-500 uppercase tracking-wider font-mono">{label}</p>
|
|
<p className="text-2xl font-bold text-white font-mono mt-1">{value}</p>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default function OrganizationSettingsPage() {
|
|
const { nodes } = useNodes();
|
|
const { isOrgOwner, isAdmin } = useAuth();
|
|
const [memberCount, setMemberCount] = useState<number | null>(null);
|
|
const [sub, setSub] = useState<Subscription | null>(null);
|
|
const [orgName, setOrgName] = useState("");
|
|
const [savedName, setSavedName] = useState("");
|
|
const [orgLoading, setOrgLoading] = useState(true);
|
|
const [saving, setSaving] = useState(false);
|
|
const [saveError, setSaveError] = useState<string | null>(null);
|
|
|
|
const canEdit = isOrgOwner || isAdmin;
|
|
|
|
useEffect(() => {
|
|
c2api.listUsers().then((u) => setMemberCount(u.length)).catch(() => setMemberCount(null));
|
|
getCurrentSubscription().then(setSub);
|
|
c2api.getOrg()
|
|
.then((org) => { setOrgName(org.name); setSavedName(org.name); })
|
|
.catch(() => {})
|
|
.finally(() => setOrgLoading(false));
|
|
}, []);
|
|
|
|
async function handleSave() {
|
|
setSaving(true);
|
|
setSaveError(null);
|
|
try {
|
|
const res = await c2api.updateOrg(orgName.trim());
|
|
setSavedName(res.name);
|
|
setOrgName(res.name);
|
|
} catch (err) {
|
|
setSaveError(err instanceof Error ? err.message : "Could not save.");
|
|
} finally {
|
|
setSaving(false);
|
|
}
|
|
}
|
|
|
|
const plan = sub ? getPlan(sub.planId) : null;
|
|
|
|
return (
|
|
<div className="space-y-6 max-w-3xl">
|
|
<Card>
|
|
<CardHeader
|
|
title="Organization profile"
|
|
subtitle="Basic identity for this DRB account."
|
|
/>
|
|
<div className="space-y-4">
|
|
<div>
|
|
<label className="text-xs text-gray-400 block mb-1">Organization name</label>
|
|
<input
|
|
value={orgName}
|
|
disabled={orgLoading || !canEdit}
|
|
onChange={(e) => setOrgName(e.target.value)}
|
|
className="w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-indigo-500 disabled:opacity-50"
|
|
/>
|
|
</div>
|
|
{saveError && <p className="text-red-400 text-xs">{saveError}</p>}
|
|
<div className="flex items-center gap-3">
|
|
<Button
|
|
size="sm"
|
|
disabled={orgLoading || !canEdit || saving || !orgName.trim() || orgName.trim() === savedName}
|
|
onClick={handleSave}
|
|
title={!canEdit ? "Only the organization owner can change this" : undefined}
|
|
>
|
|
{saving ? "Saving…" : "Save changes"}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</Card>
|
|
|
|
<Card>
|
|
<CardHeader
|
|
title="Overview"
|
|
action={
|
|
plan ? (
|
|
<Badge tone={plan.id === "free" ? "neutral" : "brand"}>{plan.name} plan</Badge>
|
|
) : (
|
|
<Skeleton className="h-5 w-16" />
|
|
)
|
|
}
|
|
/>
|
|
<div className="grid grid-cols-2 sm:grid-cols-3 gap-6">
|
|
<StatTile label="Nodes" value={nodes.length} />
|
|
<StatTile label="Members" value={memberCount ?? "—"} />
|
|
<StatTile
|
|
label="Status"
|
|
value={sub ? sub.status.replace("_", " ") : "—"}
|
|
/>
|
|
</div>
|
|
<div className="mt-5 pt-5 border-t border-gray-800 flex items-center gap-4 text-sm">
|
|
<Link href="/settings/billing" className="text-indigo-400 hover:text-indigo-300 transition-colors">
|
|
Manage plan & billing →
|
|
</Link>
|
|
<Link href="/settings/members" className="text-indigo-400 hover:text-indigo-300 transition-colors">
|
|
Manage members →
|
|
</Link>
|
|
</div>
|
|
</Card>
|
|
|
|
<DiscordServersCard canEdit={canEdit} isAdmin={isAdmin} />
|
|
|
|
<PreferredBotsCard canEdit={canEdit} />
|
|
|
|
<div className="bg-gray-900 border border-red-800/60 rounded-xl p-5">
|
|
<CardHeader title="Danger zone" subtitle="Destructive organization-level actions." />
|
|
<div className="flex flex-wrap gap-3">
|
|
<Button variant="danger" size="sm" disabled title="Not available in this build — contact support">
|
|
Delete organization
|
|
</Button>
|
|
<Button variant="secondary" size="sm" disabled title="Not available in this build — contact support">
|
|
Transfer ownership
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|