"use client" import * as React from "react" import Form from "next/form" import { toast } from "sonner" import { Button } from "@/registry/new-york-v4/ui/button" import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/registry/new-york-v4/ui/card" import { Field, FieldDescription, FieldError, FieldGroup, FieldLabel, } from "@/registry/new-york-v4/ui/field" import { Input } from "@/registry/new-york-v4/ui/input" import { InputGroup, InputGroupAddon, InputGroupText, InputGroupTextarea, } from "@/registry/new-york-v4/ui/input-group" import { Spinner } from "@/registry/new-york-v4/ui/spinner" import { demoFormAction } from "./form-next-demo-action" import { type FormState } from "./form-next-demo-schema" export default function FormNextDemo() { const [formState, formAction, pending] = React.useActionState< FormState, FormData >(demoFormAction, { values: { title: "", description: "", }, errors: null, success: false, }) const [descriptionLength, setDescriptionLength] = React.useState(0) React.useEffect(() => { if (formState.success) { toast("Thank you for your feedback", { description: "We'll review your report and get back to you soon.", }) } }, [formState.success]) React.useEffect(() => { setDescriptionLength(formState.values.description.length) }, [formState.values.description]) return ( Bug Report Help us improve by reporting bugs you encounter.
Bug Title {formState.errors?.title && ( {formState.errors.title[0]} )} Description setDescriptionLength(e.target.value.length)} /> {descriptionLength}/100 characters Include steps to reproduce, expected behavior, and what actually happened. {formState.errors?.description && ( {formState.errors.description[0]} )}
) }