import React, { useState, FormEvent } from 'react'; import { Button, Modal, Spin } from 'antd'; const App: React.FC = () => { const [moduleName, setModuleName] = useState(''); const [moduleType, setModuleType] = useState(''); const [open, setOpen] = useState(false); const [loading, setLoading] = useState(false); const handleModuleSubmit = async (e: FormEvent) => { e.preventDefault(); const data = { moduleName, moduleType, }; setLoading(true); try { const response = await fetch(`https://api.teachertrainingkolkata.in/api/create-module`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(data), }); if (!response.ok) { throw new Error('Network Response not ok'); } const result = await response.json(); console.log('Success', result); setOpen(false); // Close the modal on successful submission } catch (error) { console.error('Error', error); } finally { setLoading(false); } }; const showLoading = () => { setOpen(true); setLoading(true); // Simple loading mock. You should add cleanup logic in the real world. setTimeout(() => { setLoading(false); }, 500); }; return ( <> setOpen(false)} > {loading ? ( ) : (
setModuleName(e.target.value)} type="text" name='moduleName' id='moduleName' />
setModuleType(e.target.value)} type="text" name='moduleType' id='moduleType' />

)}
); }; export default App;