Frontend, built from design-canvas/discord-system-mockup.html ("DRB admin"):
- Settings > Discord (/settings/discord, platform admin only; the tab is
hidden from org owners because every route behind it is admin-only).
KPIs + tabs:
* Radio channels: every discord_streams doc, desired -> actual, the node's
real error, red after 2 min desired-on without connecting. Stop
(POST /discord/guilds/{id}/stop), Start for a stopped channel and
"+ Add radio channel" (POST /discord/streams), with the invite links a
"no bot in this server" refusal carries.
* Servers: linked servers plus servers seen running radio while unlinked
(acting for DISCORD_UNLINKED_GUILD_ORG_ID); Link / Change org
(PUT /discord/guilds/{id}/link).
* Radio bots: valid / check_error, guild membership with a per-server
invite link for each server the bot is missing from, lease (node,
since, releasing), fan-out, Refresh (POST /tokens/{id}/refresh),
Remove, Release all leases (POST /tokens/flush), add with optional BYO org.
* How it works.
- /tokens now renders the same radio-bot table (new token fields + refresh).
- Left out, no backend yet: alert routes, incident forum/roles/plan columns,
per-channel talkgroup chips, "Generate link code" (item 1).
Backend (routers/discord.py):
- GET /discord/admin/overview (platform admin): guilds, streams with node
and bot names, orgs, systems, limits. No token strings, no Discord user
ids, no linking-admin uid.
- PUT /discord/guilds/{id}/link: digits-only id, optional guild_name label,
and re-linking a server to a different org stops its live channels
(the reconciler would otherwise keep re-placing them on the old org's
nodes, using its stored org_id).
- POST /discord/streams: guild_id/channel_id must be digits (the web form
types them in; the bot always sent snowflakes).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
66 lines
2.4 KiB
TypeScript
66 lines
2.4 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
import Link from "next/link";
|
|
import { usePathname, useRouter } from "next/navigation";
|
|
import { useAuth } from "@/components/AuthProvider";
|
|
import { PageHeader } from "@/components/ui/PageHeader";
|
|
|
|
const TABS = [
|
|
{ href: "/settings/organization", label: "Organization" },
|
|
{ href: "/settings/members", label: "Members" },
|
|
{ href: "/settings/nodes", label: "Node Ownership" },
|
|
{ href: "/settings/api-keys", label: "API Keys" },
|
|
{ href: "/settings/billing", label: "Billing" },
|
|
];
|
|
|
|
// Platform-admin-only tabs: every route behind them is require_admin_token,
|
|
// so an org owner would only see 403s (server-26#213 item 2).
|
|
const ADMIN_TABS = [{ href: "/settings/discord", label: "Discord" }];
|
|
|
|
export default function SettingsLayout({ children }: { children: React.ReactNode }) {
|
|
// SAAS_PLAN.md B7: this used to gate on isAdmin (platform admin) alone,
|
|
// which meant a paying customer who is their own org's owner couldn't
|
|
// reach their own billing/members/node-ownership settings — "admin" here
|
|
// conflated "platform operator" with "org owner". isAdmin still passes
|
|
// (support/debugging access to any org's settings), but org_role ===
|
|
// "owner" is now sufficient on its own.
|
|
const { isAdmin, isOrgOwner, loading } = useAuth();
|
|
const canAccess = isAdmin || isOrgOwner;
|
|
const pathname = usePathname();
|
|
const router = useRouter();
|
|
|
|
useEffect(() => {
|
|
if (!loading && !canAccess) router.replace("/");
|
|
}, [loading, canAccess, router]);
|
|
|
|
if (loading || !canAccess) return null;
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<PageHeader
|
|
title="Settings"
|
|
description="Organization profile, team access, node ownership, API keys, and billing."
|
|
/>
|
|
|
|
<div className="flex flex-wrap gap-1 bg-gray-900 border border-gray-800 rounded-lg p-1 w-fit max-w-full overflow-x-auto">
|
|
{[...TABS, ...(isAdmin ? ADMIN_TABS : [])].map((t) => (
|
|
<Link
|
|
key={t.href}
|
|
href={t.href}
|
|
className={`text-sm font-mono px-4 py-1.5 rounded-md transition-colors whitespace-nowrap ${
|
|
pathname === t.href || pathname.startsWith(t.href + "/")
|
|
? "bg-gray-800 text-white"
|
|
: "text-gray-500 hover:text-gray-300"
|
|
}`}
|
|
>
|
|
{t.label}
|
|
</Link>
|
|
))}
|
|
</div>
|
|
|
|
{children}
|
|
</div>
|
|
);
|
|
}
|