import React, { useState } from 'react'; import axios from 'axios'; import { IoIosClose } from "react-icons/io"; import { FaMoneyBill, FaStickyNote, FaCheckCircle } from "react-icons/fa"; const BASE_URL = "http://localhost:8000"; const KasaEkleBox = ({ show, onClose, accountId, accountBalance }) => { const [amount, setAmount] = useState(''); const [message, setMessage] = useState(''); const [error, setError] = useState(''); const [success, setSuccess] = useState(false); if (!show) return null; const handleSubmit = async (e) => { e.preventDefault(); setError(''); if (!amount || isNaN(parseFloat(amount))) { setError('Please enter a valid amount'); return; } const token = localStorage.getItem('token'); const payload = { accountBalance: parseFloat(amount) + parseFloat(accountBalance), accountExplanation: message || '', }; try { await axios.patch(`${BASE_URL}/bank/add_balance/${accountId}`, payload, { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}`, }, }); setSuccess(true); setTimeout(() => { onClose(); window.location.reload(); }, 1500); } catch (error) { console.error('Update error:', error); setError( error.response?.data?.detail || error.response?.data?.message || 'An error occurred while processing your request' ); } }; return (
{/* Header */}

Add Balance

{/* Content */}
{success && (
Balance added successfully!
)} {/* Amount Input */}
setAmount(e.target.value)} />
{/* Note Input */}
setMessage(e.target.value)} />
{/* Error Message */} {error && (
{error}
)} {/* Submit Button */}
); }; export default KasaEkleBox; import React, { useState } from 'react'; import axios from 'axios'; import { IoIosClose } from "react-icons/io"; import { FaMoneyBill, FaStickyNote, FaCheckCircle } from "react-icons/fa"; const BASE_URL = "http://localhost:8000"; const KasaCıkarBox = ({ show, onClose, accountId, accountBalance }) => { const [amount, setAmount] = useState(''); const [message, setMessage] = useState(''); const [error, setError] = useState(''); const [success, setSuccess] = useState(false); if (!show) return null; const handleSubmit = async (e) => { e.preventDefault(); setError(''); if (!amount || isNaN(parseFloat(amount))) { setError('Please enter a valid amount'); return; } if (parseFloat(amount) > parseFloat(accountBalance)) { setError('Insufficient balance for this withdrawal'); return; } const token = localStorage.getItem('token'); const payload = { accountBalance: parseFloat(amount), accountExplanation: message || '', }; try { await axios.patch(`${BASE_URL}/bank/sub_balance/${accountId}`, payload, { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}`, }, }); setSuccess(true); setTimeout(() => { onClose(); window.location.reload(); }, 1500); } catch (error) { console.error('Update error:', error); setError( error.response?.data?.detail || error.response?.data?.message || 'An error occurred while processing your request' ); } }; return (
{/* Header */}

Withdraw Balance

{/* Content */}
{/* Current Balance Display */}
Current Balance: {Number(accountBalance).toLocaleString('tr-TR', { minimumFractionDigits: 2, maximumFractionDigits: 2 })} ₺
{success && (
Withdrawal completed successfully!
)} {/* Amount Input */}
setAmount(e.target.value)} />
{/* Note Input */}
setMessage(e.target.value)} />
{/* Error Message */} {error && (
{error}
)} {/* Submit Button */}
); }; export default KasaCıkarBox;