feat: Implement LTI deep linking, live sessions, predictive analytics, and portfolios with associated UI and database migrations.

This commit is contained in:
2026-02-24 09:37:16 -03:00
parent 7f7ea3d70c
commit 04dbe05704
81 changed files with 4119 additions and 249 deletions
@@ -0,0 +1,138 @@
"use client";
import React, { useState, useEffect } from "react";
import { lmsApi, DropoutRisk } from "@/lib/api";
import {
AlertCircle,
User,
Mail,
Calendar,
Activity,
Send,
ChevronRight,
Search
} from "lucide-react";
interface DropoutRiskDashboardProps {
courseId: string;
}
export default function DropoutRiskDashboard({ courseId }: DropoutRiskDashboardProps) {
const [risks, setRisks] = useState<DropoutRisk[]>([]);
const [loading, setLoading] = useState(true);
const [searchTerm, setSearchTerm] = useState("");
useEffect(() => {
const fetchRisks = async () => {
try {
const data = await lmsApi.getDropoutRisks(courseId);
setRisks(data);
} catch (err) {
console.error("Failed to fetch dropout risks", err);
} finally {
setLoading(false);
}
};
fetchRisks();
}, [courseId]);
const filteredRisks = risks.filter(r =>
(r.user_full_name || "").toLowerCase().includes(searchTerm.toLowerCase()) ||
(r.user_email || "").toLowerCase().includes(searchTerm.toLowerCase())
);
if (loading) return <div className="p-8 text-center text-gray-500">Calculating risk scores...</div>;
const getRiskColor = (level: string) => {
switch (level) {
case 'critical': return 'text-red-500 bg-red-500/10 border-red-500/20';
case 'high': return 'text-orange-500 bg-orange-500/10 border-orange-500/20';
case 'medium': return 'text-yellow-500 bg-yellow-500/10 border-yellow-500/20';
default: return 'text-green-500 bg-green-500/10 border-green-500/20';
}
};
return (
<div className="space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-700">
<div className="flex flex-col md:flex-row md:items-center justify-between gap-4">
<div>
<h2 className="text-2xl font-black flex items-center gap-3">
<AlertCircle className="text-red-500" />
Dropout Risk Analysis
</h2>
<p className="text-sm text-gray-400 mt-1">AI-powered detection based on grades, activity, and engagement.</p>
</div>
<div className="relative">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-500 w-4 h-4" />
<input
type="text"
placeholder="Search student..."
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
className="bg-white/5 border border-white/10 rounded-xl pl-10 pr-4 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500/50 w-full md:w-64"
/>
</div>
</div>
{filteredRisks.length > 0 ? (
<div className="grid grid-cols-1 gap-4">
{filteredRisks.map((risk) => (
<div key={risk.id} className="bg-white/5 border border-white/10 rounded-2xl p-6 hover:bg-white/[0.07] transition-all group">
<div className="flex flex-col md:flex-row md:items-center justify-between gap-6">
<div className="flex items-center gap-4">
<div className="w-12 h-12 rounded-full bg-blue-500/10 flex items-center justify-center text-blue-400 text-xl font-bold">
{risk.user_full_name?.[0] || <User />}
</div>
<div>
<h3 className="font-bold text-lg">{risk.user_full_name || "Unknown Student"}</h3>
<div className="flex items-center gap-3 text-xs text-gray-500 mt-1">
<span className="flex items-center gap-1"><Mail size={12} /> {risk.user_email || "N/A"}</span>
<span className="flex items-center gap-1"><Calendar size={12} /> Last active: {new Date(risk.last_calculated_at).toLocaleDateString()}</span>
</div>
</div>
</div>
<div className="flex flex-wrap items-center gap-4">
<div className={`px-4 py-2 rounded-xl border text-xs font-black uppercase tracking-widest ${getRiskColor(risk.risk_level)}`}>
{risk.risk_level} Risk
</div>
<div className="flex flex-col items-end min-w-[100px]">
<div className="text-sm font-bold text-gray-400">Score: {Math.round(risk.score * 100)}%</div>
<div className="w-24 h-1 bg-white/5 rounded-full mt-1 overflow-hidden">
<div
className={`h-full transition-all duration-1000 ${risk.score > 0.8 ? 'bg-red-500' : risk.score > 0.5 ? 'bg-orange-500' : 'bg-green-500'}`}
style={{ width: `${risk.score * 100}%` }}
/>
</div>
</div>
<button className="p-3 bg-blue-600/10 text-blue-400 rounded-xl hover:bg-blue-600 hover:text-white transition-all">
<Send size={18} />
</button>
</div>
</div>
{risk.reasons && risk.reasons.length > 0 && (
<div className="mt-6 pt-6 border-t border-white/5 flex flex-wrap gap-3">
{risk.reasons.map((reason, _idx) => (
<div key={_idx} className="bg-white/5 rounded-lg px-3 py-1.5 text-[10px] font-bold text-gray-400 flex items-center gap-2">
<Activity size={10} className="text-blue-500" />
{reason.description}
</div>
))}
</div>
)}
</div>
))}
</div>
) : (
<div className="bg-white/5 border border-white/10 rounded-3xl p-20 text-center">
<User size={48} className="text-gray-600 mx-auto mb-4" />
<h3 className="text-xl font-bold text-gray-400">No students at risk</h3>
<p className="text-sm text-gray-500 mt-2">Everyone seems to be doing great in this course!</p>
</div>
)}
</div>
);
}
@@ -0,0 +1,176 @@
"use client";
import React, { useState, useEffect } from "react";
import { lmsApi, Meeting } from "@/lib/api";
import {
Video,
Plus,
Calendar,
Clock,
Trash2,
ExternalLink,
AlertCircle
} from "lucide-react";
interface LiveSessionsProps {
courseId: string;
}
export default function LiveSessions({ courseId }: LiveSessionsProps) {
const [meetings, setMeetings] = useState<Meeting[]>([]);
const [loading, setLoading] = useState(true);
const [showForm, setShowForm] = useState(false);
const [formData, setFormData] = useState({
title: "",
description: "",
start_at: "",
duration_minutes: 60
});
useEffect(() => {
loadMeetings();
}, [courseId]);
const loadMeetings = async () => {
try {
const data = await lmsApi.getMeetings(courseId);
setMeetings(data);
} catch (err) {
console.error(err);
} finally {
setLoading(false);
}
};
const handleCreate = async (e: React.FormEvent) => {
e.preventDefault();
try {
await lmsApi.createMeeting(courseId, {
...formData,
start_at: new Date(formData.start_at).toISOString()
} as any);
setShowForm(false);
loadMeetings();
} catch (err) {
alert("Failed to create meeting");
}
};
const handleDelete = async (id: string) => {
if (!confirm("Delete this meeting?")) return;
try {
await lmsApi.deleteMeeting(courseId, id);
loadMeetings();
} catch (err) {
alert("Failed to delete");
}
};
if (loading) return <div className="p-8 text-center text-gray-500">Loading sessions...</div>;
return (
<div className="space-y-6">
<div className="flex justify-between items-center">
<div>
<h2 className="text-xl font-bold flex items-center gap-2">
<Video className="text-blue-500" />
Virtual Classrooms
</h2>
<p className="text-sm text-gray-500">Schedule and manage your live Jitsi sessions.</p>
</div>
<button
onClick={() => setShowForm(true)}
className="flex items-center gap-2 bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-xl transition-all"
>
<Plus size={18} /> Schedule Session
</button>
</div>
{showForm && (
<div className="bg-white/5 border border-white/10 rounded-2xl p-6 animate-in slide-in-from-top-4">
<form onSubmit={handleCreate} className="space-y-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="space-y-1">
<label className="text-xs font-bold text-gray-400">SESSION TITLE</label>
<input
required
className="w-full bg-black/20 border border-white/10 rounded-lg px-4 py-2 focus:border-blue-500 outline-none"
placeholder="Weekly Sync Up"
value={formData.title}
onChange={e => setFormData({ ...formData, title: e.target.value })}
/>
</div>
<div className="space-y-1">
<label className="text-xs font-bold text-gray-400">START DATE & TIME</label>
<input
required
type="datetime-local"
className="w-full bg-black/20 border border-white/10 rounded-lg px-4 py-2 focus:border-blue-500 outline-none"
value={formData.start_at}
onChange={e => setFormData({ ...formData, start_at: e.target.value })}
/>
</div>
</div>
<div className="space-y-1">
<label className="text-xs font-bold text-gray-400">DESCRIPTION (OPTIONAL)</label>
<textarea
className="w-full bg-black/20 border border-white/10 rounded-lg px-4 py-2 focus:border-blue-500 outline-none h-20"
value={formData.description}
onChange={e => setFormData({ ...formData, description: e.target.value })}
/>
</div>
<div className="flex justify-end gap-3">
<button type="button" onClick={() => setShowForm(false)} className="px-4 py-2 text-gray-400 hover:text-white">Cancel</button>
<button className="bg-blue-600 px-6 py-2 rounded-lg font-bold">Create Meeting</button>
</div>
</form>
</div>
)}
<div className="grid grid-cols-1 gap-4">
{meetings.map(m => (
<div key={m.id} className="bg-white/5 border border-white/10 rounded-2xl p-5 hover:bg-white/[0.08] transition-all group">
<div className="flex flex-col md:flex-row md:items-center justify-between gap-4">
<div className="flex items-start gap-4">
<div className="w-12 h-12 rounded-xl bg-blue-500/10 flex items-center justify-center text-blue-400">
<Video size={24} />
</div>
<div>
<h3 className="font-bold text-lg">{m.title}</h3>
<div className="flex flex-wrap items-center gap-4 text-xs text-gray-400 mt-1">
<span className="flex items-center gap-1"><Calendar size={14} /> {new Date(m.start_at).toLocaleString()}</span>
<span className="flex items-center gap-1"><Clock size={14} /> {m.duration_minutes} min</span>
<span className="capitalize px-2 py-0.5 bg-white/5 rounded-full border border-white/10">{m.provider}</span>
</div>
</div>
</div>
<div className="flex items-center gap-2">
<a
href={m.join_url}
target="_blank"
rel="noreferrer"
className="flex items-center gap-2 bg-white/10 hover:bg-white/20 px-4 py-2 rounded-xl text-sm font-bold transition-all"
>
Join Room <ExternalLink size={14} />
</a>
<button
onClick={() => handleDelete(m.id)}
className="p-2.5 text-red-400 hover:bg-red-500/10 rounded-xl transition-all opacity-0 group-hover:opacity-100"
>
<Trash2 size={18} />
</button>
</div>
</div>
</div>
))}
{meetings.length === 0 && !loading && (
<div className="p-12 text-center border-2 border-dashed border-white/5 rounded-3xl">
<AlertCircle className="mx-auto text-gray-600 mb-2" />
<p className="text-gray-500">No sessions scheduled for this course.</p>
</div>
)}
</div>
</div>
);
}