'use client'; import { useState } from 'react'; import { useQuery } from '@tanstack/react-query'; import { api } from '@/lib/api'; import { Card, CardContent } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Badge } from '@/components/ui/badge'; import { Skeleton } from '@/components/ui/skeleton'; import { Search, UserPlus, ChevronRight } from 'lucide-react'; interface Client { id: string; accountNumber: string; firstName: string; lastName: string; phone: string; isActive: boolean; area: { name: string } | null; subscriptions: Array<{ status: string; type: string; monthlyPrice: string; plan?: { name: string }; }>; } interface ClientsResponse { data: Client[]; total: number; page: number; limit: number; } const statusColors: Record = { ACTIVE: 'bg-green-100 text-green-700', PENDING: 'bg-yellow-100 text-yellow-700', SUSPENDED: 'bg-red-100 text-red-700', DISCONNECTED: 'bg-gray-100 text-gray-700', CANCELLED: 'bg-gray-100 text-gray-500', }; export default function ClientsPage() { const [search, setSearch] = useState(''); const [page, setPage] = useState(1); const { data, isLoading } = useQuery({ queryKey: ['clients', search, page], queryFn: async () => { const params = new URLSearchParams({ page: String(page), limit: '20' }); if (search) params.set('search', search); const res = await api.get(`/api/v1/clients?${params}`); return res.data; }, staleTime: 30_000, }); const clients = data?.data ?? []; const total = data?.total ?? 0; return (

Clients

{total} total clients

{/* Search */}
{ setSearch(e.target.value); setPage(1); }} />
{/* Table */}
{isLoading ? Array.from({ length: 8 }).map((_, i) => ( )) : clients.map((client) => { const sub = client.subscriptions?.[0]; const status = sub?.status ?? (client.isActive ? 'ACTIVE' : 'INACTIVE'); return ( ); })}
Account # Name Area Plan Status Monthly
{client.accountNumber} {client.firstName} {client.lastName}
{client.phone}
{client.area?.name ?? '—'} {sub?.plan?.name ?? (sub ? `${sub.type}` : '—')} {status} {sub ? `₱${Number(sub.monthlyPrice).toLocaleString()}` : '—'}
{/* Pagination */} {total > 20 && (

Showing {(page - 1) * 20 + 1}–{Math.min(page * 20, total)} of {total}

)} {!isLoading && clients.length === 0 && (
No clients found{search ? ` for "${search}"` : ''}
)}
); }