import React, { useEffect, useState } from 'react'; import { HiBars3BottomLeft } from "react-icons/hi2"; import { FaCheck } from "react-icons/fa6"; import '../App.css'; import InvestmentForm from './YatırımForm'; import axios from 'axios'; import DateInput from './DateInput'; import InvestmentTable from './YatırımTable'; const BASE_URL = "http://localhost:8000/api"; const YatırımContent = () => { const [showFilterMenu, setShowFilterMenu] = useState(true); const [showModal, setShowModal] = useState(false); const [bankAccounts, setBankAccounts] = useState([]); const [selectedAccounts, setSelectedAccounts] = useState([]); // Changed to array const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [minAmount, setMinAmount] = useState(''); const [maxAmount, setMaxAmount] = useState(''); const [filterConfig, setFilterConfig] = useState({ accountNumbers: [], // Changed to array minAmount: '', maxAmount: '', startDate: '', endDate: '', autoUpdate: true }); useEffect(() => { fetchBankAccounts(); }, []); const fetchBankAccounts = async () => { const token = localStorage.getItem('token'); setLoading(true); try { const response = await axios.get(`${BASE_URL}/bank/accounts`, { headers: { 'Authorization': `Bearer ${token}` } }); // Filter accounts that allow investments (isInvest is true) const investmentAccounts = response.data.data.filter(account => account.isInvest); setBankAccounts(investmentAccounts); } catch (err) { setError('Banka hesapları yüklenirken bir hata oluştu'); console.error('Error fetching bank accounts:', err); } finally { setLoading(false); } }; const handleAccountChange = (e) => { const selectedOptions = Array.from(e.target.selectedOptions).map(option => option.value); const selectedAccountsInfo = selectedOptions.map(accountId => { const account = bankAccounts.find(acc => acc.accountId === accountId); return account ? account.accountNumber : null; }).filter(Boolean); setSelectedAccounts(selectedOptions); setFilterConfig(prev => ({ ...prev, accountNumbers: selectedAccountsInfo })); }; const handleMinAmountChange = (e) => { const value = e.target.value; setMinAmount(value); setFilterConfig(prev => ({ ...prev, minAmount: value })); }; const handleMaxAmountChange = (e) => { const value = e.target.value; setMaxAmount(value); setFilterConfig(prev => ({ ...prev, maxAmount: value })); }; const handleDateChange = ({ startDate, endDate }) => { setFilterConfig(prev => ({ ...prev, startDate, endDate })); }; const toggleAutoUpdate = () => { setFilterConfig(prev => ({ ...prev, autoUpdate: !prev.autoUpdate })); }; const toggleFilterMenu = () => { setShowFilterMenu(prev => !prev); }; return (
{showModal && ( setShowModal(false)} /> )}
{!showFilterMenu && (
Banka Hesapları
{!loading && (
{selectedAccounts.length === 0 ? ( 'Seçili hesap yok' ) : ( `${selectedAccounts.length} hesap seçili` )} Ctrl/Cmd tuşuna basılı tutarak birden fazla hesap seçebilirsiniz
)} {error && ( {error} )}

Tutar Aralığı

ve
)}
); }; export default YatırımContent;