build bug fixes
This commit is contained in:
parent
fbe29a5cdc
commit
387c70bf56
2 changed files with 61 additions and 50 deletions
|
|
@ -1,13 +1,46 @@
|
||||||
// app/portal/rigs/page.tsx
|
// app/portal/rigs/page.tsx
|
||||||
|
import { cookies } from "next/headers";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
import RigsSwitcher from "@/components/portal/RigsSwitcher";
|
import RigsSwitcher from "@/components/portal/RigsSwitcher";
|
||||||
|
|
||||||
export const metadata = { title: "MakerDash • Rigs" };
|
type Opt = { id: string | number; label: string };
|
||||||
|
|
||||||
|
export default async function Page() {
|
||||||
|
const jar = await cookies(); // Next 15: async cookies()
|
||||||
|
const ma_at = jar.get("ma_at")?.value;
|
||||||
|
if (!ma_at) redirect("/auth/sign-in?next=/portal/rigs");
|
||||||
|
|
||||||
|
const DIRECTUS = (process.env.DIRECTUS_URL || "").replace(/\/$/, "");
|
||||||
|
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),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// fall back to empty
|
||||||
|
}
|
||||||
|
|
||||||
export default function RigsPortalPage() {
|
|
||||||
return (
|
return (
|
||||||
<div className="rounded-lg border p-6">
|
<div className="rounded-lg border p-6">
|
||||||
<h2 className="mb-4 text-xl font-semibold">Rigs</h2>
|
<h2 className="mb-4 text-xl font-semibold">Rigs</h2>
|
||||||
<RigsSwitcher />
|
<RigsSwitcher rigTypes={rigTypes} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,52 +1,30 @@
|
||||||
// app/portal/rigs/page.tsx
|
// app/rigs/page.tsx
|
||||||
import { cookies } from "next/headers";
|
import RigBuilderServer from "./RigBuilderServer";
|
||||||
import { redirect } from "next/navigation";
|
import RigsListClient from "./RigsListClient";
|
||||||
import RigsSwitcher from "@/components/portal/RigsSwitcher";
|
|
||||||
|
|
||||||
type Opt = { id: string | number; label: string };
|
|
||||||
|
|
||||||
export default async function Page() {
|
|
||||||
const jar = await cookies(); // Next 15: async
|
|
||||||
const ma_at = jar.get("ma_at")?.value;
|
|
||||||
if (!ma_at) {
|
|
||||||
redirect("/auth/sign-in?next=/portal/rigs");
|
|
||||||
}
|
|
||||||
|
|
||||||
const DIRECTUS = (process.env.DIRECTUS_URL || "").replace(/\/$/, "");
|
|
||||||
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 = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
export default function Page() {
|
||||||
return (
|
return (
|
||||||
<div className="rounded-lg border p-6">
|
<div className="p-4 space-y-6">
|
||||||
<h2 className="mb-4 text-xl font-semibold">Rigs</h2>
|
<header>
|
||||||
<RigsSwitcher rigTypes={rigTypes} />
|
<h1 className="text-2xl font-bold mb-1">Rigs</h1>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Manage rigs used when submitting settings.
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div className="grid gap-6 md:grid-cols-2">
|
||||||
|
{/* Left: existing rigs */}
|
||||||
|
<section>
|
||||||
|
<h2 className="text-lg font-semibold mb-2">My Rigs</h2>
|
||||||
|
<RigsListClient />
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{/* Right: create a new rig (server-provided rig types) */}
|
||||||
|
<section>
|
||||||
|
<h2 className="text-lg font-semibold mb-2">Create Rig</h2>
|
||||||
|
<RigBuilderServer />
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue