Fix Academy new course: use training module selector instead of topic input
The "generate course" feature now shows a list of available training modules to select from, instead of a free-text topic field. This correctly sends the module_id to the backend GenerateCourseFromTraining handler. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import React, { useState } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { useSDK } from '@/lib/sdk'
|
import { useSDK } from '@/lib/sdk'
|
||||||
@@ -11,6 +11,8 @@ import {
|
|||||||
GenerateCourseRequest
|
GenerateCourseRequest
|
||||||
} from '@/lib/sdk/academy/types'
|
} from '@/lib/sdk/academy/types'
|
||||||
import { createCourse, generateCourse } from '@/lib/sdk/academy/api'
|
import { createCourse, generateCourse } from '@/lib/sdk/academy/api'
|
||||||
|
import { getModules } from '@/lib/sdk/training/api'
|
||||||
|
import type { TrainingModule } from '@/lib/sdk/training/types'
|
||||||
|
|
||||||
type CreationMode = 'manual' | 'ai'
|
type CreationMode = 'manual' | 'ai'
|
||||||
|
|
||||||
@@ -27,10 +29,34 @@ export default function NewCoursePage() {
|
|||||||
const [duration, setDuration] = useState(60)
|
const [duration, setDuration] = useState(60)
|
||||||
const [passingScore, setPassingScore] = useState(70)
|
const [passingScore, setPassingScore] = useState(70)
|
||||||
|
|
||||||
// AI generation state
|
// AI generation state - module selection
|
||||||
const [topic, setTopic] = useState('')
|
const [trainingModules, setTrainingModules] = useState<TrainingModule[]>([])
|
||||||
const [targetGroup, setTargetGroup] = useState('Alle Mitarbeiter')
|
const [selectedModuleId, setSelectedModuleId] = useState('')
|
||||||
const [useRag, setUseRag] = useState(true)
|
const [modulesLoading, setModulesLoading] = useState(false)
|
||||||
|
|
||||||
|
// Load training modules on mount
|
||||||
|
useEffect(() => {
|
||||||
|
async function loadModules() {
|
||||||
|
setModulesLoading(true)
|
||||||
|
try {
|
||||||
|
const res = await getModules()
|
||||||
|
// Filter out modules that already have an academy_course_id
|
||||||
|
const available = (res.modules || []).filter(m => !m.academy_course_id)
|
||||||
|
setTrainingModules(available)
|
||||||
|
} catch {
|
||||||
|
// If loading fails, show all modules
|
||||||
|
try {
|
||||||
|
const res = await getModules()
|
||||||
|
setTrainingModules(res.modules || [])
|
||||||
|
} catch {
|
||||||
|
setError('Training-Module konnten nicht geladen werden.')
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setModulesLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loadModules()
|
||||||
|
}, [])
|
||||||
|
|
||||||
const handleManualCreate = async () => {
|
const handleManualCreate = async () => {
|
||||||
if (!title.trim()) {
|
if (!title.trim()) {
|
||||||
@@ -69,25 +95,16 @@ export default function NewCoursePage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleAIGenerate = async () => {
|
const handleAIGenerate = async () => {
|
||||||
if (!topic.trim()) {
|
if (!selectedModuleId) {
|
||||||
setError('Bitte geben Sie ein Thema fuer den Kurs ein.')
|
setError('Bitte waehlen Sie ein Training-Modul aus.')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
setError(null)
|
setError(null)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const tenantId = typeof window !== 'undefined'
|
|
||||||
? localStorage.getItem('bp_tenant_id') || 'default-tenant'
|
|
||||||
: 'default-tenant'
|
|
||||||
|
|
||||||
const result = await generateCourse({
|
const result = await generateCourse({
|
||||||
tenantId,
|
moduleId: selectedModuleId,
|
||||||
topic: topic.trim(),
|
|
||||||
category,
|
|
||||||
targetGroup: targetGroup.trim(),
|
|
||||||
language: 'de',
|
|
||||||
useRag
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (result && result.course && result.course.id) {
|
if (result && result.course && result.course.id) {
|
||||||
@@ -174,82 +191,63 @@ export default function NewCoursePage() {
|
|||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M13 10V3L4 14h7v7l9-11h-7z" />
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M13 10V3L4 14h7v7l9-11h-7z" />
|
||||||
</svg>
|
</svg>
|
||||||
<div>
|
<div>
|
||||||
<h3 className="font-medium text-purple-800">KI-generierter Kurs</h3>
|
<h3 className="font-medium text-purple-800">Kurs aus Training-Modul generieren</h3>
|
||||||
<p className="text-sm text-purple-600 mt-1">
|
<p className="text-sm text-purple-600 mt-1">
|
||||||
Die KI erstellt automatisch Lektionen, Inhalte und Quizfragen basierend auf dem gewaehlten Thema.
|
Waehlen Sie ein bestehendes Training-Modul aus. Der Academy-Kurs wird automatisch mit den generierten Inhalten und Quizfragen erstellt.
|
||||||
Optionaler RAG-Kontext aus relevanten Gesetzestexten wird einbezogen.
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Topic */}
|
{/* Module Selection */}
|
||||||
<div>
|
{modulesLoading ? (
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-2">Schulungsthema *</label>
|
<div className="flex items-center gap-3 py-8 justify-center text-gray-500">
|
||||||
<input
|
<svg className="animate-spin w-5 h-5" fill="none" viewBox="0 0 24 24">
|
||||||
type="text"
|
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
||||||
value={topic}
|
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" />
|
||||||
onChange={(e) => setTopic(e.target.value)}
|
</svg>
|
||||||
placeholder="z.B. DSGVO-Grundlagen fuer neue Mitarbeiter"
|
Training-Module werden geladen...
|
||||||
className="w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-purple-500 focus:border-purple-500 text-base"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Category */}
|
|
||||||
<div>
|
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-2">Kategorie *</label>
|
|
||||||
<div className="grid grid-cols-2 md:grid-cols-3 gap-3">
|
|
||||||
{Object.entries(COURSE_CATEGORY_INFO).map(([cat, info]) => (
|
|
||||||
<button
|
|
||||||
key={cat}
|
|
||||||
type="button"
|
|
||||||
onClick={() => setCategory(cat as CourseCategory)}
|
|
||||||
className={`p-4 rounded-xl border-2 text-left transition-all ${
|
|
||||||
category === cat
|
|
||||||
? 'border-purple-500 bg-purple-50'
|
|
||||||
: 'border-gray-200 hover:border-gray-300'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<div className={`text-sm font-medium ${category === cat ? 'text-purple-700' : 'text-gray-700'}`}>
|
|
||||||
{info.label}
|
|
||||||
</div>
|
|
||||||
<div className="text-xs text-gray-500 mt-1 line-clamp-2">{info.description}</div>
|
|
||||||
</button>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
) : trainingModules.length === 0 ? (
|
||||||
|
<div className="text-center py-8">
|
||||||
{/* Target Group */}
|
<p className="text-gray-500">Keine verfuegbaren Training-Module gefunden.</p>
|
||||||
<div>
|
<p className="text-sm text-gray-400 mt-1">Alle Module haben bereits einen Academy-Kurs oder es existieren noch keine Module.</p>
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-2">Zielgruppe</label>
|
</div>
|
||||||
<input
|
) : (
|
||||||
type="text"
|
|
||||||
value={targetGroup}
|
|
||||||
onChange={(e) => setTargetGroup(e.target.value)}
|
|
||||||
placeholder="z.B. Alle Mitarbeiter, IT-Abteilung, Fuehrungskraefte"
|
|
||||||
className="w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-purple-500 focus:border-purple-500"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* RAG Toggle */}
|
|
||||||
<div className="flex items-center gap-3">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => setUseRag(!useRag)}
|
|
||||||
className={`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${
|
|
||||||
useRag ? 'bg-purple-600' : 'bg-gray-300'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
className={`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${
|
|
||||||
useRag ? 'translate-x-6' : 'translate-x-1'
|
|
||||||
}`}
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
<div>
|
<div>
|
||||||
<span className="text-sm font-medium text-gray-700">RAG-Kontext verwenden</span>
|
<label className="block text-sm font-medium text-gray-700 mb-2">Training-Modul auswählen *</label>
|
||||||
<p className="text-xs text-gray-500">Relevante Gesetzestexte (DSGVO, AI Act, NIS2) einbeziehen</p>
|
<div className="grid gap-3 max-h-[400px] overflow-y-auto pr-2">
|
||||||
|
{trainingModules.map((mod) => (
|
||||||
|
<button
|
||||||
|
key={mod.id}
|
||||||
|
type="button"
|
||||||
|
onClick={() => setSelectedModuleId(mod.id)}
|
||||||
|
className={`p-4 rounded-xl border-2 text-left transition-all ${
|
||||||
|
selectedModuleId === mod.id
|
||||||
|
? 'border-purple-500 bg-purple-50'
|
||||||
|
: 'border-gray-200 hover:border-gray-300'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div className={`text-sm font-medium ${selectedModuleId === mod.id ? 'text-purple-700' : 'text-gray-700'}`}>
|
||||||
|
{mod.title}
|
||||||
|
</div>
|
||||||
|
<span className="text-xs px-2 py-1 rounded-full bg-gray-100 text-gray-600">
|
||||||
|
{mod.regulation_area}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{mod.description && (
|
||||||
|
<div className="text-xs text-gray-500 mt-1 line-clamp-2">{mod.description}</div>
|
||||||
|
)}
|
||||||
|
<div className="flex gap-3 mt-2 text-xs text-gray-400">
|
||||||
|
<span>{mod.duration_minutes} Min.</span>
|
||||||
|
<span>{mod.frequency_type}</span>
|
||||||
|
<span>{mod.module_code}</span>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
|
|
||||||
{/* Submit */}
|
{/* Submit */}
|
||||||
<div className="flex justify-end gap-3 pt-4 border-t border-gray-200">
|
<div className="flex justify-end gap-3 pt-4 border-t border-gray-200">
|
||||||
@@ -261,7 +259,7 @@ export default function NewCoursePage() {
|
|||||||
</Link>
|
</Link>
|
||||||
<button
|
<button
|
||||||
onClick={handleAIGenerate}
|
onClick={handleAIGenerate}
|
||||||
disabled={isLoading || !topic.trim()}
|
disabled={isLoading || !selectedModuleId}
|
||||||
className="px-6 py-2.5 bg-purple-600 text-white rounded-xl hover:bg-purple-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2"
|
className="px-6 py-2.5 bg-purple-600 text-white rounded-xl hover:bg-purple-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2"
|
||||||
>
|
>
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
@@ -270,7 +268,7 @@ export default function NewCoursePage() {
|
|||||||
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
||||||
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" />
|
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" />
|
||||||
</svg>
|
</svg>
|
||||||
KI generiert Kurs...
|
Kurs wird generiert...
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
|
|||||||
Reference in New Issue
Block a user