+
+
+
+ Content
+
+
+ Initial placement assessment
+
+
+ Manage the single learner placement test, its questions, and the A1–C2 score thresholds used
+ when grading submissions.
+
+
+
+
+ {published ? "Published" : "Draft"}
+
+
+ Live for learners
+ void handlePublishToggle(!published)}
+ disabled={savingSet}
+ aria-label="Publish placement assessment"
+ />
+
+
void loadSet()} disabled={loading}>
+
+ Refresh
+
+
+
+
+
+
+
+
+
+
Questions
+
+ {setDetail.question_count ?? questions.length}
+
+
+
+
+
+
+
+
+
Total points
+
{totalPoints}
+
+
+
+
+
+
+ {(
+ [
+ { id: "set", label: "Placement set" },
+ { id: "questions", label: "Questions" },
+ { id: "thresholds", label: "Score thresholds" },
+ ] as const
+ ).map((item) => (
+ setTab(item.id)}
+ className={cn(
+ "shrink-0 border-b-2 px-4 py-3 text-sm font-medium transition-colors",
+ tab === item.id
+ ? "border-brand-500 text-brand-600"
+ : "border-transparent text-grayScale-500 hover:text-grayScale-700",
+ )}
+ >
+ {item.label}
+
+ ))}
+
+
+ {tab === "set" && (
+
+
+ Placement set settings
+ void handleSaveSet()} disabled={savingSet}>
+
+ {savingSet ? "Saving…" : "Save"}
+
+
+
+
+ Title
+ setTitle(e.target.value)} />
+
+
+
+ Description
+
+
+
+
+ Time limit (minutes)
+
+ setTimeLimit(e.target.value)}
+ placeholder="Optional"
+ />
+
+
+
+
Shuffle questions
+
Randomize order for each learner attempt
+
+
setShuffle((v) => !v)} />
+
+
+
+ )}
+
+ {tab === "questions" && (
+
+
+
+
Placement questions
+
+ Multiple choice and true/false only. Publish each question so it appears in the mobile
+ placement test.
+
+
+
+
+ Add question
+
+
+
+
+
+ setQuestionsSearch(e.target.value)}
+ placeholder="Search by text, ID, type, difficulty, or status…"
+ className="pl-9"
+ aria-label="Search placement questions"
+ />
+
+
+
+
+
+
+ #
+ Question
+ Type
+ Difficulty
+ Points
+ Published
+ Actions
+
+
+
+ {questionsLoading ? (
+
+
+
+
+ Loading questions…
+
+
+
+ ) : questionsSorted.length === 0 ? (
+
+
+
+
+
+
No questions yet
+
+ Add multiple choice or true/false items to get started.
+
+
+
+
+
+ ) : filteredQuestions.length === 0 ? (
+
+
+
+
+
+
No matching questions
+
+ Try a different search, or clear the search box.
+
+
+
+
+
+ ) : (
+ paginatedQuestions.map((q, idx) => (
+
+
+ {(safeQuestionsPage - 1) * questionsPageSize + idx + 1}
+
+
+
+
+ {q.questionText}
+
+
+ {typeLabels[q.questionType] ?? q.questionType}
+ {" · "}
+ {q.points} pts
+
+
ID #{q.questionId}
+
+
+
+
+ {typeLabels[q.questionType] ?? q.questionType}
+
+
+
+
+ {(() => {
+ const value = String(q.difficultyLevel ?? "").trim()
+ if (!value || value === "—" || value === "-") return "unassigned"
+ return value.toLowerCase()
+ })()}
+
+
+
+ {Number.isFinite(q.points) ? q.points : "unassigned"}
+
+ e.stopPropagation()}>
+
+ void handleToggleQuestionStatus(q)}
+ aria-label={
+ String(q.status).toUpperCase() === "PUBLISHED"
+ ? `Unpublish question ${q.questionId}`
+ : `Publish question ${q.questionId}`
+ }
+ />
+
+ {String(q.status).toUpperCase() === "PUBLISHED" ? "Live" : "Draft"}
+
+
+
+
+
+
void openEditQuestion(q.questionId)}
+ aria-label={`Edit question ${q.questionId}`}
+ >
+
+
+
void handleRemoveQuestion(q.questionId)}
+ aria-label={`Remove question ${q.questionId}`}
+ >
+
+
+
+
+
+ ))
+ )}
+
+
+
{
+ setQuestionsPageSize(size)
+ setQuestionsPage(1)
+ }}
+ currentPage={safeQuestionsPage}
+ totalPages={questionsPageCount}
+ onPageChange={setQuestionsPage}
+ disabled={questionsLoading}
+ />
+
+
+ )}
+
+ {tab === "thresholds" &&
}
+
+ {addOpen && (
+
+
+
+
+ {editingQuestionId != null ? "Edit placement question" : "Add placement question"}
+
+
+
+
+
+ {formLoading ? (
+
+
+
+ ) : (
+ <>
+
+
+ Type
+
+ setDraft((d) => ({
+ ...d,
+ questionType: e.target.value as DraftQuestionType,
+ options:
+ e.target.value === "TRUE_FALSE"
+ ? [
+ { text: "True", isCorrect: true },
+ { text: "False", isCorrect: false },
+ ]
+ : emptyDraft().options,
+ }))
+ }
+ >
+ Multiple choice
+ True / False
+
+
+
+
+ Question text
+
+
+
+
+
+ Difficulty
+
+
+ setDraft((d) => ({
+ ...d,
+ difficulty: e.target.value as QuestionDraft["difficulty"],
+ }))
+ }
+ >
+ Easy
+ Medium
+ Hard
+
+
+
+
+ Points
+
+ setDraft((d) => ({ ...d, points: Number(e.target.value) || 1 }))}
+ />
+
+
+
+
+
+ Options
+
+ {draft.options.map((opt, idx) => (
+
+
+ setDraft((d) => ({
+ ...d,
+ options: d.options.map((o, i) => ({ ...o, isCorrect: i === idx })),
+ }))
+ }
+ />
+
+ setDraft((d) => ({
+ ...d,
+ options: d.options.map((o, i) =>
+ i === idx ? { ...o, text: e.target.value } : o,
+ ),
+ }))
+ }
+ placeholder={`Option ${idx + 1}`}
+ disabled={draft.questionType === "TRUE_FALSE"}
+ />
+
+ ))}
+
+
+
+
+ Tips
+
+ setDraft((d) => ({ ...d, tips: e.target.value }))}
+ />
+
+
+
+ Explanation
+
+
+
+
+
+ Cancel
+
+ void handleSaveQuestion()}
+ disabled={savingQuestion || formLoading}
+ >
+ {savingQuestion
+ ? "Saving…"
+ : editingQuestionId != null
+ ? "Save changes"
+ : "Add question"}
+
+
+ >
+ )}
+
+
+ )}
+
+ )
+}
diff --git a/src/pages/settings/InitialAssessmentThresholdsTab.tsx b/src/pages/settings/InitialAssessmentThresholdsTab.tsx
new file mode 100644
index 0000000..a620003
--- /dev/null
+++ b/src/pages/settings/InitialAssessmentThresholdsTab.tsx
@@ -0,0 +1,173 @@
+import { Link } from "react-router-dom"
+import { useCallback, useEffect, useState } from "react"
+import { Gauge, RefreshCw, Save } from "lucide-react"
+import { toast } from "sonner"
+import {
+ getInitialAssessmentLevelThresholds,
+ updateInitialAssessmentLevelThresholds,
+ type InitialAssessmentLevelThreshold,
+} from "../../api/initial-assessment.api"
+import { notifyApiError } from "../../lib/apiErrors"
+import { Button } from "../../components/ui/button"
+import { Card, CardContent, CardHeader, CardTitle } from "../../components/ui/card"
+import { Input } from "../../components/ui/input"
+import { SpinnerIcon } from "../../components/ui/spinner-icon"
+
+const LEVEL_ORDER = ["A1", "A2", "B1", "B2", "C1", "C2"] as const
+
+const DEFAULTS: InitialAssessmentLevelThreshold[] = [
+ { level: "A1", min_percent: 0, display_order: 1 },
+ { level: "A2", min_percent: 17, display_order: 2 },
+ { level: "B1", min_percent: 34, display_order: 3 },
+ { level: "B2", min_percent: 51, display_order: 4 },
+ { level: "C1", min_percent: 68, display_order: 5 },
+ { level: "C2", min_percent: 85, display_order: 6 },
+]
+
+function ensureAllLevels(rows: InitialAssessmentLevelThreshold[]): InitialAssessmentLevelThreshold[] {
+ const byLevel = new Map(rows.map((row) => [String(row.level).toUpperCase(), row]))
+ return LEVEL_ORDER.map((level, index) => {
+ const existing = byLevel.get(level)
+ return {
+ level,
+ min_percent: existing?.min_percent ?? DEFAULTS[index].min_percent,
+ display_order: index + 1,
+ }
+ })
+}
+
+function validateRows(rows: InitialAssessmentLevelThreshold[]): string | null {
+ if (rows[0]?.min_percent !== 0) return "A1 minimum score must be 0%."
+ for (let i = 0; i < rows.length; i++) {
+ const value = rows[i].min_percent
+ if (!Number.isFinite(value) || value < 0 || value > 100) {
+ return `${rows[i].level} minimum must be between 0 and 100.`
+ }
+ if (i > 0 && value <= rows[i - 1].min_percent) {
+ return `${rows[i].level} minimum must be greater than ${rows[i - 1].level}.`
+ }
+ }
+ return null
+}
+
+export function InitialAssessmentThresholdsTab() {
+ const [loading, setLoading] = useState(true)
+ const [saving, setSaving] = useState(false)
+ const [rows, setRows] = useState