import React, { useState, useEffect } from 'react'; import axios from 'axios'; const BASE_URL = "http://localhost:8000"; const BankLogsTable = () => { const [logs, setLogs] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [searchTerm, setSearchTerm] = useState(''); const fetchLogs = async () => { const token = localStorage.getItem('token'); try { setLoading(true); const response = await axios.get(`${BASE_URL}/bank/logs`, { headers: { 'Authorization': `Bearer ${token}`, 'Accept': 'application/json' } }); const sortedLogs = response.data.data.sort((a, b) => new Date(b.created_at) - new Date(a.created_at) ); setLogs(sortedLogs); setError(null); } catch (error) { console.error("Error fetching logs:", error); setError("Failed to load bank logs. Please try again later."); } finally { setLoading(false); } }; useEffect(() => { fetchLogs(); }, []); const filteredLogs = logs.filter(log => log.explanation.toLowerCase().includes(searchTerm.toLowerCase()) || log.transactionType.toLowerCase().includes(searchTerm.toLowerCase()) || log.accountNumber?.toLowerCase().includes(searchTerm.toLowerCase()) ); const getTransactionTypeClass = (type) => { return type === 'Ekle' ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'; }; if (loading) { return (
); } return (
setSearchTerm(e.target.value)} />
{error && (

Hata!

{error}

)}
{filteredLogs.map((log) => ( ))}
ID Hesap No İşlem Türü Miktar Önceki Bakiye Yeni Bakiye Açıklama Tarih
{log.id} {log.accountId} {log.transactionType} {log.amount.toLocaleString('tr-TR')} ₺ {log.previousBalance.toLocaleString('tr-TR')} ₺ {log.newBalance.toLocaleString('tr-TR')} ₺ {log.explanation} {new Date(log.created_at).toLocaleString("tr-TR")}
{filteredLogs.length === 0 && (
Aradığın kriterde bir işlem bulunamadı.
)}
); }; export default BankLogsTable;