new builds/id page
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Button, Field, Input } from "@/components/ui/form";
|
||||
|
||||
export default function AdminBetaInvitesPage() {
|
||||
const [dryRun, setDryRun] = useState(true);
|
||||
const [limit, setLimit] = useState("1");
|
||||
const [tokenMinutes, setTokenMinutes] = useState("30");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [result, setResult] = useState<any>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
async function runInvites() {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
setResult(null);
|
||||
|
||||
try {
|
||||
const qs = new URLSearchParams({
|
||||
dryRun: String(dryRun),
|
||||
limit: String(limit || "0"),
|
||||
tokenMinutes: String(tokenMinutes || "30"),
|
||||
});
|
||||
|
||||
const res = await fetch(`/api/admin/beta-invites?${qs.toString()}`, {
|
||||
method: "POST",
|
||||
});
|
||||
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) throw new Error(data?.message || data?.error || "Request failed");
|
||||
|
||||
setResult(data);
|
||||
} catch (e: any) {
|
||||
setError(e?.message ?? "Failed");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-xl font-semibold">Send Beta Invites</h1>
|
||||
<p className="mt-1 text-sm text-zinc-400">
|
||||
Runs the backend batch invite sender (uses your email templates + tracking).
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="rounded-lg border border-zinc-900 bg-zinc-950 p-4 space-y-4">
|
||||
<label className="flex items-center gap-2 text-sm text-zinc-200">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={dryRun}
|
||||
onChange={(e) => setDryRun(e.target.checked)}
|
||||
/>
|
||||
Dry run (do everything except actually send)
|
||||
</label>
|
||||
|
||||
<div className="grid gap-4 md:grid-cols-3">
|
||||
<Field label="Limit" htmlFor="limit">
|
||||
<Input id="limit" value={limit} onChange={(e) => setLimit(e.target.value)} />
|
||||
</Field>
|
||||
|
||||
<Field label="Token minutes" htmlFor="tokenMinutes">
|
||||
<Input
|
||||
id="tokenMinutes"
|
||||
value={tokenMinutes}
|
||||
onChange={(e) => setTokenMinutes(e.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
|
||||
<Button onClick={runInvites} disabled={loading}>
|
||||
{loading ? "Running…" : "Send Beta Invites"}
|
||||
</Button>
|
||||
|
||||
{error && (
|
||||
<div className="rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-sm text-red-200">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{result && (
|
||||
<pre className="overflow-auto rounded-md border border-zinc-800 bg-black/40 p-3 text-xs text-zinc-200">
|
||||
{JSON.stringify(result, null, 2)}
|
||||
</pre>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -29,6 +29,8 @@ const navItems = [
|
||||
{ label: "Settings", href: "/admin/settings", icon: <Settings className="h-4 w-4" /> },
|
||||
{ label: "List Emails", href: "/admin/email", icon: <LucideMail className="h-4 w-4" /> },
|
||||
{ label: "Send an Email", href: "/admin/email/send", icon: <LucideMail className="h-4 w-4" /> },
|
||||
{ label: "Beta Invites", href: "/admin/beta-invites", icon: <LucideMail className="h-4 w-4" /> },
|
||||
|
||||
];
|
||||
|
||||
export default function AdminLayout({
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
const API_BASE_URL =
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:8080";
|
||||
|
||||
// POST /api/admin/beta-invites?dryRun=true&limit=10&tokenMinutes=30
|
||||
export async function POST(req: Request) {
|
||||
const token = cookies().get("bb_access_token")?.value;
|
||||
|
||||
if (!token) {
|
||||
return NextResponse.json({ error: "Missing admin token" }, { status: 401 });
|
||||
}
|
||||
|
||||
const url = new URL(req.url);
|
||||
const dryRun = url.searchParams.get("dryRun") ?? "true";
|
||||
const limit = url.searchParams.get("limit") ?? "0";
|
||||
const tokenMinutes = url.searchParams.get("tokenMinutes") ?? "30";
|
||||
|
||||
const upstream = `${API_BASE_URL}/api/v1/admin/beta/invites/send?dryRun=${dryRun}&limit=${limit}&tokenMinutes=${tokenMinutes}`;
|
||||
|
||||
const res = await fetch(upstream, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
const text = await res.text();
|
||||
return new NextResponse(text, {
|
||||
status: res.status,
|
||||
headers: { "Content-Type": res.headers.get("content-type") ?? "application/json" },
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
const API_BASE_URL =
|
||||
process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:8080";
|
||||
|
||||
export default async function BuildBreakdownPage({
|
||||
params,
|
||||
}: {
|
||||
params: { buildId: string };
|
||||
}) {
|
||||
// You may need to add/confirm this endpoint in backend:
|
||||
// GET /api/v1/builds/{uuid}
|
||||
const res = await fetch(`${API_BASE_URL}/api/v1/builds/${params.buildId}`, {
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
if (res.status === 404) return notFound();
|
||||
|
||||
const build = await res.json().catch(() => null);
|
||||
if (!build) return notFound();
|
||||
|
||||
return (
|
||||
<main className="mx-auto max-w-6xl px-4 py-10">
|
||||
<Link href="/builds" className="text-sm text-zinc-400 hover:text-zinc-200">
|
||||
← Back to Community Builds
|
||||
</Link>
|
||||
|
||||
<div className="mt-6 rounded-lg border border-zinc-900 bg-zinc-950/60 p-6">
|
||||
<h1 className="text-2xl font-semibold text-zinc-50">
|
||||
{build.title ?? "Untitled build"}
|
||||
</h1>
|
||||
|
||||
{build.description && (
|
||||
<p className="mt-2 text-sm text-zinc-400">{build.description}</p>
|
||||
)}
|
||||
|
||||
<div className="mt-6">
|
||||
<h2 className="text-sm font-semibold text-zinc-200">Parts</h2>
|
||||
|
||||
{/* Adjust keys to match your API payload */}
|
||||
<div className="mt-3 space-y-2">
|
||||
{(build.items ?? build.buildItems ?? []).map((it: any) => (
|
||||
<div
|
||||
key={it.uuid ?? it.id}
|
||||
className="flex items-center justify-between rounded-md border border-zinc-900 bg-black/30 px-3 py-2"
|
||||
>
|
||||
<div>
|
||||
<div className="text-sm text-zinc-100">
|
||||
{it.product?.name ?? it.name ?? "Part"}
|
||||
</div>
|
||||
<div className="text-xs text-zinc-500">
|
||||
{it.slot ?? it.partRole ?? "—"}
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-xs text-zinc-400">
|
||||
x{it.quantity ?? 1}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -38,6 +38,8 @@ const defaultNavItems: AdminNavItem[] = [
|
||||
{ label: "Settings", href: "/admin/settings", icon: <Settings className="h-4 w-4" /> },
|
||||
{ label: "Manage Emails", href: "/admin/email/manage", icon: <LucideMail className="h-4 w-4" /> },
|
||||
{ label: "Send an Email", href: "/admin/email/send", icon: <LucideMail className="h-4 w-4" /> },
|
||||
{ label: "Beta Invites", href: "/admin/beta-invites", icon: <LucideMail className="h-4 w-4" />,
|
||||
},
|
||||
];
|
||||
|
||||
export default function AdminLeftNavigation({
|
||||
|
||||
+4
-1
@@ -18,6 +18,9 @@ const PUBLIC_FILE =
|
||||
export function middleware(req: NextRequest) {
|
||||
const { pathname } = req.nextUrl;
|
||||
|
||||
console.log("LAUNCH_ONLY_ROOT:", process.env.NEXT_PUBLIC_LAUNCH_ONLY_ROOT);
|
||||
|
||||
|
||||
// =========================
|
||||
// 1) Admin gate (always on)
|
||||
// =========================
|
||||
@@ -55,10 +58,10 @@ if (pathname.startsWith("/admin")) {
|
||||
|
||||
if (ALWAYS_ALLOW.has(pathname)) return NextResponse.next();
|
||||
|
||||
|
||||
return NextResponse.rewrite(new URL("/404", req.url));
|
||||
}
|
||||
|
||||
|
||||
` 1`
|
||||
export const config = {
|
||||
matcher: [
|
||||
|
||||
Reference in New Issue
Block a user