Adds a reusable useTableControls hook and TableControls/SortableTh components, then wires them into all six admin table pages (users, vendors, vessels, sites, accounts, products). Each page now supports a global search bar, clickable sortable column headers with ↑/↓/⇅ indicators, and role/status filter chips — all purely client-side with no URL params or server round-trips. Server pages continue to fetch the full list and pass it as props to a new *-table.tsx Client Component. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { auth } from "@/auth";
|
|
import { db } from "@/lib/db";
|
|
import { hasPermission } from "@/lib/permissions";
|
|
import { redirect } from "next/navigation";
|
|
import { SitesTable } from "./sites-table";
|
|
import type { Metadata } from "next";
|
|
|
|
export const metadata: Metadata = { title: "Sites" };
|
|
|
|
export default async function SitesPage() {
|
|
const session = await auth();
|
|
if (!session?.user) redirect("/login");
|
|
if (!hasPermission(session.user.role, "manage_sites")) redirect("/dashboard");
|
|
|
|
const sites = await db.site.findMany({
|
|
orderBy: { name: "asc" },
|
|
include: {
|
|
_count: { select: { vessels: true, inventory: true } },
|
|
},
|
|
});
|
|
|
|
const canEdit = session.user.role === "ADMIN";
|
|
|
|
return (
|
|
<SitesTable
|
|
canEdit={canEdit}
|
|
sites={sites.map((s) => ({
|
|
id: s.id,
|
|
code: s.code,
|
|
name: s.name,
|
|
address: s.address ?? null,
|
|
latitude: s.latitude ?? null,
|
|
longitude: s.longitude ?? null,
|
|
isActive: s.isActive,
|
|
vesselCount: s._count.vessels,
|
|
inventoryCount: s._count.inventory,
|
|
}))}
|
|
/>
|
|
);
|
|
}
|