settings overhaul and reset
This commit is contained in:
parent
7ef13e56ff
commit
e8ba98aa91
1 changed files with 57 additions and 0 deletions
|
|
@ -181,6 +181,8 @@ export default function SettingsSubmit({ mode = "create", submissionId, initialV
|
|||
handleSubmit,
|
||||
control,
|
||||
reset,
|
||||
setValue, // <-- add
|
||||
getValues, // <-- add
|
||||
formState: { isSubmitting },
|
||||
} = useForm<any>({
|
||||
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<File | null>(null);
|
||||
const [screenFile, setScreenFile] = useState<File | null>(null);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue