'use client'; import { useState } from 'react'; import { AccountCard } from './AccountCard'; interface Account { id: string; jid: string; displayName: string | null; status: string; platform: string; } export function AccountsList({ initialAccounts }: { initialAccounts: Account[] }) { const [accounts, setAccounts] = useState(initialAccounts); const [displayName, setDisplayName] = useState(''); async function handleAdd() { try { const res = await fetch('/api/accounts', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ displayName: displayName || undefined }), }); if (!res.ok) return; const account: Account = await res.json(); setAccounts((prev) => [...prev, account]); setDisplayName(''); } catch {} } return (
setDisplayName(e.target.value)} placeholder="Display name (optional)" className="flex-1 border rounded px-3 py-2 text-sm" />
{accounts.length === 0 ? (

No accounts yet. Add one above to get started.

) : (
{accounts.map((a) => ( ))}
)}
); }