'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 { Skeleton } from '@/components/ui/skeleton'; import { Search } from 'lucide-react'; import { format } from 'date-fns'; interface Payment { id: string; amount: string; channel: string; paymentDate: string; notes: string | null; client?: { firstName: string; lastName: string; accountNumber: string }; recordedBy?: { firstName: string; lastName: string }; invoice?: { invoiceNumber: string }; } const channelColors: Record = { CASH: 'bg-green-100 text-green-700', GCASH: 'bg-blue-100 text-blue-700', MAYA: 'bg-purple-100 text-purple-700', BANK_TRANSFER: 'bg-orange-100 text-orange-700', CHECK: 'bg-gray-100 text-gray-700', }; const peso = (v: string | number) => '₱' + Number(v ?? 0).toLocaleString('en-PH', { minimumFractionDigits: 2 }); export default function PaymentsPage() { const [search, setSearch] = useState(''); const [channelFilter, setChannelFilter] = useState(''); const [page, setPage] = useState(1); const { data, isLoading } = useQuery<{ data: Payment[]; total: number }>({ queryKey: ['payments', search, channelFilter, page], queryFn: async () => { const params = new URLSearchParams({ page: String(page), limit: '20' }); if (channelFilter) params.set('channel', channelFilter); const res = await api.get(`/api/v1/payments?${params}`); return res.data; }, staleTime: 30_000, }); const payments = data?.data ?? []; const total = data?.total ?? 0; return (

Payments

{total} payments

{ setSearch(e.target.value); setPage(1); }} />
{isLoading ? Array.from({ length: 8 }).map((_, i) => ( {Array.from({ length: 6 }).map((_, j) => ( ))} )) : payments.map((p) => ( ))}
Date Client Amount Channel Recorded By Invoice
{p.paymentDate ? format(new Date(p.paymentDate), 'MMM d, yyyy') : '—'} {p.client ? `${p.client.firstName} ${p.client.lastName}` : '—'}
{p.client?.accountNumber}
{peso(p.amount)} {p.channel?.replace('_', ' ')} {p.recordedBy ? `${p.recordedBy.firstName} ${p.recordedBy.lastName}` : '—'} {p.invoice?.invoiceNumber ?? '—'}
{!isLoading && payments.length === 0 && (
No payments found
)}
); }