import { auth } from "@/auth"; import { db } from "@/lib/db"; import { hasPermission } from "@/lib/permissions"; import { redirect } from "next/navigation"; import Link from "next/link"; import { AddVendorButton, EditVendorButton } from "./vendor-form"; import { ConfirmDeleteButton } from "@/components/ui/confirm-delete-button"; import { deleteVendor } from "./actions"; 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" }] }, }, }); return (
| Vendor ID | Name | Contact | Items | Verified | Status | |
|---|---|---|---|---|---|---|
| {vendor.vendorId ?? Pending} | {vendor.name} | {vendor.contacts.length > 0 ? ( <> {vendor.contacts[0].name} {vendor.contacts[0].email && ( {vendor.contacts[0].email} )} {vendor.contacts.length > 1 && ( +{vendor.contacts.length - 1} more )} > ) : "—"} | {vendor._count.vendorPrices > 0 ? vendor._count.vendorPrices : —} | {vendor.isVerified ? "Verified" : "Unverified"} | {vendor.isActive ? "Active" : "Inactive"} |
|