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>
33 lines
992 B
TypeScript
33 lines
992 B
TypeScript
import { auth } from "@/auth";
|
|
import { db } from "@/lib/db";
|
|
import { hasPermission } from "@/lib/permissions";
|
|
import { redirect } from "next/navigation";
|
|
import { nextId } from "@/lib/id-generators";
|
|
import { AccountsTable } from "./accounts-table";
|
|
import type { Metadata } from "next";
|
|
|
|
export const metadata: Metadata = { title: "Account Management" };
|
|
|
|
export default async function AdminAccountsPage() {
|
|
const session = await auth();
|
|
if (!session?.user) redirect("/login");
|
|
|
|
if (!hasPermission(session.user.role, "manage_vessels_accounts")) redirect("/dashboard");
|
|
|
|
const accounts = await db.account.findMany({ orderBy: { code: "asc" } });
|
|
|
|
const suggestedCode = nextId("ACC", accounts.map((a) => a.code));
|
|
|
|
return (
|
|
<AccountsTable
|
|
suggestedCode={suggestedCode}
|
|
accounts={accounts.map((a) => ({
|
|
id: a.id,
|
|
code: a.code,
|
|
name: a.name,
|
|
description: a.description ?? null,
|
|
isActive: a.isActive,
|
|
}))}
|
|
/>
|
|
);
|
|
}
|