import React from "react"; import { View, Text, ScrollView, Image, TouchableOpacity } from "react-native"; import ScreenWrapper from "~/components/ui/ScreenWrapper"; import { Input } from "~/components/ui/input"; import { Icons } from "~/assets/icons"; import TopBar from "~/components/ui/topBar"; import BottomSheet from "~/components/ui/bottomSheet"; type TransactionStatus = "success" | "pending" | "failed"; type AgentTransaction = { id: string; clientName: string; amount: string; currency: string; status: TransactionStatus; date: string; time: string; method: "telebirr" | "chapa" | "bank" | "cash"; reference?: string; }; const MOCK_TRANSACTIONS: AgentTransaction[] = [ { id: "tx-1", clientName: "Abebe Kebede", amount: "4,500", currency: "ETB", status: "success", date: "Today", time: "09:32 AM", method: "telebirr", reference: "REF-938201", }, { id: "tx-2", clientName: "Sara Alemu", amount: "250", currency: "USD", status: "pending", date: "Today", time: "01:15 PM", method: "chapa", reference: "REF-938202", }, { id: "tx-3", clientName: "Hope Community Fund", amount: "32,000", currency: "ETB", status: "success", date: "Yesterday", time: "05:47 PM", method: "bank", reference: "REF-937812", }, { id: "tx-4", clientName: "Kidus Tadesse", amount: "900", currency: "ETB", status: "failed", date: "Mon, 06 Jan", time: "10:02 AM", method: "telebirr", reference: "REF-937111", }, { id: "tx-5", clientName: "Blue Nile Traders", amount: "12,750", currency: "ETB", status: "success", date: "Sun, 05 Jan", time: "03:28 PM", method: "cash", reference: "REF-936444", }, ]; const getStatusPillClasses = (status: TransactionStatus) => { switch (status) { case "success": return "bg-green-100 text-green-700"; case "pending": return "bg-yellow-100 text-yellow-700"; case "failed": default: return "bg-red-100 text-red-700"; } }; export default function AgentTab() { const [search, setSearch] = React.useState(""); const [statusFilter, setStatusFilter] = React.useState< "all" | TransactionStatus >("all"); const [methodFilter, setMethodFilter] = React.useState< "all" | "telebirr" | "chapa" | "bank" | "cash" >("all"); const [selectedTx, setSelectedTx] = React.useState( null ); const [filterSheetVisible, setFilterSheetVisible] = React.useState(false); const normalizedSearch = search.trim().toLowerCase(); const filteredTransactions = React.useMemo(() => { return MOCK_TRANSACTIONS.filter((tx) => { const matchesStatus = statusFilter === "all" || tx.status === statusFilter; const matchesMethod = methodFilter === "all" || tx.method === methodFilter; const matchesSearch = !normalizedSearch || tx.clientName.toLowerCase().includes(normalizedSearch) || (tx.reference && tx.reference.toLowerCase().includes(normalizedSearch)); return matchesStatus && matchesMethod && matchesSearch; }); }, [statusFilter, methodFilter, normalizedSearch]); const { todayTotalEtb, weekTotalEtb, totalTxns, successCount, pendingCount, failedCount, } = React.useMemo(() => { const parseAmount = (amount: string) => parseInt(amount.replace(/,/g, ""), 10) || 0; let todayTotal = 0; let weekTotal = 0; let success = 0; let pending = 0; let failed = 0; MOCK_TRANSACTIONS.forEach((tx) => { if (tx.status === "success") success += 1; if (tx.status === "pending") pending += 1; if (tx.status === "failed") failed += 1; if (tx.currency === "ETB") { const val = parseAmount(tx.amount); weekTotal += val; if (tx.date === "Today") { todayTotal += val; } } }); return { todayTotalEtb: todayTotal, weekTotalEtb: weekTotal, totalTxns: MOCK_TRANSACTIONS.length, successCount: success, pendingCount: pending, failedCount: failed, }; }, []); const groupedTransactions = React.useMemo(() => { const groups: Record = {}; filteredTransactions.forEach((tx) => { if (!groups[tx.date]) { groups[tx.date] = []; } groups[tx.date].push(tx); }); return Object.entries(groups); }, [filteredTransactions]); return ( Transactions All the transactions you have processed. UI-only reporting & tracking. Last updated: Just now (mock data) {/* Search / filter bar */} setFilterSheetVisible(true)} > } /> {/* Optional summary row (dummy numbers) */} Today ETB {todayTotalEtb.toLocaleString("en-ET")} This week ETB {weekTotalEtb.toLocaleString("en-ET")} Total txns {totalTxns} Success: {successCount} · Pending: {pendingCount} · Failed:{" "} {failedCount} {/* Transactions list */} {groupedTransactions.map(([dateLabel, txs]) => ( {dateLabel} {txs.map((tx) => { const pillClasses = getStatusPillClasses(tx.status); return ( setSelectedTx(tx)} > {tx.currency} {tx.amount} {tx.status === "success" ? "Success" : tx.status === "pending" ? "Pending" : "Failed"} {tx.clientName} {tx.time} {tx.method === "telebirr" ? "Telebirr" : tx.method === "chapa" ? "Chapa" : tx.method === "bank" ? "Bank transfer" : "Cash"} {tx.reference && ( {tx.reference} )} ); })} ))} {groupedTransactions.length === 0 && ( No transactions match your filters. )} {/* Filter BottomSheet */} setFilterSheetVisible(false)} maxHeightRatio={0.5} > Filters {/* Status filter chips */} Status {["all", "success", "pending", "failed"].map((status) => { const isActive = statusFilter === status; const label = status === "all" ? "All" : status === "success" ? "Success" : status === "pending" ? "Pending" : "Failed"; return ( setStatusFilter(status as "all" | TransactionStatus) } > {label} ); })} {/* Method filter chips */} Method {["all", "telebirr", "chapa", "bank", "cash"].map((method) => { const isActive = methodFilter === method; const label = method === "all" ? "All methods" : method === "telebirr" ? "Telebirr" : method === "chapa" ? "Chapa" : method === "bank" ? "Bank" : "Cash"; return ( setMethodFilter( method as "all" | "telebirr" | "chapa" | "bank" | "cash" ) } > {label} ); })} { setStatusFilter("all"); setMethodFilter("all"); }} > Reset setFilterSheetVisible(false)} > Apply setSelectedTx(null)} maxHeightRatio={0.6} > {selectedTx && ( Transaction Details {selectedTx.currency} {selectedTx.amount} {selectedTx.status === "success" ? "Success" : selectedTx.status === "pending" ? "Pending" : "Failed"} Client {selectedTx.clientName} Date & time {selectedTx.date} · {selectedTx.time} Method {selectedTx.method === "telebirr" ? "Telebirr" : selectedTx.method === "chapa" ? "Chapa" : selectedTx.method === "bank" ? "Bank transfer" : "Cash"} {selectedTx.reference && ( Reference {selectedTx.reference} )} Repeat Payment Share Receipt )} ); }