build bug fixes
This commit is contained in:
parent
bf45c515db
commit
fbe29a5cdc
1 changed files with 34 additions and 18 deletions
|
|
@ -13,24 +13,40 @@ export default async function Page() {
|
|||
}
|
||||
|
||||
const DIRECTUS = (process.env.DIRECTUS_URL || "").replace(/\/$/, "");
|
||||
const res = await fetch(
|
||||
`${DIRECTUS}/items/user_rig_type?fields=id,name&sort=sort`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${ma_at}`,
|
||||
Accept: "application/json",
|
||||
"Cache-Control": "no-store",
|
||||
},
|
||||
cache: "no-store",
|
||||
let rigTypes: Opt[] = [];
|
||||
|
||||
try {
|
||||
const res = await fetch(
|
||||
`${DIRECTUS}/items/user_rig_type?fields=id,name&sort=sort`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${ma_at}`,
|
||||
Accept: "application/json",
|
||||
"Cache-Control": "no-store",
|
||||
},
|
||||
cache: "no-store",
|
||||
}
|
||||
);
|
||||
|
||||
if (res.ok) {
|
||||
const json = await res.json();
|
||||
rigTypes = (json?.data ?? []).map((r: any) => ({
|
||||
id: r.id,
|
||||
label: r.name ?? String(r.id),
|
||||
}));
|
||||
} else {
|
||||
// Optional: log server-side for debugging
|
||||
// console.error("Failed to fetch user_rig_type", res.status);
|
||||
rigTypes = [];
|
||||
}
|
||||
} catch {
|
||||
rigTypes = [];
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="rounded-lg border p-6">
|
||||
<h2 className="mb-4 text-xl font-semibold">Rigs</h2>
|
||||
<RigsSwitcher rigTypes={rigTypes} />
|
||||
</div>
|
||||
);
|
||||
|
||||
// Be resilient: if this fails, just show no options so the page still builds
|
||||
const json = res.ok ? await res.json().catch(() => ({ data: [] })) : { data: [] };
|
||||
const rigTypes: Opt[] = (json?.data ?? []).map((r: any) => ({
|
||||
id: r.id,
|
||||
label: r.name ?? String(r.id),
|
||||
}));
|
||||
|
||||
return <RigsSwitcher rigTypes={rigTypes} />;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue