import { GearIcon } from "@radix-ui/react-icons"; import { useEffect, useState } from "react"; import { Button } from "~/routes/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "~/routes/ui/dialog"; import { Label } from "~/routes/ui/label"; import { DEFAULT_BACKEND_BASE_URL, getCustomBackendBaseUrl, normalizeBackendBaseUrl, setCustomBackendBaseUrl, } from "~utils/backend-url"; type ConnectionSettingsButtonProps = { onSaved?: (changed: boolean) => void | Promise; }; export function ConnectionSettingsButton({ onSaved }: ConnectionSettingsButtonProps) { const [open, setOpen] = useState(false); const [customUrl, setCustomUrl] = useState(""); const [savedUrl, setSavedUrl] = useState(""); useEffect(() => { if (!open) { return; } const loadSettings = async () => { const normalized = await getCustomBackendBaseUrl(); setCustomUrl(normalized || DEFAULT_BACKEND_BASE_URL); setSavedUrl(normalized); }; loadSettings(); }, [open]); const handleSave = async () => { const normalizedUrl = normalizeBackendBaseUrl(customUrl); const nextUrl = await setCustomBackendBaseUrl( normalizedUrl === DEFAULT_BACKEND_BASE_URL ? "" : normalizedUrl ); const changed = nextUrl !== savedUrl; setSavedUrl(nextUrl); setCustomUrl(nextUrl || DEFAULT_BACKEND_BASE_URL); setOpen(false); if (onSaved) { await onSaved(changed); } }; return ( <> Connection Settings Leave blank to use the default SurfSense backend URL.
setCustomUrl(event.target.value)} placeholder={DEFAULT_BACKEND_BASE_URL} className="w-full rounded-md border border-gray-700 bg-gray-900 px-3 py-2 text-white placeholder:text-gray-500 focus:outline-none focus:ring-2 focus:ring-teal-500" />

Default: {DEFAULT_BACKEND_BASE_URL}

); }