import React, { useState, useEffect } from 'react'; import axios from 'axios'; import PopBox from './PopBox'; const BASE_URL = "http://localhost:8000"; const BankForm = ({ show, onClose, title }) => { const [accounts, setAccounts] = useState([]); const [formData, setFormData] = useState({ bankName: '', accountName: '', accountNumber: '', accountExplanation: '', isActive: false, isBlocked: false, isInvest: false, isPull: false, minInvest: '', maxInvest: '', minPull: '', maxPull: '', maxTransfer: '', maxAmount: '' }); const [isLoading, setIsLoading] = useState(false); const [showModal, setShowModal] = useState(false); useEffect(() => { const getAllByBanks = async () => { try { const response = await axios.get(`${BASE_URL}/bank/accounts`); const sortedAccounts = response.data.data.sort((a, b) => new Date(b.created_at) - new Date(a.created_at) ); setAccounts(sortedAccounts); } catch (error) { console.error("Error fetching data: " + error); } }; getAllByBanks(); }, []); const handleChange = (e) => { const { name, value, type, checked } = e.target; setFormData(prev => ({ ...prev, [name]: type === 'checkbox' ? checked : value })); }; const handleSubmit = async (e) => { e.preventDefault(); setIsLoading(true); const token = localStorage.getItem('token'); const currentDate = new Date().toLocaleString("tr-TR", { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false, }); const newBank = { ...formData, accountBalance: 0, userID: { token }, created_at: { currentDate } }; try { const response = await axios.post(`${BASE_URL}/bank/`, newBank, { headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` } }); setAccounts([...accounts, response.data]); setShowModal(true); setFormData({ bankName: '', accountName: '', accountNumber: '', accountExplanation: '', isActive: false, isBlocked: false, isInvest: false, isPull: false, minInvest: '', maxInvest: '', minPull: '', maxPull: '', maxTransfer: '', maxAmount: '' }); } catch (error) { console.error("Error saving data:", error); } finally { setIsLoading(false); } }; const handleCloseModal = () => { setShowModal(false); window.location.reload(); }; if (!show) return null; return (

{title}

{/* Bank Information */}
{/* Account Settings */}

Please fill in all required information

Thank you for your cooperation

DemSettle ®

{showModal && (

Bank Account Successfully Added

)}
); }; export default BankForm;