build bug fixes
This commit is contained in:
parent
2c858929e4
commit
bf45c515db
2 changed files with 40 additions and 30 deletions
|
|
@ -1,30 +1,36 @@
|
|||
// app/rigs/page.tsx
|
||||
import RigBuilderServer from "./RigBuilderServer";
|
||||
import RigsListClient from "./RigsListClient";
|
||||
// app/portal/rigs/page.tsx
|
||||
import { cookies } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
import RigsSwitcher from "@/components/portal/RigsSwitcher";
|
||||
|
||||
export default function Page() {
|
||||
return (
|
||||
<div className="p-4 space-y-6">
|
||||
<header>
|
||||
<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>
|
||||
type Opt = { id: string | number; label: string };
|
||||
|
||||
<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>
|
||||
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");
|
||||
}
|
||||
|
||||
{/* 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>
|
||||
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",
|
||||
}
|
||||
);
|
||||
|
||||
// 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} />;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,14 @@ import { cn } from "@/lib/utils";
|
|||
import RigsListClient from "@/app/rigs/RigsListClient";
|
||||
import RigBuilderClient from "@/app/rigs/RigBuilderClient";
|
||||
|
||||
type Opt = { id: string | number; label: string };
|
||||
|
||||
const TABS = [
|
||||
{ key: "my", label: "My Rigs" },
|
||||
{ key: "add", label: "Add Rig" },
|
||||
];
|
||||
|
||||
function Panel({ tab }: { tab: string }) {
|
||||
function Panel({ tab, rigTypes }: { tab: string; rigTypes: Opt[] }) {
|
||||
switch (tab) {
|
||||
case "my":
|
||||
return (
|
||||
|
|
@ -22,7 +24,7 @@ function Panel({ tab }: { tab: string }) {
|
|||
case "add":
|
||||
return (
|
||||
<div className="rounded-md border p-4">
|
||||
<RigBuilderClient />
|
||||
<RigBuilderClient rigTypes={rigTypes} />
|
||||
</div>
|
||||
);
|
||||
default:
|
||||
|
|
@ -30,7 +32,7 @@ function Panel({ tab }: { tab: string }) {
|
|||
}
|
||||
}
|
||||
|
||||
export default function RigsSwitcher() {
|
||||
export default function RigsSwitcher({ rigTypes }: { rigTypes: Opt[] }) {
|
||||
const router = useRouter();
|
||||
const sp = useSearchParams();
|
||||
const active = sp.get("t") || "my";
|
||||
|
|
@ -50,7 +52,9 @@ export default function RigsSwitcher() {
|
|||
onClick={() => setTab(key)}
|
||||
className={cn(
|
||||
"rounded-md border px-3 py-1.5 text-sm transition",
|
||||
active === key ? "bg-primary text-primary-foreground" : "hover:bg-muted"
|
||||
active === key
|
||||
? "bg-primary text-primary-foreground"
|
||||
: "hover:bg-muted"
|
||||
)}
|
||||
>
|
||||
{label}
|
||||
|
|
@ -58,7 +62,7 @@ export default function RigsSwitcher() {
|
|||
))}
|
||||
</div>
|
||||
|
||||
<Panel tab={active} />
|
||||
<Panel tab={active} rigTypes={rigTypes} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue