'use client'; import React, { useState, useEffect } from 'react'; import { Card, CardHeader, CardTitle, CardContent, CardFooter } from '@/components/ui/Card'; import { Button } from '@/components/ui/Button'; import { Input } from '@/components/ui/Input'; import { Form, FormRow, FormSwitch } from '@/components/ui/Form'; import { Icon } from '@/components/ui/Icon'; import { useToast } from '@/components/ui/Toast'; export default function SettingsPage() { const { success, error } = useToast(); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); // Settings State const [maxEventsPerSec, setMaxEventsPerSec] = useState('100'); const [maxPayloadSizeKb, setMaxPayloadSizeKb] = useState('100'); const [batchFlushThreshold, setBatchFlushThreshold] = useState('500'); const [batchFlushIntervalMs, setBatchFlushIntervalMs] = useState('2000'); const [fileRotationMb, setFileRotationMb] = useState('100'); const [jwtSecret, setJwtSecret] = useState('datastack-universal-secret-key-2026'); const [enableIdempotency, setEnableIdempotency] = useState(true); const [autoPruneDays, setAutoPruneDays] = useState('30'); useEffect(() => { async function loadSettings() { try { const res = await fetch('/api/settings'); if (res.ok) { const data = await res.json(); const s = data.settings; setMaxEventsPerSec(String(s.maxEventsPerSec ?? 100)); setMaxPayloadSizeKb(String(s.maxPayloadSizeKb ?? 100)); setBatchFlushThreshold(String(s.batchFlushThreshold ?? 500)); setBatchFlushIntervalMs(String(s.batchFlushIntervalMs ?? 2000)); setFileRotationMb(String(s.fileRotationMb ?? 100)); setJwtSecret(s.jwtSecret ?? 'datastack-universal-secret-key-2026'); setEnableIdempotency(Boolean(s.enableIdempotency ?? true)); setAutoPruneDays(String(s.autoPruneDays ?? 30)); } } catch { // ignore } finally { setLoading(false); } } loadSettings(); }, []); const handleSave = async (e: React.FormEvent) => { e.preventDefault(); setSaving(true); try { const res = await fetch('/api/settings', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ maxEventsPerSec: Number(maxEventsPerSec), maxPayloadSizeKb: Number(maxPayloadSizeKb), batchFlushThreshold: Number(batchFlushThreshold), batchFlushIntervalMs: Number(batchFlushIntervalMs), fileRotationMb: Number(fileRotationMb), jwtSecret, enableIdempotency, autoPruneDays: Number(autoPruneDays), }), }); if (res.ok) { success('Settings Saved', 'Core engine configuration updated and propagated'); } else { error('Save Failed', 'Server rejected configuration payload'); } } catch (err: any) { error('Error', err.message); } finally { setSaving(false); } }; return (
{/* Header */}

Settings

{/* Ingestion & Rate Limit Group */}
Throughput & Safety Limits
setMaxEventsPerSec(e.target.value)} /> setMaxPayloadSizeKb(e.target.value)} />
{/* Buffer & CSV Rotation Group */}
Redis In-Memory Buffer & CSV Partitioning
setBatchFlushThreshold(e.target.value)} /> setBatchFlushIntervalMs(e.target.value)} /> setFileRotationMb(e.target.value)} /> setAutoPruneDays(e.target.value)} />
{/* Security & Token Group */}
Authentication Secret
setJwtSecret(e.target.value)} />
Note: Updating this secret invalidates existing client handshake tokens immediately.
); }