import React, { useState } from 'react';
import { Head } from '@inertiajs/react';
import AdminLayout from '@/Layouts/AdminLayout';
import {
FileText,
Users,
ShieldAlert,
CreditCard,
Search,
RefreshCw,
Download,
Building2,
DollarSign
} from 'lucide-react';
export default function AnalyticsHub({
worker_stats = { total: 0, verified: 0, active: 0, inactive: 0 },
sponsor_stats = { total: 0, verified: 0, active_subscribers: 0, unpaid: 0 },
dispute_stats = { total: 0, open: 0, under_review: 0, resolved: 0 },
safety_stats = { total: 0, pending: 0, resolved: 0 },
payments = [],
total_revenue = 0
}) {
const [searchTerm, setSearchTerm] = useState('');
const [statusFilter, setStatusFilter] = useState('all');
// Filter payments dynamically
const filteredPayments = payments.filter(payment => {
const matchesSearch =
payment.id.toString().toLowerCase().includes(searchTerm.toLowerCase()) ||
payment.user_name.toLowerCase().includes(searchTerm.toLowerCase()) ||
payment.user_email.toLowerCase().includes(searchTerm.toLowerCase()) ||
payment.description.toLowerCase().includes(searchTerm.toLowerCase());
const matchesStatus = statusFilter === 'all' || payment.status.toLowerCase() === statusFilter.toLowerCase();
return matchesSearch && matchesStatus;
});
const handleExportCSV = () => {
const headers = ['Payment ID,Customer,Email,Details,Amount,Status,Date\n'];
const rows = filteredPayments.map(p =>
`"${p.id}","${p.user_name}","${p.user_email}","${p.description}",${p.amount},"${p.status}","${p.created_at}"`
);
const blob = new Blob([headers.concat(rows.join('\n'))], { type: 'text/csv;charset=utf-8;' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.setAttribute('download', `financial_report_${new Date().toISOString().split('T')[0]}.csv`);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};
return (
Summary of workers, employers, disputes, and payments.
Search and check payments.
| Payment ID | Customer | Details | Amount | Status | Date |
|---|---|---|---|---|---|
| TXN-{p.id} |
{p.user_name}
{p.user_email}
|
{p.description} | {p.amount.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })} {p.currency} | {p.status} | {p.created_at} |
| No payments found. | |||||