RigBuilder Form Fix

This commit is contained in:
makearmy 2025-09-27 08:34:42 -04:00
parent 12143cd4ce
commit fcb0123ba3

View file

@ -50,10 +50,20 @@ const RIG_TARGET_MAP: Record<string, string> = {
co2_gantry: "settings_co2gan",
};
// Builder rig_type -> settings form target expected by options API
const SETTINGS_TARGET_MAP: Record<string, string> = {
fiber: "settings_fiber",
co2_gantry: "settings_co2gan",
co2_galvo: "settings_co2gal",
uv: "settings_uv",
};
async function apiJson<T>(url: string, init?: RequestInit): Promise<T> {
const res = await fetch(url, {
...init,
headers: { "Content-Type": "application/json", ...(init?.headers || {}) },
cache: "no-store",
credentials: "include",
cache: "no-store",
});
if (!res.ok) {
@ -121,7 +131,8 @@ export default function RigBuilderClient() {
const rigTypeVal = watch("rig_type");
const rigTarget = RIG_TARGET_MAP[rigTypeVal ?? ""] || "";
const isGantry = rigTypeVal === "co2_gantry";
const settingsTarget = SETTINGS_TARGET_MAP[rigTypeVal ?? ""] ?? "";const isGantry = rigTypeVal === "co2_gantry";
const isScan = rigTypeVal === "fiber" || rigTypeVal === "uv" || rigTypeVal === "co2_galvo";
// Initial loads
@ -129,7 +140,7 @@ export default function RigBuilderClient() {
(async () => {
try {
const [typesRes, rigsRes] = await Promise.all([
apiJson<{ data: { id: number; name: string }[] }>("/api/options/user_rig_type"),
apiJson<{ data: { id: number; name: string }[] }>("/api/options/rig_type"),
apiJson<{ data: RigRow[] }>("/api/my/rigs"),
]);
setRigTypes(typesRes.data);
@ -162,7 +173,7 @@ export default function RigBuilderClient() {
(async () => {
try {
// laser sources (by target)
const src = await apiJson<{ data: Option[] }>(`/api/options/laser_source?target=${encodeURIComponent(rigTarget)}`);
const src = await apiJson<{ data: Option[] }>(`/api/options/laser_source?target=${settingsTarget}`);
setSourceOpts(src.data ?? []);
} catch {
setSourceOpts([]);
@ -170,7 +181,7 @@ export default function RigBuilderClient() {
try {
// software (generic list; if you have target-aware, swap the endpoint)
const soft = await apiJson<{ data: Option[] }>(`/api/options/laser_software`);
const soft = await apiJson<{ data: Option[] }>(`/api/options/laser_soft`);
setSoftwareOpts(soft.data ?? []);
} catch {
setSoftwareOpts([]);
@ -178,7 +189,7 @@ export default function RigBuilderClient() {
if (isScan) {
try {
const lenses = await apiJson<{ data: Option[] }>(`/api/options/lens?target=${encodeURIComponent(rigTarget)}`);
const lenses = await apiJson<{ data: Option[] }>(`/api/options/lens?target=${settingsTarget}`);
// server already formats "110x110mm (F160)"; keep but ensure scroll
setScanLensOpts(lenses.data ?? []);
} catch {