From 92ba85c570236e2fbf03567d13245ff93042f196 Mon Sep 17 00:00:00 2001 From: makearmy Date: Mon, 6 Oct 2025 20:46:30 -0400 Subject: [PATCH] submission form cleanup --- components/forms/SettingsSubmit.tsx | 50 +++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/components/forms/SettingsSubmit.tsx b/components/forms/SettingsSubmit.tsx index b86b1c39..f110abae 100644 --- a/components/forms/SettingsSubmit.tsx +++ b/components/forms/SettingsSubmit.tsx @@ -181,6 +181,9 @@ export default function SettingsSubmit({ mode = "create", submissionId, initialV handleSubmit, control, reset, + // ↓↓↓ added setValue & getValues for rehydrate-fix + setValue, + getValues, formState: { isSubmitting }, } = useForm({ defaultValues: { @@ -254,6 +257,48 @@ export default function SettingsSubmit({ mode = "create", submissionId, initialV const apt = useOptions("laser_scan_lens_apt", initialValues?.lens_apt ?? null); const exp = useOptions("laser_scan_lens_exp", initialValues?.lens_exp ?? null); + // 🔧 Re-apply RHF values when options hydrate (fixes stubborn placeholder) + useEffect(() => { + if (!isEdit) return; // only matters in edit-mode + const optionsByName: Record = { + mat: mats.opts, + mat_coat: coats.opts, + mat_color: colors.opts, + mat_opacity: opacs.opts, + laser_soft: soft.opts, + source: srcs.opts, + lens_conf: conf.opts, + lens_apt: apt.opts, + lens_exp: exp.opts, + lens: lens.opts, + }; + const names = Object.keys(optionsByName) as Array; + const current = getValues(); + + names.forEach((name) => { + const cur = current?.[name as string]; + if (cur == null || cur === "") return; + const opts = optionsByName[name] || []; + // if the option exists now (or even if it didn't before), nudge RHF to re-sync + if (!opts.length || opts.some((o) => String(o.id) === String(cur))) { + setValue(name as any, cur, { shouldDirty: false, shouldValidate: false }); + } + }); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [ + isEdit, + mats.opts.length, + coats.opts.length, + colors.opts.length, + opacs.opts.length, + soft.opts.length, + srcs.opts.length, + conf.opts.length, + apt.opts.length, + exp.opts.length, + lens.opts.length, + ]); + // Image files const [photoFile, setPhotoFile] = useState(null); const [screenFile, setScreenFile] = useState(null); @@ -376,7 +421,6 @@ export default function SettingsSubmit({ mode = "create", submissionId, initialV