kanban-dev-webapp/src/app/admin/projects/[projectId]/page.tsx

57 lines
No EOL
1.8 KiB
TypeScript

import { notFound } from "next/navigation";
import { AppShell } from "@/components/shell/app-shell";
import { TopBar } from "@/components/shell/top-bar";
import { IngestPanel } from "@/components/admin/ingest-panel";
import { getAdminPb } from "@/lib/pb/admin";
import type { ProjectRecord } from "@/lib/pb/types";
/**
* The admin layout has already refused anyone who is not the owner.
*
* `webhook_secret` is read here but only its presence crosses into the client
* component — never the value. PocketBase rules are record-level and cannot
* hide one field, so stripping it is this page's job.
*/
export default async function ProjectAdminPage({
params,
}: {
params: Promise<{ projectId: string }>;
}) {
const { projectId } = await params;
const pb = await getAdminPb();
let project: ProjectRecord;
try {
project = await pb.collection("projects").getOne<ProjectRecord>(projectId);
} catch {
notFound();
}
const commits = await pb
.collection("commits")
.getList(1, 1, { filter: `project = "${projectId}"`, fields: "id" });
const appUrl = process.env.NEXT_PUBLIC_APP_URL ?? "http://localhost:3000";
return (
<AppShell role="owner" currentPath="/admin/projects">
<TopBar title={project.name} subtitle="Project settings" />
<div className="flex-1 overflow-y-auto p-6">
<div className="mx-auto max-w-2xl">
<IngestPanel
projectId={project.id}
repoOwner={project.repo_owner}
repoName={project.repo_name}
hasSecret={Boolean(project.webhook_secret)}
webhookUrl={`${appUrl}/api/webhooks/forgejo/${project.id}`}
lastIngestAt={project.last_ingest_at}
commitCount={commits.totalItems}
/>
</div>
</div>
</AppShell>
);
}