fetch bug fix
This commit is contained in:
parent
f10dc5148f
commit
a2ec2fa52c
2 changed files with 19 additions and 8 deletions
|
|
@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
|||
import { cookies } from "next/headers";
|
||||
import { directusFetch } from "@/lib/directus";
|
||||
|
||||
const BASE_COLLECTION = "rigs"; // change if your collection name differs
|
||||
const BASE_COLLECTION = "user_rigs";
|
||||
|
||||
async function bearerFromCookies() {
|
||||
// Some Next 15 type defs model cookies() as async—await to satisfy TS in all envs.
|
||||
|
|
|
|||
|
|
@ -163,15 +163,20 @@ export default function RigBuilderClient() {
|
|||
const isGantry = rigTypeVal === "co2_gantry";
|
||||
const isScan = rigTypeVal === "fiber" || rigTypeVal === "uv" || rigTypeVal === "co2_galvo";
|
||||
|
||||
// Initial loads
|
||||
// Initial loads (rig types + existing rigs)
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
const [typesRes, rigsRes] = await Promise.all([
|
||||
apiJson<{ data: { id: number; name: string }[] }>(`/api/options/rig_type`),
|
||||
apiJson<{ data: { id: number | string; label?: string; name?: string }[] }>(`/api/options/user_rig_type`),
|
||||
apiJson<{ data: RigRow[] }>(`/api/my/rigs`),
|
||||
]);
|
||||
setRigTypes(typesRes.data ?? []);
|
||||
|
||||
const mappedTypes: RigType[] = (typesRes?.data ?? []).map((t) => ({
|
||||
id: t.id,
|
||||
name: (t.label ?? t.name ?? String(t.id)) as any,
|
||||
}));
|
||||
setRigTypes(mappedTypes);
|
||||
setRigs(rigsRes.data ?? []);
|
||||
} catch (e: any) {
|
||||
if (!handleAuthError(e)) {
|
||||
|
|
@ -202,12 +207,17 @@ export default function RigBuilderClient() {
|
|||
}
|
||||
|
||||
(async () => {
|
||||
// LASER sources by target (matches settings_* targets), fallback to no target
|
||||
try {
|
||||
// LASER sources by target (matches anonymous form targets)
|
||||
const srcJson = await apiJson<{ data: Option[] }>(
|
||||
const withTarget = await apiJson<{ data: Option[] }>(
|
||||
`/api/options/laser_source?target=${encodeURIComponent(settingsTarget)}`
|
||||
);
|
||||
setSourceOpts(srcJson.data ?? []);
|
||||
let list = withTarget?.data ?? [];
|
||||
if (!list.length) {
|
||||
const fallback = await apiJson<{ data: Option[] }>(`/api/options/laser_source`);
|
||||
list = fallback?.data ?? [];
|
||||
}
|
||||
setSourceOpts(list);
|
||||
} catch (e: any) {
|
||||
if (!handleAuthError(e)) console.error("[laser_source] load failed:", e);
|
||||
setSourceOpts([]);
|
||||
|
|
@ -463,7 +473,7 @@ export default function RigBuilderClient() {
|
|||
</SelectTrigger>
|
||||
<SelectContent position="popper" className="max-h-64 overflow-y-auto z-50 bg-background text-foreground border">
|
||||
<SelectItem value="none">—</SelectItem>
|
||||
{/* Swap to live options if/when exposed by API */}
|
||||
{/* Static until API endpoint for these is exposed */}
|
||||
<SelectItem value="10mm">10 mm</SelectItem>
|
||||
<SelectItem value="14mm">14 mm</SelectItem>
|
||||
<SelectItem value="20mm">20 mm</SelectItem>
|
||||
|
|
@ -483,6 +493,7 @@ export default function RigBuilderClient() {
|
|||
</SelectTrigger>
|
||||
<SelectContent position="popper" className="max-h-64 overflow-y-auto z-50 bg-background text-foreground border">
|
||||
<SelectItem value="none">—</SelectItem>
|
||||
{/* Static until API endpoint for these is exposed */}
|
||||
<SelectItem value="1.5x">1.5×</SelectItem>
|
||||
<SelectItem value="2x">2×</SelectItem>
|
||||
<SelectItem value="3x">3×</SelectItem>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue