import React, { useEffect, useState } from 'react'; import { HiBars3BottomLeft } from "react-icons/hi2"; import { FaCheck } from "react-icons/fa6"; import '../App.css'; import WithdrawalForm from './Cekimform'; import axios from 'axios'; import DateInput from './DateInput'; import WithdrawalTable from './CekimTable'; const BASE_URL = "http://localhost:8000/api"; const WithdrawalContent = () => { const [showFilterMenu, setShowFilterMenu] = useState(true); const [showModal, setShowModal] = useState(false); const [bankAccounts, setBankAccounts] = useState([]); const [selectedAccount, setSelectedAccount] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [minAmount, setMinAmount] = useState(''); const [maxAmount, setMaxAmount] = useState(''); const [filterConfig, setFilterConfig] = useState({ accountNumber: '', 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 withdrawals (isPull is true) const withdrawalAccounts = response.data.data.filter(account => account.isPull); setBankAccounts(withdrawalAccounts); } 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 selectedAccount = bankAccounts.find(acc => acc.accountId === e.target.value); setSelectedAccount(e.target.value); setFilterConfig(prev => ({ ...prev, accountNumber: selectedAccount ? selectedAccount.accountNumber : '' })); }; 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ı
{error && ( {error} )}

Tutar Aralığı

ve
)}
); }; export default WithdrawalContent;