import React, { useState } from 'react'; 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 response = await fetch(`${BASE_URL}/register`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(formData) }); if (!response.ok) { const errorData = await response.json(); throw new Error(errorData.detail || 'Registration failed'); } 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 saving data:", error); setError(error.message || '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;