pelagia-portal/App/app/(portal)/inventory/items/page.tsx
Hardik 478f1d1f9c refactor(items): canonical detail route is /inventory/items/[id]
- /inventory/items uses same ProductsTable as /admin/products
- canManage driven by manage_products permission on both pages
- /inventory/items/[id] is the canonical detail page (same content,
  breadcrumb back to /inventory/items)
- /admin/products/[id] redirects to /inventory/items/[id]
- All ProductsTable name links point to /inventory/items/[id]
- Old items-table.tsx (cart-based browse) retired in favour of shared table

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 06:24:46 +05:30

44 lines
1.4 KiB
TypeScript

import { auth } from "@/auth";
import { db } from "@/lib/db";
import { hasPermission } from "@/lib/permissions";
import { redirect } from "next/navigation";
import { ProductsTable } from "@/app/(portal)/admin/products/products-table";
import type { Metadata } from "next";
export const metadata: Metadata = { title: "Item Catalogue" };
export default async function InventoryItemsPage() {
const session = await auth();
if (!session?.user) redirect("/login");
const products = await db.product.findMany({
where: { isActive: true },
orderBy: { name: "asc" },
include: {
lastVendor: true,
_count: { select: { vendorPrices: true } },
},
});
// canManage lets managers/admins see the Edit/Delete controls even from /inventory/items
const canManage = hasPermission(session.user.role, "manage_products");
return (
<div className="max-w-6xl">
<ProductsTable
canManage={canManage}
products={products.map((p) => ({
id: p.id,
code: p.code,
name: p.name,
description: p.description ?? null,
lastPrice: p.lastPrice !== null ? Number(p.lastPrice) : null,
lastVendorName: p.lastVendor?.name ?? null,
updatedAt: p.updatedAt.toISOString(),
isActive: p.isActive,
vendorPriceCount: p._count.vendorPrices,
}))}
/>
</div>
);
}