import { useEffect, useState } from 'react' import { Save } from 'lucide-react' import { getSettings, saveSettings, type AppSetting } from '../api' const SETTING_LABELS: Record = { forecasting_api_key: { label: 'Forecasting API Key', hint: 'API key for the Forecasting app public API. Create one in Forecasting → Settings → API Keys.', secret: true, }, forecasting_url: { label: 'Forecasting URL', hint: 'Internal URL for the Forecasting backend (e.g. http://10.10.10.113:3080). Leave blank to use the default.', }, } export function SettingsPage() { const [settings, setSettings] = useState([]) const [values, setValues] = useState>({}) const [loading, setLoading] = useState(true) const [saving, setSaving] = useState(false) const [saved, setSaved] = useState(false) const [error, setError] = useState(null) const [revealed, setRevealed] = useState>({}) useEffect(() => { getSettings() .then(({ settings: rows }) => { setSettings(rows) const v: Record = {} for (const r of rows) v[r.key] = r.value setValues(v) }) .catch(e => setError(e.message)) .finally(() => setLoading(false)) }, []) async function handleSave() { setSaving(true); setSaved(false); setError(null) try { await saveSettings(Object.entries(values).map(([key, value]) => ({ key, value }))) setSaved(true) setTimeout(() => setSaved(false), 3000) } catch (e) { setError((e as Error).message) } finally { setSaving(false) } } if (loading) return
return (

Reports Settings

These settings are stored in the database and override environment variables.

{settings.map(s => { const meta = SETTING_LABELS[s.key] ?? { label: s.key, hint: '' } const isSecret = meta.secret const isRevealed = revealed[s.key] return (
setValues(v => ({ ...v, [s.key]: e.target.value }))} className="setting-input" autoComplete="off" spellCheck={false} /> {isSecret && ( )}
{s.updated_at && ( Last saved: {new Date(s.updated_at).toLocaleString('en-GB')} )}
) })}
{error && {error}} {saved && Saved ✓}
) }