From f334bcba73424582d11a7aa0395f56655f88e741 Mon Sep 17 00:00:00 2001 From: makearmy Date: Sat, 27 Sep 2025 09:03:15 -0400 Subject: [PATCH] more rigbuilder fixes --- app/my/rigs/RigBuilderClient.tsx | 39 ++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/app/my/rigs/RigBuilderClient.tsx b/app/my/rigs/RigBuilderClient.tsx index c0d53199..dfeaf62d 100644 --- a/app/my/rigs/RigBuilderClient.tsx +++ b/app/my/rigs/RigBuilderClient.tsx @@ -5,6 +5,17 @@ import { useForm } from "react-hook-form"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; +function handleAuthError(err: any): boolean { + const status = (err as any)?.status; + const code = (err as any)?.code; + if (status === 401 || code === "TOKEN_EXPIRED") { + const next = encodeURIComponent(window.location.pathname + window.location.search); + window.location.assign(`/auth/sign-in?next=${next}`); + return true; + } + return false; +} + import { useToast } from "@/hooks/use-toast"; import { Input } from "@/components/ui/input"; @@ -101,6 +112,20 @@ export default function RigBuilderClient() { // Options that depend on rig type const [sourceOpts, setSourceOpts] = useState([]); const [softwareOpts, setSoftwareOpts] = useState([]); + + // Load laser software list once (independent of rig type) + useEffect(() => { + (async () => { + try { + const swJson = await apiJson(`/api/options/laser_software`); + const sw = Array.isArray(swJson?.data) ? swJson.data : Array.isArray(swJson) ? swJson : []; + setSoftwareOpts(sw); + } catch (e) { if (!handleAuthError(e)) { + console.error('[laser_software] load failed:', e); + setSoftwareOpts([]); + } + })(); + }, []); const [scanLensOpts, setScanLensOpts] = useState([]); const [focusLensOpts, setFocusLensOpts] = useState([]); @@ -315,7 +340,7 @@ export default function RigBuilderClient() { {/* add scroll so big lists are usable */} - + {rigTypeItems.map((rt) => ( {rt.label} @@ -335,7 +360,7 @@ export default function RigBuilderClient() { - + {sourceOpts.map((o) => ( @@ -356,7 +381,7 @@ export default function RigBuilderClient() { - + {softwareOpts.map((o) => ( @@ -385,7 +410,7 @@ export default function RigBuilderClient() { - + {focusLensOpts.map((o) => ( @@ -410,7 +435,7 @@ export default function RigBuilderClient() { - + {scanLensOpts.map((o) => ( @@ -430,7 +455,7 @@ export default function RigBuilderClient() { - + {/* These can be swapped to real options when you expose them as /api/options/... */} 10 mm @@ -450,7 +475,7 @@ export default function RigBuilderClient() { - + 1.5×