"use client"; import { useState, useTransition } from "react"; import { useRouter } from "next/navigation"; import { createHarvestLot } from "@/actions/route-trace/lots"; export default function LotCreateForm({ brandId }: { brandId: string }) { const router = useRouter(); const [isPending, startTransition] = useTransition(); const [error, setError] = useState(null); const [notesOpen, setNotesOpen] = useState(false); const [crop_type, setCropType] = useState(""); const [variety, setVariety] = useState(""); const [harvest_date, setHarvestDate] = useState(new Date().toISOString().split("T")[0]); const [field_location, setFieldLocation] = useState(""); const [field_block, setFieldBlock] = useState(""); const [worker_name, setWorkerName] = useState(""); const [packer_name, setPackerName] = useState(""); const [quantity_lbs, setQuantityLbs] = useState(""); const [yield_estimate_lbs, setYieldEstimateLbs] = useState(""); const [yield_unit, setYieldUnit] = useState("lbs"); const [customYieldUnit, setCustomYieldUnit] = useState(""); const [bin_id, setBinId] = useState(""); const [container_id, setContainerId] = useState(""); const [pallets, setPallets] = useState(""); const [notes, setNotes] = useState(""); function handleSubmit(e: React.FormEvent) { e.preventDefault(); setError(null); startTransition(async () => { const result = await createHarvestLot(brandId, { crop_type, variety: variety || undefined, harvest_date, field_location: field_location || undefined, worker_name: worker_name || undefined, packer_name: packer_name || undefined, quantity_lbs: quantity_lbs ? Number(quantity_lbs) : undefined, notes: notes || undefined, bin_id: bin_id || undefined, container_id: container_id || undefined, field_block: field_block || undefined, yield_estimate_lbs: yield_estimate_lbs ? Number(yield_estimate_lbs) : undefined, yield_unit: yield_unit === "custom" ? customYieldUnit.trim() || undefined : yield_unit, pallets: pallets ? Number(pallets) : undefined, }); if (result.success && result.lot) { router.push(`/admin/route-trace/lots/${result.lot.id}`); } else { setError(result.error ?? "Failed to create lot"); } }); } return (
🌱

New Harvest Lot

Quick entry β€” scan or fill in the fields below

{error && (
{error}
)} {/* Required β€” large touch targets for field use */}
setCropType(e.target.value)} placeholder="e.g. Sweet Corn" required className="w-full rounded-xl border border-stone-200 bg-stone-50 px-4 py-4 text-lg font-medium outline-none focus:border-stone-900 focus:bg-white transition-colors" />
setVariety(e.target.value)} placeholder="e.g. Golden Bantam" className="w-full rounded-xl border border-stone-200 bg-stone-50 px-4 py-4 text-lg font-medium outline-none focus:border-stone-900 focus:bg-white transition-colors" />
setHarvestDate(e.target.value)} required className="w-full rounded-xl border border-stone-200 bg-stone-50 px-4 py-4 text-lg font-medium outline-none focus:border-stone-900 focus:bg-white transition-colors" />
{/* Field & Location */}

Field & Location

setFieldLocation(e.target.value)} placeholder="e.g. North Field" required className="w-full rounded-xl border border-stone-200 bg-stone-50 px-4 py-3.5 text-base outline-none focus:border-stone-900 focus:bg-white transition-colors" />
setFieldBlock(e.target.value)} placeholder="e.g. Block A" className="w-full rounded-xl border border-stone-200 bg-stone-50 px-3 py-3 text-sm outline-none focus:border-stone-900 focus:bg-white transition-colors" />
setWorkerName(e.target.value)} placeholder="e.g. Maria S." className="w-full rounded-xl border border-stone-200 bg-stone-50 px-3 py-3 text-sm outline-none focus:border-stone-900 focus:bg-white transition-colors" />
{/* Quantity + Yield */}

Weight & Yield

setQuantityLbs(e.target.value)} placeholder="e.g. 4800" min="0" step="0.01" className="w-full rounded-xl border border-stone-200 bg-stone-50 px-3 py-3.5 text-base outline-none focus:border-stone-900 focus:bg-white transition-colors" />
setYieldEstimateLbs(e.target.value)} placeholder="e.g. 5000" min="0" step="0.01" className="flex-1 px-3 py-3.5 text-base outline-none bg-transparent" />
{yield_unit === "custom" && ( setCustomYieldUnit(e.target.value)} className="mt-1.5 w-full rounded-xl border border-stone-200 bg-stone-50 px-3 py-2 text-sm outline-none focus:border-stone-900 focus:bg-white transition-colors" /> )}
{/* Bin + Container */}

Bin, Container & Pallets

setBinId(e.target.value)} placeholder="e.g. BIN-001" className="w-full rounded-xl border border-stone-200 bg-stone-50 px-3 py-3 text-sm outline-none focus:border-stone-900 focus:bg-white transition-colors" />
setContainerId(e.target.value)} placeholder="e.g. CONT-A42" className="w-full rounded-xl border border-stone-200 bg-stone-50 px-3 py-3 text-sm outline-none focus:border-stone-900 focus:bg-white transition-colors" />
setPallets(e.target.value)} placeholder="e.g. 4" min="0" className="w-full rounded-xl border border-stone-200 bg-stone-50 px-3 py-3 text-sm outline-none focus:border-stone-900 focus:bg-white transition-colors" />
setPackerName(e.target.value)} placeholder="e.g. Jose R." className="w-full rounded-xl border border-stone-200 bg-stone-50 px-3 py-3 text-sm outline-none focus:border-stone-900 focus:bg-white transition-colors" />
{/* Notes β€” collapsible */}
{notesOpen && (