এই পেজটি এখনো বাংলা ভাষায় পাওয়া যায় না, তাই ইংরেজিতে দেখানো হচ্ছে।
Admin pages, permissions and settings
Server-component pages with permission guards, server actions that validate and log, and settings fields stored for you.
app/admin/page.tsx→/admin/<id>;app/admin/<sub>/page.tsx→/admin/<id>/<sub>. Declare the root inroutesand add anaventry.- Guard every page with
requireAdminPage("<group>.<action>"), every server action withrequirePermission(...), and check read vs write withcan(user, key). - Log every mutation with
logActivity({ userId, action, entityType: "plugin:<id>", entityId, meta }). - Use the admin kit (
PageHeader,Panel,StatCard, DataTable v2) and colour tokens — never hard-coded colours.
import { requireAdminPage } from "@/lib/auth/guards";
import { prisma } from "@/lib/prisma";
import { PageHeader, Panel, StatCard, fmtDate } from "@/components/admin/ui";
import { DataTable } from "@/components/admin/table/DataTable";
export const dynamic = "force-dynamic";
export default async function SiteVisitsPage({ searchParams }: { searchParams: Promise<Record<string, string | undefined>> }) {
await requireAdminPage("sitevisits.view");
const sp = await searchParams;
const rows = await prisma.siteVisit.findMany({ orderBy: { plannedAt: "asc" }, take: 200 });
return (
<>
<PageHeader title="Site visits" description="Visits planned from sent quotations." />
<div className="mb-6 grid gap-4 sm:grid-cols-2">
<StatCard label="Planned" value={rows.filter((r) => r.status === "PLANNED").length} />
<StatCard label="Total" value={rows.length} tone="info" />
</div>
<Panel title="Visits">
<DataTable
rows={rows}
basePath="/admin/site-visits"
tableId="site-visits"
searchParams={sp}
columns={[
{ key: "customer", header: "Customer", render: (r) => r.customerName },
{ key: "when", header: "When", render: (r) => fmtDate(r.plannedAt) + " · " + r.slot },
{ key: "status", header: "Status", render: (r) => r.status },
]}
empty="No visits yet — they appear when a quotation is sent."
/>
</Panel>
</>
);
}"use server";
import { revalidatePath } from "next/cache";
import { z } from "zod";
import { requirePermission, logActivity, ForbiddenError } from "@/lib/auth/guards";
import { callPluginAction } from "@/lib/plugins/loader";
import type { ActionResult } from "@/components/admin/actions";
export async function completeVisit(id: string): Promise<ActionResult> {
try {
const user = await requirePermission("sitevisits.manage");
const parsed = z.string().min(10).max(40).safeParse(id);
if (!parsed.success) return { ok: false, error: "Invalid id" };
await callPluginAction("site-visits", "complete", parsed.data);
await logActivity({ userId: user.id, action: "updated", entityType: "plugin:site-visits", entityId: parsed.data, meta: { status: "DONE" } });
revalidatePath("/admin/site-visits");
return { ok: true, message: "Visit completed" };
} catch (e) {
return { ok: false, error: e instanceof ForbiddenError ? e.message : "Could not update the visit" };
}
}Settings
Fields declared in module.json → settings are edited by admins at /admin/plugins/<id>/settings and stored in one Setting row (plugin_<id_with_underscores>). Read them with getPluginSettings<T>(id) — manifest defaults merged with saved values. Secrets such as API tokens do not belong in settings fields: use .env or encryptSecret / decryptSecret from @/lib/secrets with pluginStore.
Written from: docs/PLUGIN-DEVELOPER-GUIDE.md, src/lib/plugins/sdk.ts, src/lib/auth/guards.ts, modules/example-checklist/app/admin/page.tsx, modules/example-checklist/app/admin/actions.ts