Checkpoint: Ajout de 3 améliorations pour le système de notifications :
1. Interface de gestion des emails formateurs (Configuration > Formateurs) - permet de gérer les adresses email des formateurs pour activer/désactiver les notifications 2. Tableau de bord des notifications (Configuration > Notifications) - historique complet des emails envoyés avec filtres et statistiques 3. Lien vers questionnaire de satisfaction automatiquement inclus dans l'email de remerciement post-formation
This commit is contained in:
@@ -27,6 +27,8 @@ import AdminQuestionnaireAnalyse from "./pages/AdminQuestionnaireAnalyse";
|
||||
import AdminQuestionnaireSuivi from "./pages/AdminQuestionnaireSuivi";
|
||||
import AdminRappelsHistorique from "./pages/admin/AdminRappelsHistorique";
|
||||
import AdminRappelsStats from "./pages/admin/AdminRappelsStats";
|
||||
import AdminFormateurs from "./pages/admin/AdminFormateurs";
|
||||
import AdminNotifications from "./pages/admin/AdminNotifications";
|
||||
import QuestionnaireReponse from "./pages/QuestionnaireReponse";
|
||||
import Inscription from "./pages/Inscription";
|
||||
import Login from "./pages/Login";
|
||||
@@ -49,6 +51,8 @@ function Router() {
|
||||
<Route path={"/admin/apprenants/:id"} component={AdminApprenantDetail} />
|
||||
<Route path={"/admin/sequences/:id/inscrits"} component={AdminSequenceInscrits} />
|
||||
<Route path={"/admin/users"} component={AdminUsers} />
|
||||
<Route path={"/admin/formateurs"} component={AdminFormateurs} />
|
||||
<Route path={"/admin/notifications"} component={AdminNotifications} />
|
||||
<Route path={"/admin/email-templates"} component={AdminEmailTemplates} />
|
||||
<Route path={"/admin/email-config"} component={AdminEmailConfig} />
|
||||
<Route path={"/admin/calendrier"} component={AdminCalendrier} />
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
} from "@/components/ui/sidebar";
|
||||
import { APP_LOGO, APP_TITLE, getLoginUrl } from "@/const";
|
||||
import { useIsMobile } from "@/hooks/useMobile";
|
||||
import { LayoutDashboard, LogOut, PanelLeft, Users, GraduationCap, Calendar, CalendarDays, Bell, BarChart3, UserCog, Mail, Settings, TrendingUp, Building2, FileSpreadsheet, ClipboardList, ChevronDown } from "lucide-react";
|
||||
import { LayoutDashboard, LogOut, PanelLeft, Users, GraduationCap, Calendar, CalendarDays, Bell, BarChart3, UserCog, Mail, Settings, TrendingUp, Building2, FileSpreadsheet, ClipboardList, ChevronDown, User } from "lucide-react";
|
||||
import { CSSProperties, useEffect, useRef, useState } from "react";
|
||||
import { useLocation } from "wouter";
|
||||
import { DashboardLayoutSkeleton } from './DashboardLayoutSkeleton';
|
||||
@@ -47,6 +47,7 @@ const menuSections = [
|
||||
title: "Configuration",
|
||||
items: [
|
||||
{ icon: UserCog, label: "Utilisateurs", path: "/admin/users" },
|
||||
{ icon: User, label: "Formateurs", path: "/admin/formateurs" },
|
||||
{ icon: FileSpreadsheet, label: "Import Excel", path: "/admin/import-excel" },
|
||||
{ icon: Bell, label: "Rappels", path: "/admin/rappels", subItems: [
|
||||
{ label: "Historique", path: "/admin/rappels/historique" },
|
||||
@@ -55,6 +56,7 @@ const menuSections = [
|
||||
{ icon: ClipboardList, label: "Questionnaires", path: "/admin/questionnaires" },
|
||||
{ icon: Mail, label: "Templates d'emails", path: "/admin/email-templates" },
|
||||
{ icon: Settings, label: "Configuration SMTP", path: "/admin/email-config" },
|
||||
{ icon: Mail, label: "Notifications", path: "/admin/notifications" },
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
422
client/src/pages/admin/AdminFormateurs.tsx
Normal file
422
client/src/pages/admin/AdminFormateurs.tsx
Normal file
@@ -0,0 +1,422 @@
|
||||
import { useState } from "react";
|
||||
import { trpc } from "@/lib/trpc";
|
||||
import DashboardLayout from "@/components/DashboardLayout";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { toast } from "sonner";
|
||||
import { Plus, Pencil, Trash2, Mail, User, AlertCircle, CheckCircle2 } from "lucide-react";
|
||||
|
||||
export default function AdminFormateurs() {
|
||||
const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false);
|
||||
const [isEditDialogOpen, setIsEditDialogOpen] = useState(false);
|
||||
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false);
|
||||
const [selectedFormateur, setSelectedFormateur] = useState<{
|
||||
id: number;
|
||||
nom: string;
|
||||
email: string | null;
|
||||
} | null>(null);
|
||||
const [formData, setFormData] = useState({
|
||||
nom: "",
|
||||
email: "",
|
||||
});
|
||||
|
||||
const { data: formateurs, isLoading, refetch } = trpc.formateurs.list.useQuery();
|
||||
const createMutation = trpc.formateurs.create.useMutation({
|
||||
onSuccess: () => {
|
||||
toast.success("Formateur créé avec succès");
|
||||
setIsCreateDialogOpen(false);
|
||||
setFormData({ nom: "", email: "" });
|
||||
refetch();
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error(`Erreur: ${error.message}`);
|
||||
},
|
||||
});
|
||||
const updateMutation = trpc.formateurs.update.useMutation({
|
||||
onSuccess: () => {
|
||||
toast.success("Formateur mis à jour avec succès");
|
||||
setIsEditDialogOpen(false);
|
||||
setSelectedFormateur(null);
|
||||
refetch();
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error(`Erreur: ${error.message}`);
|
||||
},
|
||||
});
|
||||
const deleteMutation = trpc.formateurs.delete.useMutation({
|
||||
onSuccess: () => {
|
||||
toast.success("Formateur supprimé avec succès");
|
||||
setIsDeleteDialogOpen(false);
|
||||
setSelectedFormateur(null);
|
||||
refetch();
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error(`Erreur: ${error.message}`);
|
||||
},
|
||||
});
|
||||
|
||||
const handleCreate = () => {
|
||||
if (!formData.nom.trim()) {
|
||||
toast.error("Le nom est obligatoire");
|
||||
return;
|
||||
}
|
||||
createMutation.mutate({
|
||||
nom: formData.nom.trim(),
|
||||
email: formData.email.trim() || undefined,
|
||||
});
|
||||
};
|
||||
|
||||
const handleEdit = () => {
|
||||
if (!selectedFormateur) return;
|
||||
if (!formData.nom.trim()) {
|
||||
toast.error("Le nom est obligatoire");
|
||||
return;
|
||||
}
|
||||
updateMutation.mutate({
|
||||
id: selectedFormateur.id,
|
||||
nom: formData.nom.trim(),
|
||||
email: formData.email.trim() || null,
|
||||
});
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
if (!selectedFormateur) return;
|
||||
deleteMutation.mutate({ id: selectedFormateur.id });
|
||||
};
|
||||
|
||||
const openEditDialog = (formateur: { id: number; nom: string; email: string | null }) => {
|
||||
setSelectedFormateur(formateur);
|
||||
setFormData({
|
||||
nom: formateur.nom,
|
||||
email: formateur.email || "",
|
||||
});
|
||||
setIsEditDialogOpen(true);
|
||||
};
|
||||
|
||||
const openDeleteDialog = (formateur: { id: number; nom: string; email: string | null }) => {
|
||||
setSelectedFormateur(formateur);
|
||||
setIsDeleteDialogOpen(true);
|
||||
};
|
||||
|
||||
const formateursSansEmail = formateurs?.filter((f) => !f.email) || [];
|
||||
const formateursAvecEmail = formateurs?.filter((f) => f.email) || [];
|
||||
|
||||
return (
|
||||
<DashboardLayout>
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold">Gestion des Formateurs</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Gérez les formateurs et leurs adresses email pour les notifications
|
||||
</p>
|
||||
</div>
|
||||
<Button onClick={() => {
|
||||
setFormData({ nom: "", email: "" });
|
||||
setIsCreateDialogOpen(true);
|
||||
}}>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
Ajouter un formateur
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Alerte si des formateurs n'ont pas d'email */}
|
||||
{formateursSansEmail.length > 0 && (
|
||||
<Card className="border-orange-200 bg-orange-50">
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-orange-700 flex items-center gap-2 text-base">
|
||||
<AlertCircle className="h-5 w-5" />
|
||||
Formateurs sans email ({formateursSansEmail.length})
|
||||
</CardTitle>
|
||||
<CardDescription className="text-orange-600">
|
||||
Ces formateurs ne recevront pas les notifications d'inscription et d'annulation.
|
||||
Ajoutez leur adresse email pour activer les notifications.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{formateursSansEmail.map((f) => (
|
||||
<Badge
|
||||
key={f.id}
|
||||
variant="outline"
|
||||
className="cursor-pointer hover:bg-orange-100 border-orange-300"
|
||||
onClick={() => openEditDialog(f)}
|
||||
>
|
||||
{f.nom}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{/* Statistiques */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-muted-foreground">
|
||||
Total formateurs
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex items-center gap-2">
|
||||
<User className="h-5 w-5 text-blue-500" />
|
||||
<span className="text-2xl font-bold">{formateurs?.length || 0}</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-muted-foreground">
|
||||
Avec email configuré
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex items-center gap-2">
|
||||
<CheckCircle2 className="h-5 w-5 text-green-500" />
|
||||
<span className="text-2xl font-bold">{formateursAvecEmail.length}</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-muted-foreground">
|
||||
Sans email (pas de notifications)
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex items-center gap-2">
|
||||
<AlertCircle className="h-5 w-5 text-orange-500" />
|
||||
<span className="text-2xl font-bold">{formateursSansEmail.length}</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Tableau des formateurs */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Liste des formateurs</CardTitle>
|
||||
<CardDescription>
|
||||
Cliquez sur un formateur pour modifier ses informations
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{isLoading ? (
|
||||
<div className="text-center py-8 text-muted-foreground">
|
||||
Chargement...
|
||||
</div>
|
||||
) : formateurs?.length === 0 ? (
|
||||
<div className="text-center py-8 text-muted-foreground">
|
||||
Aucun formateur enregistré
|
||||
</div>
|
||||
) : (
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Nom</TableHead>
|
||||
<TableHead>Email</TableHead>
|
||||
<TableHead>Notifications</TableHead>
|
||||
<TableHead className="text-right">Actions</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{formateurs?.map((formateur) => (
|
||||
<TableRow key={formateur.id}>
|
||||
<TableCell className="font-medium">{formateur.nom}</TableCell>
|
||||
<TableCell>
|
||||
{formateur.email ? (
|
||||
<div className="flex items-center gap-2">
|
||||
<Mail className="h-4 w-4 text-muted-foreground" />
|
||||
{formateur.email}
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-muted-foreground italic">Non renseigné</span>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{formateur.email ? (
|
||||
<Badge variant="default" className="bg-green-500">
|
||||
<CheckCircle2 className="h-3 w-3 mr-1" />
|
||||
Activées
|
||||
</Badge>
|
||||
) : (
|
||||
<Badge variant="outline" className="text-orange-600 border-orange-300">
|
||||
<AlertCircle className="h-3 w-3 mr-1" />
|
||||
Désactivées
|
||||
</Badge>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => openEditDialog(formateur)}
|
||||
className="text-blue-600 hover:text-blue-700"
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => openDeleteDialog(formateur)}
|
||||
className="text-red-600 hover:text-red-700"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Dialog de création */}
|
||||
<Dialog open={isCreateDialogOpen} onOpenChange={setIsCreateDialogOpen}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Ajouter un formateur</DialogTitle>
|
||||
<DialogDescription>
|
||||
Renseignez les informations du nouveau formateur. L'email est optionnel mais
|
||||
nécessaire pour recevoir les notifications.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4 py-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="nom">Nom complet *</Label>
|
||||
<Input
|
||||
id="nom"
|
||||
value={formData.nom}
|
||||
onChange={(e) => setFormData({ ...formData, nom: e.target.value })}
|
||||
placeholder="Jean Dupont"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="email">Adresse email</Label>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
value={formData.email}
|
||||
onChange={(e) => setFormData({ ...formData, email: e.target.value })}
|
||||
placeholder="jean.dupont@exemple.fr"
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
L'email permet de recevoir les notifications d'inscription et d'annulation.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setIsCreateDialogOpen(false)}>
|
||||
Annuler
|
||||
</Button>
|
||||
<Button onClick={handleCreate} disabled={createMutation.isPending}>
|
||||
{createMutation.isPending ? "Création..." : "Créer"}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{/* Dialog de modification */}
|
||||
<Dialog open={isEditDialogOpen} onOpenChange={setIsEditDialogOpen}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Modifier le formateur</DialogTitle>
|
||||
<DialogDescription>
|
||||
Modifiez les informations du formateur. L'email est nécessaire pour recevoir
|
||||
les notifications.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4 py-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="edit-nom">Nom complet *</Label>
|
||||
<Input
|
||||
id="edit-nom"
|
||||
value={formData.nom}
|
||||
onChange={(e) => setFormData({ ...formData, nom: e.target.value })}
|
||||
placeholder="Jean Dupont"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="edit-email">Adresse email</Label>
|
||||
<Input
|
||||
id="edit-email"
|
||||
type="email"
|
||||
value={formData.email}
|
||||
onChange={(e) => setFormData({ ...formData, email: e.target.value })}
|
||||
placeholder="jean.dupont@exemple.fr"
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Sans email, le formateur ne recevra pas les notifications d'inscription et
|
||||
d'annulation.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setIsEditDialogOpen(false)}>
|
||||
Annuler
|
||||
</Button>
|
||||
<Button onClick={handleEdit} disabled={updateMutation.isPending}>
|
||||
{updateMutation.isPending ? "Enregistrement..." : "Enregistrer"}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{/* Dialog de suppression */}
|
||||
<AlertDialog open={isDeleteDialogOpen} onOpenChange={setIsDeleteDialogOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Supprimer le formateur ?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
Êtes-vous sûr de vouloir supprimer le formateur "{selectedFormateur?.nom}" ?
|
||||
Cette action est irréversible.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Annuler</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDelete}
|
||||
className="bg-red-600 hover:bg-red-700"
|
||||
>
|
||||
Supprimer
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</DashboardLayout>
|
||||
);
|
||||
}
|
||||
497
client/src/pages/admin/AdminNotifications.tsx
Normal file
497
client/src/pages/admin/AdminNotifications.tsx
Normal file
@@ -0,0 +1,497 @@
|
||||
import { useState } from "react";
|
||||
import { trpc } from "@/lib/trpc";
|
||||
import DashboardLayout from "@/components/DashboardLayout";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { format } from "date-fns";
|
||||
import { fr } from "date-fns/locale";
|
||||
import {
|
||||
Mail,
|
||||
CheckCircle2,
|
||||
XCircle,
|
||||
TrendingUp,
|
||||
Send,
|
||||
AlertCircle,
|
||||
Filter,
|
||||
RefreshCw,
|
||||
BarChart3,
|
||||
} from "lucide-react";
|
||||
|
||||
const notificationTypeLabels: Record<string, string> = {
|
||||
remerciement: "Remerciement post-formation",
|
||||
notification_formateur_inscription: "Notification formateur (inscription)",
|
||||
notification_formateur_annulation: "Notification formateur (annulation)",
|
||||
alerte_capacite: "Alerte capacité atteinte",
|
||||
notification_liste_attente: "Notification liste d'attente",
|
||||
};
|
||||
|
||||
const notificationTypeColors: Record<string, string> = {
|
||||
remerciement: "bg-blue-100 text-blue-800",
|
||||
notification_formateur_inscription: "bg-green-100 text-green-800",
|
||||
notification_formateur_annulation: "bg-orange-100 text-orange-800",
|
||||
alerte_capacite: "bg-red-100 text-red-800",
|
||||
notification_liste_attente: "bg-purple-100 text-purple-800",
|
||||
};
|
||||
|
||||
export default function AdminNotifications() {
|
||||
const [filters, setFilters] = useState({
|
||||
type: "",
|
||||
statut: "",
|
||||
email: "",
|
||||
dateDebut: "",
|
||||
dateFin: "",
|
||||
});
|
||||
const [page, setPage] = useState(0);
|
||||
const limit = 20;
|
||||
|
||||
const { data: historiqueData, isLoading: isLoadingHistorique, refetch } = trpc.notifications.historique.useQuery({
|
||||
type: filters.type as any || undefined,
|
||||
statut: filters.statut as any || undefined,
|
||||
email: filters.email || undefined,
|
||||
dateDebut: filters.dateDebut || undefined,
|
||||
dateFin: filters.dateFin || undefined,
|
||||
limit,
|
||||
offset: page * limit,
|
||||
});
|
||||
|
||||
const { data: statsData, isLoading: isLoadingStats } = trpc.notifications.statistiques.useQuery({
|
||||
dateDebut: filters.dateDebut || undefined,
|
||||
dateFin: filters.dateFin || undefined,
|
||||
});
|
||||
|
||||
const totalPages = Math.ceil((historiqueData?.total || 0) / limit);
|
||||
|
||||
const handleFilterChange = (key: string, value: string) => {
|
||||
setFilters((prev) => ({ ...prev, [key]: value }));
|
||||
setPage(0);
|
||||
};
|
||||
|
||||
const resetFilters = () => {
|
||||
setFilters({
|
||||
type: "",
|
||||
statut: "",
|
||||
email: "",
|
||||
dateDebut: "",
|
||||
dateFin: "",
|
||||
});
|
||||
setPage(0);
|
||||
};
|
||||
|
||||
return (
|
||||
<DashboardLayout>
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold">Tableau de bord des Notifications</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Historique et statistiques de tous les emails envoyés
|
||||
</p>
|
||||
</div>
|
||||
<Button onClick={() => refetch()} variant="outline">
|
||||
<RefreshCw className="h-4 w-4 mr-2" />
|
||||
Actualiser
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Tabs defaultValue="historique">
|
||||
<TabsList>
|
||||
<TabsTrigger value="historique">
|
||||
<Mail className="h-4 w-4 mr-2" />
|
||||
Historique
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="statistiques">
|
||||
<BarChart3 className="h-4 w-4 mr-2" />
|
||||
Statistiques
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value="statistiques" className="space-y-6">
|
||||
{isLoadingStats ? (
|
||||
<div className="text-center py-8 text-muted-foreground">Chargement...</div>
|
||||
) : statsData ? (
|
||||
<>
|
||||
{/* Cartes de statistiques globales */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-muted-foreground">
|
||||
Total envoyés
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex items-center gap-2">
|
||||
<Send className="h-5 w-5 text-blue-500" />
|
||||
<span className="text-2xl font-bold">{statsData.global.total}</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-muted-foreground">
|
||||
Réussis
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex items-center gap-2">
|
||||
<CheckCircle2 className="h-5 w-5 text-green-500" />
|
||||
<span className="text-2xl font-bold">{statsData.global.success}</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-muted-foreground">
|
||||
Échoués
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex items-center gap-2">
|
||||
<XCircle className="h-5 w-5 text-red-500" />
|
||||
<span className="text-2xl font-bold">{statsData.global.failed}</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-sm font-medium text-muted-foreground">
|
||||
Taux de succès
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex items-center gap-2">
|
||||
<TrendingUp className="h-5 w-5 text-blue-500" />
|
||||
<span className="text-2xl font-bold">{statsData.global.tauxSucces}%</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Statistiques par type */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Répartition par type de notification</CardTitle>
|
||||
<CardDescription>
|
||||
Nombre d'emails envoyés par catégorie
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Type</TableHead>
|
||||
<TableHead className="text-right">Total</TableHead>
|
||||
<TableHead className="text-right">Réussis</TableHead>
|
||||
<TableHead className="text-right">Échoués</TableHead>
|
||||
<TableHead className="text-right">Taux de succès</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{statsData.parType.map((stat) => (
|
||||
<TableRow key={stat.type}>
|
||||
<TableCell>
|
||||
<Badge className={notificationTypeColors[stat.type] || "bg-gray-100"}>
|
||||
{notificationTypeLabels[stat.type] || stat.type}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-medium">{stat.total}</TableCell>
|
||||
<TableCell className="text-right text-green-600">{stat.success}</TableCell>
|
||||
<TableCell className="text-right text-red-600">{stat.failed}</TableCell>
|
||||
<TableCell className="text-right">
|
||||
{stat.total > 0 ? Math.round((stat.success / stat.total) * 100) : 0}%
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
{statsData.parType.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={5} className="text-center text-muted-foreground">
|
||||
Aucune donnée disponible
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Évolution par jour */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Évolution des envois</CardTitle>
|
||||
<CardDescription>
|
||||
Nombre d'emails envoyés par jour
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Date</TableHead>
|
||||
<TableHead className="text-right">Total</TableHead>
|
||||
<TableHead className="text-right">Réussis</TableHead>
|
||||
<TableHead className="text-right">Échoués</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{statsData.evolutionParJour.map((jour) => (
|
||||
<TableRow key={jour.date}>
|
||||
<TableCell>
|
||||
{format(new Date(jour.date), "EEEE d MMMM yyyy", { locale: fr })}
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-medium">{jour.total}</TableCell>
|
||||
<TableCell className="text-right text-green-600">{jour.success}</TableCell>
|
||||
<TableCell className="text-right text-red-600">{jour.failed}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
{statsData.evolutionParJour.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={4} className="text-center text-muted-foreground">
|
||||
Aucune donnée disponible
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</>
|
||||
) : (
|
||||
<div className="text-center py-8 text-muted-foreground">
|
||||
Aucune statistique disponible
|
||||
</div>
|
||||
)}
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="historique" className="space-y-6">
|
||||
{/* Filtres */}
|
||||
<Card>
|
||||
<CardHeader className="pb-3">
|
||||
<CardTitle className="text-base flex items-center gap-2">
|
||||
<Filter className="h-4 w-4" />
|
||||
Filtres
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="grid grid-cols-1 md:grid-cols-5 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label>Type</Label>
|
||||
<Select
|
||||
value={filters.type}
|
||||
onValueChange={(value) => handleFilterChange("type", value)}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Tous les types" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="">Tous les types</SelectItem>
|
||||
<SelectItem value="remerciement">Remerciement</SelectItem>
|
||||
<SelectItem value="notification_formateur_inscription">
|
||||
Notif. formateur (inscription)
|
||||
</SelectItem>
|
||||
<SelectItem value="notification_formateur_annulation">
|
||||
Notif. formateur (annulation)
|
||||
</SelectItem>
|
||||
<SelectItem value="alerte_capacite">Alerte capacité</SelectItem>
|
||||
<SelectItem value="notification_liste_attente">
|
||||
Liste d'attente
|
||||
</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>Statut</Label>
|
||||
<Select
|
||||
value={filters.statut}
|
||||
onValueChange={(value) => handleFilterChange("statut", value)}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Tous les statuts" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="">Tous les statuts</SelectItem>
|
||||
<SelectItem value="success">Réussi</SelectItem>
|
||||
<SelectItem value="failed">Échoué</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>Email</Label>
|
||||
<Input
|
||||
placeholder="Rechercher par email"
|
||||
value={filters.email}
|
||||
onChange={(e) => handleFilterChange("email", e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>Date début</Label>
|
||||
<Input
|
||||
type="date"
|
||||
value={filters.dateDebut}
|
||||
onChange={(e) => handleFilterChange("dateDebut", e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>Date fin</Label>
|
||||
<Input
|
||||
type="date"
|
||||
value={filters.dateFin}
|
||||
onChange={(e) => handleFilterChange("dateFin", e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-4 flex justify-end">
|
||||
<Button variant="outline" onClick={resetFilters}>
|
||||
Réinitialiser les filtres
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Tableau historique */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Historique des envois</CardTitle>
|
||||
<CardDescription>
|
||||
{historiqueData?.total || 0} notification(s) trouvée(s)
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{isLoadingHistorique ? (
|
||||
<div className="text-center py-8 text-muted-foreground">Chargement...</div>
|
||||
) : historiqueData?.logs.length === 0 ? (
|
||||
<div className="text-center py-8 text-muted-foreground">
|
||||
Aucune notification trouvée
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Date</TableHead>
|
||||
<TableHead>Type</TableHead>
|
||||
<TableHead>Destinataire</TableHead>
|
||||
<TableHead>Sujet</TableHead>
|
||||
<TableHead>Formation / Séquence</TableHead>
|
||||
<TableHead>Statut</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{historiqueData?.logs.map((log) => (
|
||||
<TableRow key={log.id}>
|
||||
<TableCell className="whitespace-nowrap">
|
||||
{format(new Date(log.dateEnvoi), "dd/MM/yyyy HH:mm", { locale: fr })}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Badge className={notificationTypeColors[log.type] || "bg-gray-100"}>
|
||||
{notificationTypeLabels[log.type] || log.type}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex flex-col">
|
||||
<span className="font-medium">{log.emailDestinataire}</span>
|
||||
{log.apprenantNom && log.apprenantPrenom && (
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{log.apprenantPrenom} {log.apprenantNom}
|
||||
</span>
|
||||
)}
|
||||
{log.formateurNom && (
|
||||
<span className="text-sm text-muted-foreground">
|
||||
Formateur: {log.formateurNom}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="max-w-xs truncate" title={log.sujet}>
|
||||
{log.sujet}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{log.formationNom && log.sequenceNom ? (
|
||||
<div className="flex flex-col">
|
||||
<span className="font-medium">{log.formationNom}</span>
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{log.sequenceNom}
|
||||
</span>
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-muted-foreground">-</span>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{log.statut === "success" ? (
|
||||
<Badge variant="default" className="bg-green-500">
|
||||
<CheckCircle2 className="h-3 w-3 mr-1" />
|
||||
Envoyé
|
||||
</Badge>
|
||||
) : (
|
||||
<div className="flex flex-col gap-1">
|
||||
<Badge variant="destructive">
|
||||
<XCircle className="h-3 w-3 mr-1" />
|
||||
Échec
|
||||
</Badge>
|
||||
{log.messageErreur && (
|
||||
<span className="text-xs text-red-600" title={log.messageErreur}>
|
||||
{log.messageErreur.substring(0, 50)}...
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
|
||||
{/* Pagination */}
|
||||
{totalPages > 1 && (
|
||||
<div className="flex items-center justify-between mt-4">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Page {page + 1} sur {totalPages}
|
||||
</p>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setPage((p) => Math.max(0, p - 1))}
|
||||
disabled={page === 0}
|
||||
>
|
||||
Précédent
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setPage((p) => Math.min(totalPages - 1, p + 1))}
|
||||
disabled={page >= totalPages - 1}
|
||||
>
|
||||
Suivant
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
</DashboardLayout>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user