From 9522143f51c5bd381c83578a16ee913b11f743b1 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sat, 18 Apr 2026 02:05:39 +0000 Subject: [PATCH] Changes Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com> --- .../forms/form-fields-fill-panel.tsx | 232 ++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 src/components/forms/form-fields-fill-panel.tsx diff --git a/src/components/forms/form-fields-fill-panel.tsx b/src/components/forms/form-fields-fill-panel.tsx new file mode 100644 index 0000000..307fcb3 --- /dev/null +++ b/src/components/forms/form-fields-fill-panel.tsx @@ -0,0 +1,232 @@ +import { useEffect, useState } from "react"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { Textarea } from "@/components/ui/textarea"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; +import { + fetchClients, + fetchHomeowners, + type ClientLite, + type HomeownerLite, + type FormFieldDef, +} from "@/lib/forms-shared"; +import { FL_COUNTIES } from "@/lib/florida"; + +export function FormFieldsFillPanel({ + fields, + values, + onChange, +}: { + fields: FormFieldDef[]; + values: Record; + onChange: (next: Record) => void; +}) { + const [clients, setClients] = useState([]); + const [homeownersByClient, setHomeownersByClient] = useState>({}); + + // Track which client a homeowner field is filtered by (per-field-key) + const [hoClientByField, setHoClientByField] = useState>({}); + + useEffect(() => { + if (fields.some((f) => f.type === "client" || f.type === "homeowner")) { + fetchClients().then(setClients); + } + }, [fields]); + + const set = (key: string, v: string) => onChange({ ...values, [key]: v }); + + const ensureHomeowners = async (clientId: string) => { + if (!clientId || homeownersByClient[clientId]) return; + const hs = await fetchHomeowners(clientId); + setHomeownersByClient((prev) => ({ ...prev, [clientId]: hs })); + }; + + if (fields.length === 0) { + return ( +

+ No fillable fields. Click "Edit fields" to define inputs. +

+ ); + } + + return ( +
+ {fields.map((f) => { + const v = values[f.key] ?? f.default ?? ""; + const labelEl = ( + + ); + if (f.type === "textarea") { + return ( +
+ {labelEl} +