"use client"; import { useState } from "react"; import { useQuery } from "@tanstack/react-query"; import { UserPlus, RefreshCw } from "lucide-react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/Card"; import { Table, TableHead, TableBody, TableRow, Th, Td, EmptyState } from "@/components/ui/Table"; import { Badge } from "@/components/ui/Badge"; import { Button } from "@/components/ui/Button"; import { Input } from "@/components/ui/Input"; import { formatDate } from "@/lib/utils"; import api from "@/lib/api"; import type { Lead } from "@/types"; const statusVariant: Record = { NEW: "muted", CONTACTED: "default", INTERESTED: "warning", CONVERTED: "success", LOST: "danger", }; export default function LeadsPage() { const [search, setSearch] = useState(""); const { data, isLoading, refetch } = useQuery({ queryKey: ["leads", search], queryFn: async () => { const params = new URLSearchParams({ limit: "50" }); if (search) params.set("search", search); const res = await api.get(`/api/v1/leads?${params}`); const d = res.data; return Array.isArray(d) ? d : d.data ?? []; }, }); const leads = data ?? []; return (

Leads

Prospective customers pipeline

{/* Status summary */}
{Object.entries(statusVariant).map(([status]) => { const count = leads.filter(l => l.status === status).length; return count > 0 ? (

{count}

{status}

) : null; })}
All Leads ({leads.length}) setSearch(e.target.value)} className="max-w-xs" />
{isLoading ? ( ) : leads.length === 0 ? ( } /> ) : ( leads.map((lead) => ( )) )}
Name Phone Email Address Status Assigned To Added Loading...{lead.firstName} {lead.lastName} {lead.phone} {lead.email ?? "—"} {lead.address ?? "—"} {lead.status} {lead.assignedTo ? `${lead.assignedTo.firstName} ${lead.assignedTo.lastName}` : "—"} {formatDate(lead.createdAt)}
); }