import { useId, useState } from "react"; import type { ApiSettings, LoginResponse } from "../../types"; import { login } from "../../api/auth"; import Button from "../../components/Button"; import Dialog from "../../components/Dialog"; import FormField from "../../components/FormField"; import PasswordField from "../../components/PasswordField"; import DismissibleAlert from "../../components/DismissibleAlert"; export default function LoginModal({ settings, onClose, onLogin, title = "Sign in", message }: { settings: ApiSettings; onClose: () => void; onLogin: (response: LoginResponse) => void; title?: string; message?: string; }) { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [busy, setBusy] = useState(false); const formId = useId(); async function submit(event: React.FormEvent) { event.preventDefault(); setError(""); setBusy(true); try { const response = await login(settings, { email, password }); onLogin(response); onClose(); } catch (err) { setError(err instanceof Error ? err.message : String(err)); } finally { setBusy(false); } } return ( )} >
{message && {message}} {error && {error}} setEmail(e.target.value)} />
); }