From e8ba98aa9107bfe1b03706cf181d0c956b2cdce1 Mon Sep 17 00:00:00 2001 From: makearmy Date: Sun, 5 Oct 2025 21:21:25 -0400 Subject: [PATCH] settings overhaul and reset --- components/forms/SettingsSubmit.tsx | 57 +++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/components/forms/SettingsSubmit.tsx b/components/forms/SettingsSubmit.tsx index 2e7a9f7f..4d38c012 100644 --- a/components/forms/SettingsSubmit.tsx +++ b/components/forms/SettingsSubmit.tsx @@ -181,6 +181,8 @@ export default function SettingsSubmit({ mode = "create", submissionId, initialV handleSubmit, control, reset, + setValue, // <-- add + getValues, // <-- add formState: { isSubmitting }, } = useForm({ defaultValues: { @@ -254,6 +256,61 @@ 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); + // 🔧 Targeted fix: when options hydrate, re-apply current ids so selects adopt them. + useEffect(() => { + if (!initialValues) return; + + type Name = + | "mat" + | "mat_coat" + | "mat_color" + | "mat_opacity" + | "laser_soft" + | "source" + | "lens_conf" + | "lens_apt" + | "lens_exp" + | "lens"; + + const ensure = (name: Name, id?: string | null, opts?: Opt[]) => { + if (!id) return; + if (!opts || opts.length === 0) return; + const curr = getValues(name as any); + // Re-apply if blank OR already equal to the intended id (forces the select to adopt it) + if (curr == null || curr === "" || String(curr) === String(id)) { + setValue(name as any, String(id), { shouldDirty: false, shouldValidate: false }); + } + }; + + ensure("mat", initialValues.mat ?? null, mats.opts); + ensure("mat_coat", initialValues.mat_coat ?? null, coats.opts); + ensure("mat_color", initialValues.mat_color ?? null, colors.opts); + ensure("mat_opacity",initialValues.mat_opacity ?? null, opacs.opts); + + ensure("laser_soft", initialValues.laser_soft ?? null, soft.opts); + ensure("source", initialValues.source ?? null, srcs.opts); + + // Order: source → (conf/apt/exp) → lens + ensure("lens_conf", initialValues.lens_conf ?? null, conf.opts); + ensure("lens_apt", initialValues.lens_apt ?? null, apt.opts); + ensure("lens_exp", initialValues.lens_exp ?? null, exp.opts); + ensure("lens", initialValues.lens ?? null, lens.opts); + }, [ + initialValues, + mats.opts, + coats.opts, + colors.opts, + opacs.opts, + soft.opts, + srcs.opts, + lens.opts, + conf.opts, + apt.opts, + exp.opts, + getValues, + setValue, + ]); + // Image files const [photoFile, setPhotoFile] = useState(null); const [screenFile, setScreenFile] = useState(null);