"use client"; import { useEffect, useState, useTransition } from "react"; import { createUser } from "@/app/actions"; import FormDialogShell, { Field, inputClass } from "./form-dialog-shell"; type Props = { open: boolean; onClose: () => void; }; export default function CreateUserDialog({ open, onClose }: Props) { const [pending, startTransition] = useTransition(); const [error, setError] = useState(null); const [fUsername, setFUsername] = useState(""); const [fPassword, setFPassword] = useState(""); const [tUsername, setTUsername] = useState(""); const [tPassword, setTPassword] = useState(""); useEffect(() => { if (open) { setFUsername(""); setFPassword(""); setTUsername(""); setTPassword(""); setError(null); } }, [open]); function submit() { if (!fUsername.trim() || !fPassword || !tUsername.trim() || !tPassword) { setError("All fields are required"); return; } setError(null); startTransition(async () => { const result = await createUser({ f_username: fUsername.trim(), f_password: fPassword, t_username: tUsername.trim(), t_password: tPassword, }); if (result.ok) { onClose(); } else { setError(result.error); } }); } return ( setFUsername(e.target.value)} disabled={pending} autoFocus autoComplete="off" spellCheck={false} className={inputClass} /> setFPassword(e.target.value)} disabled={pending} autoComplete="off" spellCheck={false} className={inputClass} /> setTUsername(e.target.value)} disabled={pending} autoComplete="off" spellCheck={false} className={inputClass} /> setTPassword(e.target.value)} disabled={pending} autoComplete="off" spellCheck={false} className={inputClass} /> ); }