"use client"; import * as React from "react"; import { useRouter } from "next/navigation"; import { updateProfileName } from "@/actions/account"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Field, Hint, Label } from "@/components/ui/label"; import { Alert } from "@/components/ui/alert"; export function ProfileNameForm({ name }: { name: string }) { const router = useRouter(); const [value, setValue] = React.useState(name); const [error, setError] = React.useState(null); const [saved, setSaved] = React.useState(false); const [pending, startTransition] = React.useTransition(); const dirty = value.trim() !== name; return (
{ e.preventDefault(); setError(null); setSaved(false); startTransition(async () => { const res = await updateProfileName(value); if (!res.ok) { setError(res.error); return; } setSaved(true); router.refresh(); }); }} > {error ? {error} : null} {saved ? Name updated. : null}
setValue(e.target.value)} maxLength={80} autoComplete="name" className="sm:max-w-sm" />
Shown in the dashboard and in emails we send you.
); }