import React from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { Search, MoreHorizontal, UserCheck, UserX, Mail } from "lucide-react"; import { fetchServer } from "@/lib/api"; interface Vendor { _id: string; username: string; email?: string; storeId?: string; pgpKey?: string; createdAt?: string; currentToken?: string; isAdmin?: boolean; } export default async function AdminVendorsPage() { let vendors: Vendor[] = []; let error: string | null = null; try { vendors = await fetchServer("/admin/vendors"); } catch (err) { console.error("Failed to fetch vendors:", err); error = "Failed to load vendors"; } if (error) { return (

All Vendors

Manage vendor accounts and permissions

{error}

); } const activeVendors = vendors.filter(v => v.currentToken); const adminVendors = vendors.filter(v => v.isAdmin); const suspendedVendors = vendors.filter(v => !v.currentToken); return (

All Vendors

Manage vendor accounts and permissions

{/* Stats Cards */}
Total Vendors
{vendors.length}

Registered vendors

Active Vendors
{activeVendors.length}

{vendors.length > 0 ? Math.round((activeVendors.length / vendors.length) * 100) : 0}% active rate

Suspended
{suspendedVendors.length}

{vendors.length > 0 ? Math.round((suspendedVendors.length / vendors.length) * 100) : 0}% suspension rate

Admin Users
{adminVendors.length}

Administrative access

{/* Search and Filters */}
Vendor Management View and manage all vendor accounts
Vendor Store Status Join Date Orders Revenue Actions {vendors.map((vendor) => (
{vendor.username}
{vendor.email || 'No email'}
{vendor.storeId || 'No store'}
{vendor.currentToken ? "active" : "suspended"} {vendor.isAdmin && ( Admin )}
{vendor.createdAt ? new Date(vendor.createdAt).toLocaleDateString() : 'N/A'} N/A N/A
))}
); }