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>
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
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 { VendorsTable } from "./vendors-table";
|
|
import type { Metadata } from "next";
|
|
|
|
export const metadata: Metadata = { title: "Vendor Registry" };
|
|
|
|
export default async function AdminVendorsPage() {
|
|
const session = await auth();
|
|
if (!session?.user) redirect("/login");
|
|
if (!hasPermission(session.user.role, "manage_vendors")) redirect("/dashboard");
|
|
|
|
const vendors = await db.vendor.findMany({
|
|
orderBy: { name: "asc" },
|
|
include: {
|
|
_count: { select: { vendorPrices: true } },
|
|
contacts: { orderBy: [{ isPrimary: "desc" }, { createdAt: "asc" }] },
|
|
},
|
|
});
|
|
|
|
const suggestedVendorId = nextId("VND", vendors.map((v) => v.vendorId));
|
|
|
|
return (
|
|
<VendorsTable
|
|
suggestedVendorId={suggestedVendorId}
|
|
vendors={vendors.map((v) => ({
|
|
id: v.id,
|
|
vendorId: v.vendorId,
|
|
name: v.name,
|
|
gstin: v.gstin ?? null,
|
|
address: v.address ?? null,
|
|
pincode: v.pincode ?? null,
|
|
isVerified: v.isVerified,
|
|
isActive: v.isActive,
|
|
itemCount: v._count.vendorPrices,
|
|
contacts: v.contacts.map((c) => ({
|
|
name: c.name,
|
|
role: c.role ?? "",
|
|
mobile: c.mobile ?? "",
|
|
email: c.email ?? "",
|
|
isPrimary: c.isPrimary,
|
|
})),
|
|
}))}
|
|
/>
|
|
);
|
|
}
|