import React, { useEffect, useState } from 'react';
import { FiFilter, FiX, FiRefreshCw } from 'react-icons/fi';
import axios from 'axios';
const BASE_URL = "http://localhost:8000/api";
const YatırımContent = ({ onFiltersChange }) => {
const [filters, setFilters] = useState({
account: '',
status: '',
dateRange: {
start: '',
end: ''
},
amountRange: {
min: '',
max: ''
}
});
const [showFilters, setShowFilters] = useState(true);
const [loading, setLoading] = useState(false);
const [autoRefresh, setAutoRefresh] = useState(true);
const [accounts, setAccounts] = useState([]);
const [error, setError] = useState(null);
useEffect(() => {
fetchAccounts();
const interval = autoRefresh ? setInterval(fetchAccounts, 30000) : null;
return () => interval && clearInterval(interval);
}, [autoRefresh]);
useEffect(() => {
onFiltersChange(filters);
}, [filters, onFiltersChange]);
const fetchAccounts = async () => {
setLoading(true);
try {
const token = localStorage.getItem('token');
const response = await axios.get(`${BASE_URL}/bank/accounts`, {
headers: { 'Authorization': `Bearer ${token}` }
});
setAccounts(response.data.data);
setError(null);
} catch (err) {
setError('Failed to load accounts');
console.error(err);
} finally {
setLoading(false);
}
};
const handleFilterChange = (key, value) => {
setFilters(prev => ({
...prev,
[key]: value
}));
};
const clearFilters = () => {
setFilters({
account: '',
status: '',
dateRange: { start: '', end: '' },
amountRange: { min: '', max: '' }
});
};
const formatDate = (dateString) => {
if (!dateString) return '';
const date = new Date(dateString);
return date.toLocaleDateString('tr-TR');
};
const statusOptions = [
{ value: '', label: 'Tüm Durumlar' },
{ value: 'Beklemede', label: 'Beklemede' },
{ value: 'Onaylandı', label: 'Onaylandı' },
{ value: 'İptal', label: 'İptal' }
];
return (
{/* Header Section */}
{/* Filter Section */}
{showFilters && (
{/* Account Filter */}
{/* Status Filter */}
{/* Date Range Filter */}
{/* Amount Range Filter */}
)}
{/* Active Filters Display */}
{Object.values(filters).some(value =>
value && (typeof value === 'string' ? value.length > 0 : Object.values(value).some(v => v))
) && (
{filters.account && (
Hesap: {accounts.find(a => a.accountId === filters.account)?.bankName || filters.account}
)}
{filters.status && (
Durum: {filters.status}
)}
{(filters.dateRange.start || filters.dateRange.end) && (
Tarih: {formatDate(filters.dateRange.start)}
{filters.dateRange.end && ` - ${formatDate(filters.dateRange.end)}`}
)}
{(filters.amountRange.min || filters.amountRange.max) && (
Tutar: {filters.amountRange.min ? `${filters.amountRange.min}₺` : '0₺'}
{' - '}
{filters.amountRange.max ? `${filters.amountRange.max}₺` : '∞'}
)}
)}
{/* Error Display */}
{error && (
{error}
)}
);
};
export default YatırımContent;