Admin fixes, minio texts removed, added is_active to User model
This commit is contained in:
@@ -172,6 +172,45 @@ export default function AdminTestsPage() {
|
||||
|
||||
const handleUpload = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
|
||||
if (testType === 'DPP_PDF') {
|
||||
const file = fileInputRef.current?.files?.[0]
|
||||
if (!file) {
|
||||
alert("Please select a PDF file to upload to Minio.")
|
||||
return
|
||||
}
|
||||
if (!userId) return
|
||||
setUploading(true)
|
||||
try {
|
||||
const formData = new FormData()
|
||||
formData.append("file", file)
|
||||
formData.append("title", title)
|
||||
formData.append("exam_pattern", examPattern)
|
||||
formData.append("time_limit", timeLimit)
|
||||
formData.append("admin_id", userId as string)
|
||||
if (scheduledDate) formData.append("scheduled_date", scheduledDate.toISOString())
|
||||
|
||||
const res = await fetchWithAuth("/api/admin/tests/upload", {
|
||||
method: "POST",
|
||||
body: formData
|
||||
})
|
||||
if (res.ok) {
|
||||
alert("PDF uploaded successfully to Minio and connected!")
|
||||
setTitle("")
|
||||
removeFile()
|
||||
fetchTests()
|
||||
} else {
|
||||
const err = await res.json()
|
||||
alert(`Upload failed: ${JSON.stringify(err)}`)
|
||||
}
|
||||
} catch (err) {
|
||||
alert("Upload failed")
|
||||
} finally {
|
||||
setUploading(false)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (!validQuestions || validQuestions.length === 0) {
|
||||
alert("Please upload a valid JSON file with questions first.")
|
||||
return
|
||||
@@ -251,13 +290,14 @@ export default function AdminTestsPage() {
|
||||
value={testType}
|
||||
onChange={(e) => setTestType(e.target.value)}
|
||||
>
|
||||
<option value="CBT">🎯 CBT Mock Test — appears in Mock Tests section</option>
|
||||
<option value="DPS">📋 DPP (Daily Practice) — appears in PrepPilot AI section</option>
|
||||
<option value="CBT">🎯 CBT Test (JSON) — appears in Mock Tests section</option>
|
||||
<option value="PREP_PILOT">🤖 Prep Pilot Test (as CBT JSON) — appears in AI Coach</option>
|
||||
<option value="DPP_PDF">📋 DPP PDF (Minio Upload) — Class/Plan aligned</option>
|
||||
</select>
|
||||
<p className="text-[11px] text-muted-foreground">
|
||||
{testType === 'CBT'
|
||||
? '✅ This will appear under Dashboard → Mock Tests (CBT) for students to attempt.'
|
||||
: '✅ This will appear under AI Coach → PrepPilot AI as a DPP with full CBT interface.'}
|
||||
{testType === 'CBT' && '✅ Purely for CBT. Appears under Dashboard → Mock Tests.'}
|
||||
{testType === 'PREP_PILOT' && '✅ Purely for CBT. Appears under AI Coach → PrepPilot AI.'}
|
||||
{testType === 'DPP_PDF' && '✅ Uploads a PDF to Minio storage for Class/Plan aligned DPP.'}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -313,7 +353,21 @@ export default function AdminTestsPage() {
|
||||
<div className="space-y-2 pt-2">
|
||||
<label className="text-sm font-medium">Questions JSON File</label>
|
||||
|
||||
{validQuestions ? (
|
||||
{testType === 'DPP_PDF' ? (
|
||||
<div className="space-y-2 pt-2">
|
||||
<label className="text-sm font-medium">PDF File (Minio Upload)</label>
|
||||
<input
|
||||
type="file"
|
||||
accept=".pdf"
|
||||
ref={fileInputRef}
|
||||
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background cursor-pointer file:border-0 file:bg-primary file:text-primary-foreground file:h-full file:px-4 file:mr-4 file:font-semibold hover:file:bg-primary/90"
|
||||
onChange={(e) => {
|
||||
const file = e.target.files?.[0]
|
||||
if(file) setValidationErrors([])
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
) : validQuestions ? (
|
||||
<div className="flex items-center justify-between p-3 border border-green-500/50 bg-green-500/10 rounded-md">
|
||||
<div className="flex items-center gap-2 text-green-600 dark:text-green-400">
|
||||
<CheckCircle2 className="w-5 h-5" />
|
||||
@@ -364,9 +418,9 @@ export default function AdminTestsPage() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Button type="submit" className="w-full" disabled={uploading || !validQuestions}>
|
||||
<Button type="submit" className="w-full" disabled={uploading || (!validQuestions && testType !== 'DPP_PDF')}>
|
||||
{uploading ? <Loader2 className="w-4 h-4 mr-2 animate-spin" /> : <FileText className="w-4 h-4 mr-2" />}
|
||||
{uploading ? "Creating Test..." : "Create Test from JSON"}
|
||||
{uploading ? "Creating Test..." : (testType === 'DPP_PDF' ? "Upload PDF to Minio" : "Create Test from JSON")}
|
||||
</Button>
|
||||
</form>
|
||||
</CardContent>
|
||||
|
||||
Reference in New Issue
Block a user