import React, { useState, useEffect } from 'react'; import axios from 'axios'; const BASE_URL = "http://localhost:8000"; const InvestmentForm = ({ show, onClose, title }) => { const [refs, setRefs] = useState([]); const [formData, setFormData] = useState({ refId: '', fullName: '', balance: '', username: '', accountName: '', accountNumber: '', method: '', note: '', investmentStatus: 'Beklemede' }); const [isLoading, setIsLoading] = useState(false); const [showModal, setShowModal] = useState(false); const [error, setError] = useState(''); useEffect(() => { const fetchRefs = async () => { const token = localStorage.getItem('token'); try { const response = await axios.get(`${BASE_URL}/refs/`, { headers: { 'Authorization': `Bearer ${token}` } }); setRefs(response.data); } catch (error) { console.error("Error fetching refs:", error); setError(error.response?.data?.detail || "Failed to load references"); } }; fetchRefs(); }, []); 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); setError(''); const token = localStorage.getItem('token'); try { await axios.post(`${BASE_URL}/investment/`, formData, { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` } }); setShowModal(true); setFormData({ refId: '', fullName: '', balance: '', username: '', accountName: '', accountNumber: '', method: '', note: '', investmentStatus: 'Beklemede' }); } catch (error) { console.error("Error:", error); setError(error.response?.data?.detail || 'An error occurred during investment creation'); } finally { setIsLoading(false); } }; const handleCloseModal = () => { setShowModal(false); window.location.reload(); }; if (!show) return null; return (