32 lines
987 B
TypeScript
32 lines
987 B
TypeScript
// app/rigs/RigBuilderServer.tsx
|
|
import { cookies } from "next/headers";
|
|
import { redirect } from "next/navigation";
|
|
import RigBuilderClient from "./RigBuilderClient";
|
|
import { dxGET } from "@/lib/directus";
|
|
|
|
type Opt = { id: string | number; label: string };
|
|
|
|
function getBearerFromCookies(): string | null {
|
|
const jar = cookies();
|
|
const token = jar.get("ma_at")?.value;
|
|
return token ? `Bearer ${token}` : null;
|
|
}
|
|
|
|
export default async function RigBuilderServer() {
|
|
const bearer = getBearerFromCookies();
|
|
if (!bearer) {
|
|
const next = encodeURIComponent("/rigs");
|
|
redirect(`/auth/sign-in?next=${next}`);
|
|
}
|
|
|
|
const rows = await dxGET<{
|
|
data: Array<{ id: string | number; name?: string }>;
|
|
}>("/items/user_rig_type?fields=id,name&sort=sort", bearer);
|
|
|
|
const rigTypes: Opt[] = (rows?.data ?? []).map((r) => ({
|
|
id: r.id,
|
|
label: r.name ?? String(r.id),
|
|
}));
|
|
|
|
return <RigBuilderClient rigTypes={rigTypes} />;
|
|
}
|