import { useEffect, useRef, useState } from "react"; import { ImageUpload01Icon } from "@hugeicons/core-free-icons"; import { api } from "@/api/client"; import { Icon } from "@/components/icon"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { useBranding } from "@/context/BrandingContext"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; function readFileAsDataUrl(file: File): Promise { return new Promise((resolve, reject) => { const reader = new FileReader(); reader.onload = () => resolve(String(reader.result)); reader.onerror = () => reject(new Error("Could not read file")); reader.readAsDataURL(file); }); } interface DashboardBrandingSettingsProps { canEdit: boolean; } export function DashboardDangerZone({ canEdit }: DashboardBrandingSettingsProps) { const [saving, setSaving] = useState(false); const [message, setMessage] = useState(""); const [open, setOpen] = useState(false); async function resetDashboard() { if (!canEdit) return; setSaving(true); setMessage(""); try { const res = await api.resetDashboard(); setMessage(res.message || "Dashboard reset successfully."); setTimeout(() => { window.location.href = "/setup"; }, 1500); } catch (err) { setMessage(err instanceof Error ? err.message : "Reset failed"); setSaving(false); } } if (!canEdit) return null; return (

Reset the dashboard to factory settings. This clears the configuration and returns you to the initial setup screen.

Are you absolutely sure? This action cannot be undone. This will reset the dashboard to setup mode. You will need to reconnect the Discord OAuth and reconfigure the dashboard owners. {message &&

{message}

}
); } export function DashboardBrandingSettings({ canEdit }: DashboardBrandingSettingsProps) { const { branding, setBrandingLocal } = useBranding(); const fileRef = useRef(null); const [title, setTitle] = useState(branding.title); const [pageTitle, setPageTitle] = useState(branding.pageTitle); const [saving, setSaving] = useState(false); const [uploading, setUploading] = useState(false); const [message, setMessage] = useState(""); useEffect(() => { setTitle(branding.title); setPageTitle(branding.pageTitle); }, [branding.title, branding.pageTitle]); const faviconPreview = branding.hasFavicon && branding.faviconUrl ? `${branding.faviconUrl}${branding.updatedAt ? `?v=${branding.updatedAt}` : ""}` : null; async function saveText() { if (!canEdit) return; setSaving(true); setMessage(""); try { const res = await api.updateBranding({ title, pageTitle }); if (res.data) setBrandingLocal(res.data); setMessage(res.message || "Branding saved."); } catch (err) { setMessage(err instanceof Error ? err.message : "Save failed"); } finally { setSaving(false); } } async function onFaviconSelected(file: File | null) { if (!canEdit || !file) return; setUploading(true); setMessage(""); try { const dataUrl = await readFileAsDataUrl(file); const res = await api.uploadBrandingFavicon(dataUrl); if (res.data) setBrandingLocal(res.data); setMessage(res.message || "Favicon uploaded."); } catch (err) { setMessage(err instanceof Error ? err.message : "Upload failed"); } finally { setUploading(false); if (fileRef.current) fileRef.current.value = ""; } } async function removeFavicon() { if (!canEdit) return; setUploading(true); setMessage(""); try { const res = await api.removeBrandingFavicon(); if (res.data) setBrandingLocal(res.data); setMessage(res.message || "Favicon removed."); } catch (err) { setMessage(err instanceof Error ? err.message : "Remove failed"); } finally { setUploading(false); } } const textDirty = title.trim() !== branding.title || pageTitle.trim() !== branding.pageTitle; return (
{/* Text Branding */}

Branding Text

Sidebar title and browser tab title — saved on the server for everyone using this dashboard.

setTitle(e.target.value)} className="border-border bg-secondary/30" placeholder="SupportBot" />
setPageTitle(e.target.value)} className="border-border bg-secondary/30" placeholder="SupportBot Dashboard" />
{canEdit ? (
{message && textDirty ? ( {message} ) : null}
) : null}
{/* Favicon Branding */}

Favicon

PNG, ICO, SVG, JPEG, or WebP — max 512 KB. Shown in the browser tab and beside the sidebar title.

{faviconPreview ? ( Favicon preview ) : ( )}
void onFaviconSelected(e.target.files?.[0] ?? null)} />
{canEdit ? (
{branding.hasFavicon ? ( ) : null}
) : ( View only )} {!textDirty && message ? ( {message} ) : null}
); }