Public Access
feat: Implement API modules for admin, auth, exam, result, and setup functionalities
- Created adminApi.ts for admin-related operations including user management and site settings. - Developed authApi.ts for authentication processes such as registration, login, and profile management. - Added examApi.ts for handling exam CRUD operations. - Introduced resultApi.ts for managing results submission and retrieval. - Established setupApi.ts for initial setup processes and status checks. - Created ErrorBoundary component to handle rendering errors gracefully in the frontend. - Re-exported shared API utilities in index.ts for easier access.
This commit is contained in:
1 parent
62af83ce53
commit
c64cdcd9e3
46 files changed
+2227
-1125
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { useParams, useNavigate } from 'react-router-dom'
|
||||
import { apiFetch } from '../utils/api'
|
||||
import type { Exam, Question, QuestionType, Choice, MatchItem } from '../types'
|
||||
import * as examApi from '../api/examApi'
|
||||
import type { Exam, Question, QuestionType, Choice } from '../types'
|
||||
|
||||
const QUESTION_TYPES: { value: QuestionType; label: string }[] = [
|
||||
{ value: 'multiple-choice', label: 'Multiple Choice' },
|
||||
@@ -61,9 +61,9 @@ export default function ExamEditor() {
|
||||
useEffect(() => {
|
||||
if (isNew) return
|
||||
setLoading(true)
|
||||
apiFetch<{ exam: Exam }>(`/api/exams/${examId}`)
|
||||
examApi.getExam(examId!)
|
||||
.then((data) => {
|
||||
setExam(data.exam)
|
||||
setExam(data)
|
||||
setHasChanges(false)
|
||||
})
|
||||
.catch((e) => setError((e as Error).message))
|
||||
@@ -111,18 +111,12 @@ export default function ExamEditor() {
|
||||
setError(null)
|
||||
try {
|
||||
if (isNew) {
|
||||
const data = await apiFetch<{ id: number }>('/api/exams', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ exam }),
|
||||
})
|
||||
const data = await examApi.createExam(exam)
|
||||
setSaveMsg('Exam created successfully')
|
||||
setHasChanges(false)
|
||||
navigate(`/exam-editor/${data.id}`, { replace: true })
|
||||
} else {
|
||||
await apiFetch(`/api/exams/${examId}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ exam }),
|
||||
})
|
||||
await examApi.updateExam(examId!, exam)
|
||||
setSaveMsg('Exam saved')
|
||||
setHasChanges(false)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user