import { ChevronLeft, ChevronRight } from 'lucide-react'; import { CommissionEntry } from '../../services/commissions/entries.api'; import { EntryStatusBadge } from './EntryStatusBadge'; /** * Props for the EntriesList component. */ interface EntriesListProps { /** Array of commission entries to display in the table */ entries: CommissionEntry[]; /** Total number of entries across all pages */ total: number; /** Current page number (1-indexed) */ page: number; /** Total number of pages available */ totalPages: number; /** Array of selected entry IDs for bulk operations */ selectedEntries: string[]; /** Callback when selection changes (for bulk approve/reject) */ onSelectionChange: (ids: string[]) => void; /** Callback when page changes for pagination */ onPageChange: (page: number) => void; /** Callback to refresh the entries list */ onRefresh: () => void; } /** * Displays a paginated table of commission entries with selection support. * Allows selecting pending entries for bulk approval/rejection operations. * Shows entry details including date, user, reference, amounts, and status. * * @param props - The component props * @param props.entries - Commission entries to display * @param props.total - Total entry count for pagination info * @param props.page - Current page number * @param props.totalPages - Total pages for pagination controls * @param props.selectedEntries - Currently selected entry IDs * @param props.onSelectionChange - Handler for selection updates * @param props.onPageChange - Handler for page navigation * @param props.onRefresh - Handler to refresh data after operations * * @example * ```tsx * const [selected, setSelected] = useState([]); * const [page, setPage] = useState(1); * * refetch()} * /> * ``` */ export function EntriesList({ entries, total, page, totalPages, selectedEntries, onSelectionChange, onPageChange, }: EntriesListProps) { const formatCurrency = (amount: number) => new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(amount); const handleSelectAll = () => { const pendingIds = entries.filter((e) => e.status === 'pending').map((e) => e.id); if (pendingIds.every((id) => selectedEntries.includes(id))) { onSelectionChange(selectedEntries.filter((id) => !pendingIds.includes(id))); } else { onSelectionChange([...new Set([...selectedEntries, ...pendingIds])]); } }; const handleSelectOne = (id: string) => { if (selectedEntries.includes(id)) { onSelectionChange(selectedEntries.filter((i) => i !== id)); } else { onSelectionChange([...selectedEntries, id]); } }; const pendingEntries = entries.filter((e) => e.status === 'pending'); const allPendingSelected = pendingEntries.length > 0 && pendingEntries.every((e) => selectedEntries.includes(e.id)); return (
{entries.length === 0 ? ( ) : ( entries.map((entry) => ( )) )}
Date User Reference Base Amount Rate Commission Status
No commission entries found
{entry.status === 'pending' && ( handleSelectOne(entry.id)} className="h-4 w-4 text-blue-600 rounded" /> )} {new Date(entry.created_at).toLocaleDateString()} {entry.user ? `${entry.user.first_name} ${entry.user.last_name}` : entry.user_id.slice(0, 8)} {entry.reference_type} {formatCurrency(entry.base_amount)} {entry.rate_applied}% {formatCurrency(entry.commission_amount)}
{/* Pagination */} {totalPages > 1 && (

Showing {entries.length} of {total} entries

Page {page} of {totalPages}
)}
); }