Replaces the hardcoded PROJECT_CODES array with an admin-managed `ProjectCode` model, mirroring the Delivery Locations pattern (PR #100): - ProjectCode model (unique `code` + isActive) + migration seeding the five previously-hardcoded codes; PO.projectCode stays a free-text snapshot (no FK) so history/exports/imports are unchanged. - manage_project_codes permission (Manager + SuperUser + Admin). - /admin/project-codes CRUD screen (table + Add/Edit + activate/delete) and an Administration sidebar link. - ProjectCodeField now takes `options` from the active codes; the three PO forms + pages fetch them from the DB. Static list removed. - Unit test reworked to the options API; CRUD integration test added; documented in App/CLAUDE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
28 lines
825 B
TypeScript
28 lines
825 B
TypeScript
import { auth } from "@/auth";
|
|
import { db } from "@/lib/db";
|
|
import { hasPermission } from "@/lib/permissions";
|
|
import { redirect } from "next/navigation";
|
|
import { ProjectCodesTable } from "./project-codes-table";
|
|
import type { Metadata } from "next";
|
|
|
|
export const metadata: Metadata = { title: "Project Codes" };
|
|
|
|
export default async function ProjectCodesPage() {
|
|
const session = await auth();
|
|
if (!session?.user) redirect("/login");
|
|
if (!hasPermission(session.user.role, "manage_project_codes")) redirect("/dashboard");
|
|
|
|
const projectCodes = await db.projectCode.findMany({
|
|
orderBy: [{ isActive: "desc" }, { code: "asc" }],
|
|
});
|
|
|
|
return (
|
|
<ProjectCodesTable
|
|
projectCodes={projectCodes.map((c) => ({
|
|
id: c.id,
|
|
code: c.code,
|
|
isActive: c.isActive,
|
|
}))}
|
|
/>
|
|
);
|
|
}
|