import React, { useState, useEffect, FormEvent } from 'react'; import { Button, Modal, Spin } from 'antd'; interface QuizModule { moduleId: string; moduleName: string; } const App: React.FC = () => { const [moduleList, setModuleList] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [quizName, setQuizName] = useState(''); const [totalQuestion, settotalQuestion] = useState(''); const [attendance, setAttendance] = useState(''); const [internalMarks, setInternalMarks] = useState(''); const [moduleId, setModuleId] = useState(''); const [open, setOpen] = useState(false); const [submitLoading, setSubmitLoading] = useState(false); useEffect(() => { fetch(`http://localhost:5174/api/quiz-module-list`) .then((res) => { if (!res.ok) { throw new Error('Network response was not ok'); } return res.json(); }) .then((data) => { console.log(data); setModuleList(data); setLoading(false); }) .catch((error) => { console.error('An error occurred', error); setError(error); setLoading(false); }); }, []); const handleModuleSubmit = async (e: FormEvent) => { e.preventDefault(); const data = { quizName, totalQuestion, attendance, internalMarks, moduleId, }; setSubmitLoading(true); try { const response = await fetch(`http://localhost:5174/api/create-quiz`, { 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 // Optionally, refresh the quiz list here } catch (error) { console.error('Error', error); } finally { setSubmitLoading(false); } }; const showLoading = () => { setOpen(true); }; if (loading) { return ; } if (error) { return
Error: {error.message}
; } return ( <> setOpen(false)}> {submitLoading ? ( ) : (
setQuizName(e.target.value)} type="text" name='quizName' id='quizName'/>
settotalQuestion(e.target.value)} type="text" name='totalQuestion' id='totalQuestion'/>
setAttendance(e.target.value)} type="text" name='attendance' id='attendance'/>
setAttendance(e.target.value)} type="text" name='attendance' id='attendance'/>
setInternalMarks(e.target.value)} type="text" name='internalMarks' id='internalMarks'/>

)}
); }; export default App; // quizList