import React, { useEffect, useState } from 'react'; import { HiBars3BottomLeft } from "react-icons/hi2"; import { FaCheck } from "react-icons/fa6"; import { IoSearch } from "react-icons/io5"; import '../App.css'; import WithdrawalForm from './Cekimform'; import WithdrawalTable from './CekimTable'; import DateInput from './DateInput'; import axios from 'axios'; const BASE_URL = "http://localhost:8000/api"; const WithdrawalContent = () => { const [showFilterMenu, setShowFilterMenu] = useState(true); const [showModal, setShowModal] = useState(false); const [bankAccounts, setBankAccounts] = useState([]); const [selectedAccounts, setSelectedAccounts] = useState([]); const [accountSearchTerm, setAccountSearchTerm] = useState(''); const [filteredAccounts, setFilteredAccounts] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [minAmount, setMinAmount] = useState(''); const [maxAmount, setMaxAmount] = useState(''); const [filterConfig, setFilterConfig] = useState({ accountNumbers: [], minAmount: '', maxAmount: '', startDate: '', endDate: '', autoUpdate: true }); useEffect(() => { fetchBankAccounts(); }, []); useEffect(() => { if (accountSearchTerm.trim() === '') { setFilteredAccounts(bankAccounts); return; } const searchTerms = accountSearchTerm.toLowerCase().split(' '); const filtered = bankAccounts.filter(account => { const accountString = `${account.accountName} ${account.bankName} ${account.accountNumber}`.toLowerCase(); return searchTerms.every(term => accountString.includes(term)); }); setFilteredAccounts(filtered); }, [accountSearchTerm, bankAccounts]); 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); setFilteredAccounts(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 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 (
{/* Header Section */}
{/* Withdrawal Form Modal */} {showModal && ( setShowModal(false)} /> )} {/* Filter Toggle Button */}
{/* Filter Section */} {!showFilterMenu && (
{/* Bank Accounts Section */}
Banka Hesapları
{/* Account Search */}
setAccountSearchTerm(e.target.value)} className="w-full pl-8 pr-4 py-1.5 rounded-md text-xs border border-gray-300 focus:outline-none focus:ring-2 focus:ring-emerald-500 placeholder-gray-400" />
{/* Accounts Multi-Select */} {/* Selection Info and Help Text */}
{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} )} {loading && (
)}
{/* Amount Range and Auto-Update Section */}

Tutar Aralığı

ve
)}
{/* Withdrawals Table */}
); }; export default WithdrawalContent;