import "./components/ui/tidal.css"; import { useLayoutEffect, useRef, useState } from "react"; import { TidalDeveloperPortalTemplate } from "./components/ui/developer-portal-template"; import type { TidalApiKeyRecord } from "./components/ui/api-key-manager"; import { TidalWebhookEndpointForm, type TidalWebhookEndpoint } from "./components/ui/webhook-manager"; import type { TidalUsageMetric } from "./components/ui/usage-limits"; import { TidalButton } from "./components/ui/tidal-button"; import "./components/ui/api-key-manager.css"; import "./components/ui/webhook-manager.css"; import "./components/ui/usage-limits.css"; import "./components/ui/developer-portal-template.css"; import "./components/ui/code-block.css"; import "./components/ui/status-badge.css"; import "./components/ui/toggle-switch.css"; import "./components/ui/collapsible-panel.css"; import "./components/ui/meter.css"; const tidalExampleStyles = ".tidal-scope .tidal-developer-portal-confirmation {\n display: grid;\n gap: 10px;\n margin-block-start: 14px;\n padding: 12px;\n border: 1px solid var(--t-border);\n border-radius: 10px;\n background: var(--t-subtle);\n}\n.tidal-scope .tidal-developer-portal-confirmation p {\n margin: 0;\n font-size: 12px;\n line-height: 1.5;\n overflow-wrap: anywhere;\n}\n.tidal-scope .tidal-developer-portal-confirmation > div {\n display: flex;\n flex-wrap: wrap;\n gap: 8px;\n}"; const INITIAL_KEYS: TidalApiKeyRecord[] = [ { id: "key-sample-1", name: "Local development", maskedValue: "tidal_sample_••••7F2A", scopes: ["projects:read", "events:read"], status: "active", created: { label: "October 12, 2026", dateTime: "2026-10-12" }, lastUsed: { label: "Sample activity 18 minutes ago" }, }, { id: "key-sample-2", name: "Reporting preview", maskedValue: "tidal_sample_••••1C09", scopes: ["reports:read"], status: "active", created: { label: "October 4, 2026", dateTime: "2026-10-04" }, }, ]; const INITIAL_ENDPOINTS: TidalWebhookEndpoint[] = [ { id: "endpoint-sample", name: "Local event receiver", url: "https://example.test/hooks/tidal", enabled: true, signing: "configured", events: ["project.updated", "report.ready"], deliveriesOpen: false, deliveries: [ { id: "delivery-sample", event: "project.updated", outcome: "delivered", time: { label: "Sample delivery at 2:14 PM" }, response: "204 sample response", duration: "184 ms", }, ], }, ]; const WEEKLY_USAGE: readonly TidalUsageMetric[] = [ { id: "requests", kind: "metered", label: "API requests", value: 18420, limit: 50000, valueText: "18,420", limitText: "50,000", reset: { label: "Sample period resets Monday" }, }, { id: "events", kind: "metered", label: "Webhook events", value: 2100, limit: 10000, valueText: "2,100", limitText: "10,000", }, ]; const MONTHLY_USAGE: readonly TidalUsageMetric[] = [ { id: "requests", kind: "metered", label: "API requests", value: 74600, limit: 200000, valueText: "74,600", limitText: "200,000", reset: { label: "Sample period resets November 1" }, }, { id: "events", kind: "metered", label: "Webhook events", value: 8600, limit: 40000, valueText: "8,600", limitText: "40,000", }, ]; const WEBHOOK_EVENTS = [ { value: "project.updated", label: "Project updated" }, { value: "report.ready", label: "Report ready" }, { value: "workspace.created", label: "Workspace created" }, ] as const; export function DeveloperPortalTemplateDemo() { const [keys, setKeys] = useState(INITIAL_KEYS); const [endpoints, setEndpoints] = useState(INITIAL_ENDPOINTS); const [period, setPeriod] = useState<"week" | "month">("week"); const [pendingRevokeId, setPendingRevokeId] = useState(); const [editingEndpointId, setEditingEndpointId] = useState( null, ); const [endpointValues, setEndpointValues] = useState({ name: "", url: "", events: [] as readonly string[], }); const [status, setStatus] = useState("Developer sample ready."); const createKeyRef = useRef(null); const createEndpointRef = useRef(null); const endpointOpenerRef = useRef(null); const endpointNameRef = useRef(null); const localRecordSequence = useRef(1); const pendingRevoke = keys.find((record) => record.id === pendingRevokeId); useLayoutEffect(() => { if (editingEndpointId === null) return; const input = endpointNameRef.current; const ownerWindow = input?.ownerDocument.defaultView; if (!input || !ownerWindow) return; const frame = ownerWindow.requestAnimationFrame(() => { input.focus({ preventScroll: true }); input.scrollIntoView({ block: "nearest", inline: "nearest" }); }); return () => ownerWindow.cancelAnimationFrame(frame); }, [editingEndpointId]); const returnToKeyManager = () => { queueMicrotask(() => createKeyRef.current?.focus({ preventScroll: true })); }; const closeEndpointEditor = () => { setEditingEndpointId(null); queueMicrotask(() => (endpointOpenerRef.current ?? createEndpointRef.current)?.focus({ preventScroll: true, }), ); }; return ( { const sampleId = "key-local-created"; if (keys.some((record) => record.id === sampleId)) { setStatus("The local sample key is already visible."); return; } setKeys((items) => [ ...items, { id: sampleId, name: "New local sample", maskedValue: "tidal_sample_••••8B14", scopes: ["projects:read"], status: "active", created: { label: "Created in this preview" }, lastUsed: { label: "Never used" }, }, ]); setStatus( "A masked fictional key record was added locally. No credential was generated.", ); }, onRevokeRequest: (record) => { setPendingRevokeId(record.id); setStatus(`Confirm the local revoke for ${record.name}.`); }, dialog: pendingRevoke ? (

Mark {pendingRevoke.name} revoked in this local sample?

{ setKeys((items) => items.map((item) => item.id === pendingRevoke.id ? { ...item, status: "revoked" } : item, ), ); setStatus( `${pendingRevoke.name} was marked revoked in local sample state.`, ); setPendingRevokeId(undefined); returnToKeyManager(); }} > Confirm local revoke { setPendingRevokeId(undefined); setStatus("Local revoke canceled."); returnToKeyManager(); }} > Keep key
) : null, }} webhooks={{ title: "Webhooks", description: "One fictional endpoint and exact supplied delivery metadata.", endpoints, createButtonRef: createEndpointRef, onCreateRequest: (event) => { endpointOpenerRef.current = event.currentTarget; setEndpointValues({ name: "", url: "", events: [] }); setEditingEndpointId("new"); setStatus("Complete the local endpoint form."); }, onEnabledChange: (endpoint, enabled) => { setEndpoints((items) => items.map((item) => item.id === endpoint.id ? { ...item, enabled } : item, ), ); setStatus( `${endpoint.name} is ${enabled ? "enabled" : "paused"} in local sample state.`, ); }, onTestRequest: (endpoint) => { const id = `local-delivery-${localRecordSequence.current++}`; setEndpoints((items) => items.map((item) => item.id === endpoint.id ? { ...item, deliveriesOpen: true, deliveries: [ { id, event: "webhook.test", outcome: "delivered", time: { label: "Just now · local sample" }, response: "204 sample response", duration: "96 ms", }, ...item.deliveries, ], } : item, ), ); setStatus( `A fictional delivery was added for ${endpoint.name}. No network request was sent.`, ); }, onEditRequest: (endpoint, event) => { endpointOpenerRef.current = event.currentTarget; setEndpointValues({ name: endpoint.name, url: endpoint.url, events: endpoint.events, }); setEditingEndpointId(endpoint.id); setStatus(`Edit ${endpoint.name} in the local form.`); }, onDeliveriesOpenChange: (endpoint, open) => setEndpoints((items) => items.map((item) => item.id === endpoint.id ? { ...item, deliveriesOpen: open } : item, ), ), editor: editingEndpointId !== null ? ( { event.preventDefault(); const name = endpointValues.name.trim(); const endpointId = editingEndpointId === "new" ? `endpoint-local-${localRecordSequence.current++}` : editingEndpointId; setEndpoints((items) => editingEndpointId === "new" ? [ ...items, { id: endpointId, name, url: endpointValues.url, enabled: false, signing: "not-configured", events: endpointValues.events, deliveries: [], deliveriesOpen: false, }, ] : items.map((item) => item.id === editingEndpointId ? { ...item, name, url: endpointValues.url, events: endpointValues.events, } : item, ), ); setStatus(`${name} was saved in local sample state.`); closeEndpointEditor(); }} /> ) : undefined, }} usage={{ title: "Usage", description: `Fictional ${period === "week" ? "weekly" : "monthly"} allowance readings.`, metrics: period === "week" ? WEEKLY_USAGE : MONTHLY_USAGE, action: ( { setPeriod((value) => (value === "week" ? "month" : "week")); setStatus("Local usage period changed."); }} > Show {period === "week" ? "month" : "week"} ), }} footer={ <> {status} {" "} Fictional records only. No credential, webhook, request, account, or usage service is connected. } /> ); } export default function AgentExample() { return (
); }