'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; export default function AddPage() { const router = useRouter(); const [firmName, setFirmName] = useState(''); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [saving, setSaving] = useState(false); const inputCls = 'w-full border border-slate-200 rounded-lg px-3 py-2 text-sm text-slate-800 focus:outline-none focus:ring-2 focus:ring-blue-400'; const labelCls = 'block text-xs font-semibold uppercase tracking-wider text-slate-500 mb-1'; const handleSave = async () => { if (!firmName.trim() || !username.trim() || !password.trim()) return; setSaving(true); setError(''); try { const res = await fetch('/api/firms', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: firmName.trim(), username: username.trim(), password: password.trim() }), }); if (!res.ok) { const data = await res.json() as { error?: string }; setError(data.error ?? 'Failed to save firm'); return; } router.push('/'); } catch { setError('Could not connect to server'); } finally { setSaving(false); } }; return (