v0.2.1 — Fix add plant button not submitting

This commit is contained in:
Bonna Moon
2026-06-15 17:36:46 -05:00
parent 5938c6346e
commit ed4a50dae9

View File

@@ -1,6 +1,6 @@
"use client"; "use client";
import { useState, useRef, useEffect } from "react"; import { useState } from "react";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod"; import { zodResolver } from "@hookform/resolvers/zod";
@@ -39,7 +39,6 @@ export function AddPlantButton() {
const [suggestions, setSuggestions] = useState<PlantSuggestion[]>([]); const [suggestions, setSuggestions] = useState<PlantSuggestion[]>([]);
const [showSuggestions, setShowSuggestions] = useState(false); const [showSuggestions, setShowSuggestions] = useState(false);
const [category, setCategory] = useState<PlantCategory>("CANOPY_TREE"); const [category, setCategory] = useState<PlantCategory>("CANOPY_TREE");
const nameRef = useRef<HTMLInputElement>(null);
const router = useRouter(); const router = useRouter();
const { toast } = useToast(); const { toast } = useToast();
@@ -113,13 +112,13 @@ export function AddPlantButton() {
<Label htmlFor="commonName">What plant is it? *</Label> <Label htmlFor="commonName">What plant is it? *</Label>
<Input <Input
id="commonName" id="commonName"
ref={nameRef}
placeholder="Start typing — apple, comfrey, zinnia…" placeholder="Start typing — apple, comfrey, zinnia…"
value={form.watch("commonName") ?? ""} autoComplete="off"
onChange={(e) => onNameChange(e.target.value)} {...form.register("commonName", {
onChange: (e) => onNameChange(e.target.value),
})}
onBlur={() => setTimeout(() => setShowSuggestions(false), 150)} onBlur={() => setTimeout(() => setShowSuggestions(false), 150)}
onFocus={() => suggestions.length > 0 && setShowSuggestions(true)} onFocus={() => suggestions.length > 0 && setShowSuggestions(true)}
autoComplete="off"
/> />
{form.formState.errors.commonName && ( {form.formState.errors.commonName && (
<p className="text-xs text-destructive">{form.formState.errors.commonName.message}</p> <p className="text-xs text-destructive">{form.formState.errors.commonName.message}</p>