import React, { useState } from 'react'; import axios from 'axios'; const BASE_URL = "http://localhost:8000"; const AdminForm = ({ show, onClose, title }) => { const [formData, setFormData] = useState({ fullName: '', username: '', password: '', note: '', role: '', skype: '', email: '', is_active: false, is_admin: false }); const [isLoading, setIsLoading] = useState(false); const [showModal, setShowModal] = useState(false); const [error, setError] = useState(''); 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(''); try { const params = new URLSearchParams({ username: formData.username, fullName: formData.fullName, password: formData.password, email: formData.email, role: formData.role, skype: formData.skype, note: formData.note, is_active: formData.is_active, is_admin: formData.is_admin }); await axios.post(${BASE_URL}/register?${params.toString()}); setShowModal(true); // Clear form after successful submission setFormData({ fullName: '', username: '', password: '', note: '', role: '', skype: '', email: '', is_active: false, is_admin: false }); } catch (error) { console.error("Error:", error); setError(error.response?.data?.detail || 'An error occurred during registration'); } finally { setIsLoading(false); } }; const handleCloseModal = () => { setShowModal(false); window.location.reload(); }; if (!show) return null; return (

{title}

{error && (
{error}
)}
{/* Basic Information */}
{/* Additional Information */}

Please fill in all required information

Thank you for your cooperation

DemSettle ®

{showModal && (

Admin Successfully Added

)}
); }; export default AdminForm;