import React, { useState, useEffect } from 'react'; import axios from 'axios'; const BASE_URL = "http://localhost:8000"; const Logs = ({ show, onClose, title, accountId }) => { const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [logs, setLogs] = useState([]); useEffect(() => { if (show && accountId) { fetchLogs(); } }, [show, accountId]); const fetchLogs = async () => { setLoading(true); setError(null); try { const token = localStorage.getItem('token'); if (!token) { throw new Error('No authentication token found'); } const response = await axios.get(`${BASE_URL}/bank/logs/${accountId}`, { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` } }); setLogs(response.data.data); } catch (error) { console.error("Error fetching logs:", error); setError(error.response?.data?.detail || 'Failed to fetch logs'); } finally { setLoading(false); } }; if (!show) return null; return (
{/* Header */}

{title}

{/* Content */}
{loading ? (
) : error ? (
Error! {error}
) : (
{logs.map((log) => ( ))}
Date Transaction Type Amount Previous Balance New Balance Explanation
{new Date(log.created_at).toLocaleString()} {log.transactionType} {Number(log.amount).toLocaleString('tr-TR', { style: 'currency', currency: 'TRY' })} {Number(log.previousBalance).toLocaleString('tr-TR', { style: 'currency', currency: 'TRY' })} {Number(log.newBalance).toLocaleString('tr-TR', { style: 'currency', currency: 'TRY' })} {log.explanation}
)}
{/* Footer */}
); }; export default Logs;