import React, { useState, useEffect } from 'react'; import axios from 'axios'; import BankaCardBox from './BankaCardBox'; import KrediCardBox from './KrediCardBox'; import { FaWallet, FaChartPie } from 'react-icons/fa6'; const BASE_URL = "http://localhost:8000"; const Main = () => { const [users, setUsers] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const getAllByUsers = async () => { try { setLoading(true); const response = await axios.get(`${BASE_URL}/bank/accounts`); setUsers(response.data.data); } catch (error) { console.error("Error fetching data:", error); setError("Failed to load account data. Please try again later."); } finally { setLoading(false); } }; useEffect(() => { getAllByUsers(); }, []); if (loading) { return (
); } if (error) { return (

Error

{error}
); } const totalBalance = users.reduce((acc, data) => acc + data.accountBalance, 0); return (
{/* Left Column - Account Summary */}

Bank Accounts

{/* Total Balance Card */}

Total Balance

{totalBalance.toLocaleString('tr-TR', { minimumFractionDigits: 2, maximumFractionDigits: 2 })} ₺
{/* Account List */}
{users.map((account) => (
{account.accountName} {account.bankName}
{Number(account.accountBalance).toLocaleString("tr-TR", { minimumFractionDigits: 2, maximumFractionDigits: 2 })} ₺
Last Updated: {new Date(account.created_at).toLocaleString("tr-TR")}
))}
{/* Right Column - Cards */}
{/* Statistics Cards */}
); }; export default Main;