'use client' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Checkbox } from '@/components/ui/checkbox' import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card' import { updateSystemConfig, testSMTP } from '@/app/actions/admin-settings' import { toast } from 'sonner' import { useState, useEffect } from 'react' export function AdminSettingsForm({ config }: { config: Record }) { const [isSaving, setIsSaving] = useState(false) const [isTesting, setIsTesting] = useState(false) // Local state for Checkbox const [allowRegister, setAllowRegister] = useState(config.ALLOW_REGISTRATION !== 'false') const [smtpSecure, setSmtpSecure] = useState(config.SMTP_SECURE === 'true') const [smtpIgnoreCert, setSmtpIgnoreCert] = useState(config.SMTP_IGNORE_CERT === 'true') // Sync state with config when server revalidates useEffect(() => { setAllowRegister(config.ALLOW_REGISTRATION !== 'false') setSmtpSecure(config.SMTP_SECURE === 'true') setSmtpIgnoreCert(config.SMTP_IGNORE_CERT === 'true') }, [config]) const handleSaveSecurity = async (formData: FormData) => { setIsSaving(true) // We override the formData get because the hidden input might be tricky const data = { ALLOW_REGISTRATION: allowRegister ? 'true' : 'false', } const result = await updateSystemConfig(data) setIsSaving(false) if (result.error) { toast.error('Failed to update security settings') } else { toast.success('Security Settings updated') } } const handleSaveAI = async (formData: FormData) => { setIsSaving(true) const data = { AI_PROVIDER: formData.get('AI_PROVIDER') as string, OLLAMA_BASE_URL: formData.get('OLLAMA_BASE_URL') as string, AI_MODEL_EMBEDDING: formData.get('AI_MODEL_EMBEDDING') as string, OPENAI_API_KEY: formData.get('OPENAI_API_KEY') as string, } const result = await updateSystemConfig(data) setIsSaving(false) if (result.error) { toast.error('Failed to update AI settings') } else { toast.success('AI Settings updated') } } const handleSaveSMTP = async (formData: FormData) => { setIsSaving(true) const data = { SMTP_HOST: formData.get('SMTP_HOST') as string, SMTP_PORT: formData.get('SMTP_PORT') as string, SMTP_USER: formData.get('SMTP_USER') as string, SMTP_PASS: formData.get('SMTP_PASS') as string, SMTP_FROM: formData.get('SMTP_FROM') as string, SMTP_IGNORE_CERT: smtpIgnoreCert ? 'true' : 'false', SMTP_SECURE: smtpSecure ? 'true' : 'false', } const result = await updateSystemConfig(data) setIsSaving(false) if (result.error) { toast.error('Failed to update SMTP settings') } else { toast.success('SMTP Settings updated') } } const handleTestEmail = async () => { setIsTesting(true) try { const result: any = await testSMTP() if (result.success) { toast.success('Test email sent successfully!') } else { toast.error(`Failed: ${result.error}`) } } catch (e: any) { toast.error(`Error: ${e.message}`) } finally { setIsTesting(false) } } return (
Security Settings Manage access control and registration policies.
setAllowRegister(!!c)} />

If disabled, new users can only be added by an Administrator via the User Management page.

AI Configuration Configure the AI provider for auto-tagging and semantic search.
SMTP Configuration Configure email server for password resets.
setSmtpSecure(!!c)} />
setSmtpIgnoreCert(!!c)} />
) }