import { useForm } from '@tanstack/react-form'; import { toast } from 'sonner'; import z from 'zod'; import { Button } from '@/components/ui/button'; import { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from '@/components/ui/dialog'; import { Field, FieldError, FieldLabel, } from '@/components/ui/field'; import { Input, } from '@/components/ui/input'; const formSchema = z.object({ email: z.string(), nickname: z.string().min(1), subtitle: z.string().min(1), }); export function EditProfileDialog() { const form = useForm({ defaultValues: { email: '', nickname: '', subtitle: '', }, validators: { onBlur: formSchema, }, onSubmit: async ({ value, }) => { try { toast( {JSON.stringify(value, null, 2)}, ); } catch (error) { console.error('Form submission error', error); toast.error('Failed to submit the form. Please try again.'); } }, }); return (
{ e.preventDefault(); e.stopPropagation(); void form.handleSubmit(); }} > 编辑个人资料 Email form.setFieldValue('email', e.target.value)} /> 昵称 form.setFieldValue('nickname', e.target.value)} /> 副标题 form.setFieldValue('subtitle', e.target.value)} />
); }