user nouveau onglet
This commit is contained in:
29
app/api/debug-users/route.ts
Normal file
29
app/api/debug-users/route.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getDatabase } from "@/lib/db/mongodb";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const db = await getDatabase();
|
||||
|
||||
// Récupérer 5 users pour debug
|
||||
const users = await db.collection("users")
|
||||
.find({ referent: { $exists: true } })
|
||||
.limit(5)
|
||||
.toArray();
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
count: users.length,
|
||||
users: users.map(u => ({
|
||||
_id: u._id,
|
||||
name: u.name,
|
||||
email: u.email,
|
||||
referent: u.referent,
|
||||
cours: u.cours,
|
||||
})),
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Debug error:", error);
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ export default function ConversationsPage() {
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight">Conversations</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Gestion des conversations Cercle GPTT
|
||||
Gestion des conversations Cercle GPT
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
194
app/referents/[referent]/[cours]/page.tsx
Normal file
194
app/referents/[referent]/[cours]/page.tsx
Normal file
@@ -0,0 +1,194 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect, useMemo } from "react";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { ArrowLeft, Mail } from "lucide-react";
|
||||
import { formatDate } from "@/lib/utils";
|
||||
import { LibreChatUser, LibreChatBalance } from "@/lib/types";
|
||||
import { useCollection } from "@/hooks/useCollection";
|
||||
|
||||
// Couleurs prédéfinies pour les référents
|
||||
const REFERENT_COLORS: Record<string, string> = {
|
||||
"Emmanuel WATHELE": "#3B82F6",
|
||||
"IHECS": "#10B981",
|
||||
};
|
||||
|
||||
export default function CoursDetailPage() {
|
||||
const params = useParams();
|
||||
const router = useRouter();
|
||||
const referent = decodeURIComponent(params.referent as string);
|
||||
const cours = decodeURIComponent(params.cours as string);
|
||||
|
||||
const [students, setStudents] = useState<LibreChatUser[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
// Charger tous les balances
|
||||
const { data: balances = [] } = useCollection<LibreChatBalance>("balances", {
|
||||
limit: 1000,
|
||||
});
|
||||
|
||||
// Créer une map des crédits par utilisateur
|
||||
const creditsMap = useMemo(() => {
|
||||
const map = new Map<string, number>();
|
||||
balances.forEach((balance) => {
|
||||
map.set(balance.user, balance.tokenCredits || 0);
|
||||
});
|
||||
return map;
|
||||
}, [balances]);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchStudents = async () => {
|
||||
try {
|
||||
const response = await fetch(
|
||||
"/api/collections/users?page=1&limit=1000&filter={}"
|
||||
);
|
||||
const result = await response.json();
|
||||
|
||||
if (result.data) {
|
||||
// Filtrer les étudiants pour ce référent et ce cours
|
||||
const filtered = result.data.filter(
|
||||
(user: any) =>
|
||||
user.referent === referent && user.cours === cours
|
||||
);
|
||||
setStudents(filtered);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Erreur lors du chargement des étudiants:", error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchStudents();
|
||||
}, [referent, cours]);
|
||||
|
||||
const couleur = REFERENT_COLORS[referent] || "#6B7280";
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => router.push("/referents")}
|
||||
className="mb-4"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4 mr-2" />
|
||||
Retour aux référents
|
||||
</Button>
|
||||
<Card>
|
||||
<CardContent className="p-6">
|
||||
<div className="space-y-4">
|
||||
{Array.from({ length: 5 }).map((_, i) => (
|
||||
<div key={i} className="h-16 bg-muted animate-pulse rounded" />
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => router.push("/referents")}
|
||||
className="mb-4"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4 mr-2" />
|
||||
Retour aux référents
|
||||
</Button>
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
<div
|
||||
className="w-6 h-6 rounded-full flex-shrink-0"
|
||||
style={{ backgroundColor: couleur }}
|
||||
/>
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight">{referent}</h1>
|
||||
<p className="text-muted-foreground">{cours}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex items-center justify-between">
|
||||
<CardTitle>
|
||||
Étudiants ({students.length})
|
||||
</CardTitle>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{students.length === 0 ? (
|
||||
<div className="text-center py-12">
|
||||
<p className="text-sm text-gray-500">
|
||||
Aucun étudiant dans ce cours
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="rounded-md border">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Nom</TableHead>
|
||||
<TableHead>Email</TableHead>
|
||||
<TableHead>Rôle</TableHead>
|
||||
<TableHead>Crédits</TableHead>
|
||||
<TableHead>Créé le</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{students.map((student) => (
|
||||
<TableRow key={student._id}>
|
||||
<TableCell>
|
||||
<div className="flex items-center gap-2">
|
||||
<div
|
||||
className="w-2 h-2 rounded-full"
|
||||
style={{ backgroundColor: couleur }}
|
||||
/>
|
||||
<span className="font-medium">
|
||||
{student.prenom} {student.nom}
|
||||
</span>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex items-center gap-2">
|
||||
<Mail className="h-4 w-4 text-gray-400" />
|
||||
<span className="text-sm">{student.email}</span>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant={student.role === "ADMIN" ? "default" : "secondary"}>
|
||||
{student.role}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<span className="text-sm">
|
||||
{(creditsMap.get(student._id) || 0).toLocaleString()} tokens
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell className="text-sm text-gray-500">
|
||||
{formatDate(student.createdAt)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
183
app/referents/page.tsx
Normal file
183
app/referents/page.tsx
Normal file
@@ -0,0 +1,183 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { GraduationCap, Users, ChevronRight } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
|
||||
// Couleurs prédéfinies pour les référents
|
||||
const REFERENT_COLORS: Record<string, string> = {
|
||||
"Emmanuel WATHELE": "#3B82F6", // Bleu
|
||||
"IHECS": "#10B981", // Vert
|
||||
};
|
||||
|
||||
interface ReferentData {
|
||||
nom: string;
|
||||
couleur: string;
|
||||
cours: string[];
|
||||
nombreEtudiants: number;
|
||||
}
|
||||
|
||||
export default function ReferentsPage() {
|
||||
const [referents, setReferents] = useState<ReferentData[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchReferents = async () => {
|
||||
try {
|
||||
// Récupérer tous les users pour compter par référent
|
||||
const response = await fetch(
|
||||
"/api/collections/users?page=1&limit=1000&filter={}"
|
||||
);
|
||||
const result = await response.json();
|
||||
|
||||
if (result.data) {
|
||||
// Grouper par référent
|
||||
const referentsMap = new Map<string, ReferentData>();
|
||||
|
||||
result.data.forEach((user: any) => {
|
||||
if (user.referent) {
|
||||
if (!referentsMap.has(user.referent)) {
|
||||
referentsMap.set(user.referent, {
|
||||
nom: user.referent,
|
||||
couleur: REFERENT_COLORS[user.referent] || "#6B7280", // Gris par défaut
|
||||
cours: [],
|
||||
nombreEtudiants: 0,
|
||||
});
|
||||
}
|
||||
|
||||
const ref = referentsMap.get(user.referent)!;
|
||||
ref.nombreEtudiants++;
|
||||
|
||||
// Ajouter le cours s'il n'existe pas déjà
|
||||
if (user.cours && !ref.cours.includes(user.cours)) {
|
||||
ref.cours.push(user.cours);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setReferents(Array.from(referentsMap.values()));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Erreur lors du chargement des référents:", error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchReferents();
|
||||
}, []);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight">Référents</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Gestion des référents et leurs cours
|
||||
</p>
|
||||
</div>
|
||||
<Card>
|
||||
<CardContent className="p-6">
|
||||
<div className="space-y-4">
|
||||
{Array.from({ length: 3 }).map((_, i) => (
|
||||
<div key={i} className="h-24 bg-muted animate-pulse rounded" />
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (referents.length === 0) {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight">Référents</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Gestion des référents et leurs cours
|
||||
</p>
|
||||
</div>
|
||||
<Card>
|
||||
<CardContent className="p-6">
|
||||
<div className="text-center py-12">
|
||||
<GraduationCap className="mx-auto h-12 w-12 text-gray-400" />
|
||||
<h3 className="mt-2 text-sm font-semibold text-gray-900">
|
||||
Aucun référent
|
||||
</h3>
|
||||
<p className="mt-1 text-sm text-gray-500">
|
||||
Importez des utilisateurs avec référents pour commencer.
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight">Référents</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Gestion des référents et leurs cours
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4">
|
||||
{referents.map((referent) => (
|
||||
<Card key={referent.nom} className="hover:shadow-md transition-shadow">
|
||||
<CardHeader>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
{/* Point coloré */}
|
||||
<div
|
||||
className="w-4 h-4 rounded-full flex-shrink-0"
|
||||
style={{ backgroundColor: referent.couleur }}
|
||||
/>
|
||||
<div>
|
||||
<CardTitle className="text-xl">{referent.nom}</CardTitle>
|
||||
<div className="flex items-center gap-2 mt-1">
|
||||
<Users className="h-4 w-4 text-gray-500" />
|
||||
<span className="text-sm text-gray-500">
|
||||
{referent.nombreEtudiants} étudiant
|
||||
{referent.nombreEtudiants > 1 ? "s" : ""}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-3">
|
||||
<h4 className="text-sm font-semibold text-gray-700">Cours :</h4>
|
||||
<div className="space-y-2">
|
||||
{referent.cours.map((cours) => (
|
||||
<Link
|
||||
key={cours}
|
||||
href={`/referents/${encodeURIComponent(referent.nom)}/${encodeURIComponent(cours)}`}
|
||||
>
|
||||
<div className="flex items-center justify-between p-3 bg-gray-50 hover:bg-gray-100 rounded-lg transition-colors cursor-pointer">
|
||||
<div className="flex items-center gap-2">
|
||||
<div
|
||||
className="w-2 h-2 rounded-full"
|
||||
style={{ backgroundColor: referent.couleur }}
|
||||
/>
|
||||
<span className="text-sm font-medium">{cours}</span>
|
||||
</div>
|
||||
<ChevronRight className="h-4 w-4 text-gray-400" />
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -6,7 +6,7 @@ export default function UsersPage() {
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight">Utilisateurs</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Gestion des utilisateurs Cercle GPTT
|
||||
Gestion des utilisateurs Cercle GPT
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user