import React, { useEffect, useState } from 'react'; import axios from 'axios'; import Layout from '../components/Layout'; import BrandKit from '../components/BrandKit'; import { Settings, Save, Plus, Trash2, ToggleLeft, ToggleRight, Search } from 'lucide-react'; interface ConfigItem { key: string; value: string; description?: string; } export default function ConfigPage() { const [configs, setConfigs] = useState([]); const [loading, setLoading] = useState(true); const [search, setSearch] = useState(''); const [newItem, setNewItem] = useState({ key: '', value: '', description: '' }); const [editingItem, setEditingItem] = useState(null); useEffect(() => { fetchConfigs(); }, []); const fetchConfigs = async () => { try { const res = await axios.get('/api/admin/config'); setConfigs(res.data.configs); } catch (err) { console.error(err); } finally { setLoading(false); } }; const handleSave = async (key: string, value: string, description?: string) => { try { await axios.put('/api/admin/config', { key, value, description }); setEditingItem(null); fetchConfigs(); if (key === newItem.key) setNewItem({ key: '', value: '', description: '' }); } catch (err) { alert('Failed to save config'); } }; const filteredConfigs = (configs || []).filter(c => c.key.toLowerCase().includes(search.toLowerCase()) || (c.description || '').toLowerCase().includes(search.toLowerCase()) ); return (

System Configuration

Manage global variables, feature flags, and system limits.

{/* New Config Card */}

Add New Variable

setNewItem({ ...newItem, key: e.target.value.toUpperCase() })} /> setNewItem({ ...newItem, value: e.target.value })} /> setNewItem({ ...newItem, description: e.target.value })} />
{/* Search Bar */}
setSearch(e.target.value)} />
{/* Config Table */}
{filteredConfigs.map(config => ( ))} {filteredConfigs.length === 0 && ( )}
Key Name Value Description Actions
{config.key} {editingItem === config.key ? ( handleSave(config.key, e.target.value, config.description)} onKeyDown={(e) => { if (e.key === 'Enter') handleSave(config.key, e.currentTarget.value, config.description); }} autoFocus /> ) : ( )} {config.description || '-'}
No configuration keys found.
); }