Mirrors the Place-of-Delivery (#19) pattern: an admin clause library that feeds the PO T&C fields as dropdowns. (No "work order" type — POs only, per steer.) - schema + migration: TermsCondition (category enum + text + isActive); the migration seeds the prior TC_DEFAULTS as the starting clauses. - permission manage_terms (Manager + SuperUser + Admin). - admin screen /admin/terms: table + Add/Edit dialogs + activate/deactivate + delete (mirrors /admin/delivery-locations); sidebar link under Administration. - PO forms (new / edit / manager-edit): the five named T&C slots (Delivery / Dispatch / Inspection / Transit Insurance / Payment Terms) become a shared <TermsField> select sourced from active clauses of that category; "Others" stays free text; the fixed boilerplate lines are untouched. - tc* columns stay free-text SNAPSHOTS (export/import unchanged); a current value not among active clauses is preserved as a "(current)" option. - tests: terms CRUD + permission guard + grouping helper (6). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
29 lines
831 B
TypeScript
29 lines
831 B
TypeScript
import { auth } from "@/auth";
|
|
import { db } from "@/lib/db";
|
|
import { hasPermission } from "@/lib/permissions";
|
|
import { redirect } from "next/navigation";
|
|
import { TermsTable } from "./terms-table";
|
|
import type { Metadata } from "next";
|
|
|
|
export const metadata: Metadata = { title: "Terms & Conditions" };
|
|
|
|
export default async function TermsPage() {
|
|
const session = await auth();
|
|
if (!session?.user) redirect("/login");
|
|
if (!hasPermission(session.user.role, "manage_terms")) redirect("/dashboard");
|
|
|
|
const terms = await db.termsCondition.findMany({
|
|
orderBy: [{ category: "asc" }, { isActive: "desc" }, { createdAt: "asc" }],
|
|
});
|
|
|
|
return (
|
|
<TermsTable
|
|
terms={terms.map((t) => ({
|
|
id: t.id,
|
|
category: t.category,
|
|
text: t.text,
|
|
isActive: t.isActive,
|
|
}))}
|
|
/>
|
|
);
|
|
}
|