diff --git a/src/pages/content-management/HumanLanguagePage.tsx b/src/pages/content-management/HumanLanguagePage.tsx index 06c6a48..9026667 100644 --- a/src/pages/content-management/HumanLanguagePage.tsx +++ b/src/pages/content-management/HumanLanguagePage.tsx @@ -4,7 +4,7 @@ import { BookOpen, ChevronDown, ChevronRight, Languages, Loader2, Plus } from "l import { Card, CardContent, CardHeader, CardTitle } from "../../components/ui/card" import { Button } from "../../components/ui/button" import { SpinnerIcon } from "../../components/ui/spinner-icon" -import { createHumanLanguageLesson, getHumanLanguageHierarchy } from "../../api/courses.api" +import { createCourse, createHumanLanguageLesson, getHumanLanguageHierarchy } from "../../api/courses.api" import type { HumanLanguageCourseTree, HumanLanguageSubCategoryTree } from "../../types/course.types" import { toast } from "sonner" @@ -20,6 +20,9 @@ export function HumanLanguagePage() { const [selectedLevel, setSelectedLevel] = useState("ALL") const [collapsedLevels, setCollapsedLevels] = useState([]) const [creatingKey, setCreatingKey] = useState(null) + const [quickSubCategoryName, setQuickSubCategoryName] = useState("") + const [quickCourseName, setQuickCourseName] = useState("") + const [quickCreating, setQuickCreating] = useState(false) const loadHierarchy = async () => { setLoading(true) @@ -147,6 +150,35 @@ export function HumanLanguagePage() { } } + const handleQuickCreatePath = async () => { + if (!categoryId) { + toast.error("Human Language category is not available") + return + } + if (!quickSubCategoryName.trim() || !quickCourseName.trim()) { + toast.error("Subcategory and course names are required") + return + } + setQuickCreating(true) + try { + const title = `${quickSubCategoryName.trim()} - ${quickCourseName.trim()}` + await createCourse({ + category_id: categoryId, + title, + description: `${quickSubCategoryName.trim()} / ${quickCourseName.trim()}`, + }) + toast.success("Subcategory/course path created") + setQuickSubCategoryName("") + setQuickCourseName("") + await loadHierarchy() + } catch (error) { + console.error("Failed to quick-create language path:", error) + toast.error("Failed to create subcategory/course path") + } finally { + setQuickCreating(false) + } + } + return (
@@ -235,6 +267,42 @@ export function HumanLanguagePage() {
) : (
+ {availableCourses.length === 0 ? ( + + +

+ No Human Language subcategory/course is available yet. Create the language course path first, then you can add incremental modules and sub-modules per level. +

+
+ setQuickSubCategoryName(e.target.value)} + /> + setQuickCourseName(e.target.value)} + /> + +
+
+ + + + {categoryId ? ( + + + + ) : null} +
+
+
+ ) : null} {CEFR_LEVELS.filter((l) => selectedLevel === "ALL" || l === selectedLevel).map((level) => { const modulesByCourse = selectedCourses .map((course: HumanLanguageCourseTree) => {