import type { EnvironmentId, UnifiedSettings } from "@t3tools/contracts"; import { PlusIcon } from "lucide-react"; import { useState } from "react"; import { useUpdateEnvironmentSettings } from "../../hooks/useSettings"; import { AlertDialog, AlertDialogClose, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogPopup, AlertDialogTitle, } from "../ui/alert-dialog"; import { Button } from "../ui/button"; import { AddUsageLimitSourceDialog } from "./AddUsageLimitSourceDialog"; import { searchableSetting } from "./settingsSearch"; import { SettingsRow, SettingsSection } from "./settingsLayout"; /** Hub management follows the selected device and access rules of provider settings. */ export function UsageProviderSettings({ environmentId, environmentLabel, sources, readOnly, }: { readonly environmentId: EnvironmentId; readonly environmentLabel: string; readonly sources: UnifiedSettings["usageLimitSources"]; readonly readOnly: boolean; }) { const updateSettings = useUpdateEnvironmentSettings(environmentId); const [adding, setAdding] = useState(false); const entries = Object.entries(sources); return ( <> setAdding(true)}> Add hub ) : null } > {entries.length === 0 ? ( ) : ( entries.map(([id, source]) => { const label = source.label?.trim() || source.url; return ( CLI Proxy{source.enabled ? "" : " · Disabled"} {label !== source.url ? ` · ${source.url}` : ""} } control={ !readOnly ? ( updateSettings({ usageLimitSources: { [id]: null } })} /> ) : null } /> ); }) )} {adding && !readOnly ? ( ) : null} ); } /** Removing a hub deletes its stored management key, so it requires confirmation. */ function RemoveUsageProviderButton({ label, onConfirm, }: { readonly label: string; readonly onConfirm: () => void; }) { const [open, setOpen] = useState(false); return ( <> Remove {label}? The hub's management key is deleted from this server. Its accounts leave the Limits view; the hub itself is untouched. Add it again with the URL and key to bring them back. }>Cancel ); }