import { useCallback, useEffect, useState } from "react"; import { Download04Icon, Loading03Icon, RefreshIcon, } from "@hugeicons/core-free-icons"; import { api, type UpdateCheckResult } from "@/api/client"; import { useAuth } from "@/context/AuthContext"; import { Icon } from "@/components/icon"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { ColorPicker } from "@/components/ui/color-picker"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Skeleton } from "@/components/ui/skeleton"; import { DEFAULT_ACCENT_HEX, getStoredAccentHex, resetAccentTheme, saveAccentTheme, } from "@/lib/accent-theme"; import { normalizeHex } from "@/lib/normalize-hex"; import { DashboardBrandingSettings, DashboardDangerZone } from "@/components/settings/dashboard-branding-settings"; import { DashboardApiSettings } from "@/components/settings/dashboard-api-settings"; export default function Settings() { const { hasPermission } = useAuth(); const canUpdate = hasPermission("settings.update"); const [checks, setChecks] = useState(null); const [loading, setLoading] = useState(true); const [updating, setUpdating] = useState(false); const [error, setError] = useState(""); const [notice, setNotice] = useState(""); const [accentHex, setAccentHex] = useState( () => getStoredAccentHex() ?? DEFAULT_ACCENT_HEX, ); const [accentSaved, setAccentSaved] = useState(""); const [activeTab, setActiveTab] = useState<"appearance" | "api" | "updates" | "danger">("appearance"); const loadCheck = useCallback(async () => { setLoading(true); setError(""); try { const res = await api.checkForUpdates(); if (res.data) setChecks(res.data); } catch (err) { setError(err instanceof Error ? err.message : "Could not check for updates"); } finally { setLoading(false); } }, []); useEffect(() => { loadCheck(); }, [loadCheck]); async function handleUpdate(check: UpdateCheckResult) { if (!check.updateAvailable) return; setUpdating(true); setError(""); setNotice(""); try { const res = await api.runUpdate(check.id, check.latest, check.zipUrl); setNotice( res.message || "Update installed. Restart your server (stop and run npm start again) to finish applying changes.", ); await loadCheck(); } catch (err) { setError(err instanceof Error ? err.message : "Update failed"); } finally { setUpdating(false); } } return (

Settings

Application updates and maintenance — config files are edited under each module in the sidebar.

{activeTab === "appearance" && (
Dashboard appearance Customise branding for all users, and pick an accent colour for this browser only.

Accent colour

Buttons, links, and highlights — saved in this browser only.

{ setAccentHex(hex); saveAccentTheme(hex); setAccentSaved("Accent updated."); }} /> setAccentHex(e.target.value)} onBlur={() => { const next = normalizeHex(accentHex, DEFAULT_ACCENT_HEX); setAccentHex(next); saveAccentTheme(next); setAccentSaved("Accent updated."); }} className="w-32 border-border bg-secondary/30 font-mono uppercase" maxLength={7} />
Primary button Highlight Accent surface
{accentSaved ? (

{accentSaved}

) : null}
)} {activeTab === "danger" && canUpdate && ( Danger Zone Destructive actions that reset or permanently alter your dashboard. )} {activeTab === "api" && ( API Configuration Configure the internal API settings, Emerald API key, and OAuth. )} {activeTab === "updates" && ( Software updates Manage updates for the bot and dashboard. {loading ? ( ) : checks && checks.length > 0 ? (
{checks.map((check) => (

{check.name} {" "} ({check.branch} branch)

Installed: v{check.current}

Latest: v{check.latest}

{check.updateAvailable ? (

A newer version is available. Update downloads files while keeping your Configs and Data.

) : (

You are on the latest release.

)} {check.updateAvailable && canUpdate ? ( ) : null} {check.updateAvailable && !canUpdate ? (

You cannot install updates with your role.

) : null}
))}
) : null} {error ? ( {error} ) : null} {notice ? ( {notice} ) : null}
)}
); }