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:
9
.manus/db/db-query-1765830115158.json
Normal file
9
.manus/db/db-query-1765830115158.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"query": "CREATE TABLE IF NOT EXISTS `logsNotifications` (\n `id` int AUTO_INCREMENT NOT NULL,\n `type` enum('remerciement','notification_formateur_inscription','notification_formateur_annulation','alerte_capacite','notification_liste_attente') NOT NULL,\n `sequenceId` int,\n `apprenantId` int,\n `formateurId` int,\n `emailDestinataire` varchar(320) NOT NULL,\n `sujet` varchar(500) NOT NULL,\n `dateEnvoi` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n `statut` enum('success','failed') NOT NULL,\n `messageErreur` text,\n `metadata` text,\n `createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n CONSTRAINT `logsNotifications_id` PRIMARY KEY(`id`)\n);",
|
||||||
|
"command": "mysql --batch --raw --column-names --default-character-set=utf8mb4 --host gateway02.us-east-1.prod.aws.tidbcloud.com --port 4000 --user 4CrrYuB5tme73Qo.root --database 7PAT67UmWoxv8vwp8Bbcv6 --execute CREATE TABLE IF NOT EXISTS `logsNotifications` (\n `id` int AUTO_INCREMENT NOT NULL,\n `type` enum('remerciement','notification_formateur_inscription','notification_formateur_annulation','alerte_capacite','notification_liste_attente') NOT NULL,\n `sequenceId` int,\n `apprenantId` int,\n `formateurId` int,\n `emailDestinataire` varchar(320) NOT NULL,\n `sujet` varchar(500) NOT NULL,\n `dateEnvoi` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n `statut` enum('success','failed') NOT NULL,\n `messageErreur` text,\n `metadata` text,\n `createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n CONSTRAINT `logsNotifications_id` PRIMARY KEY(`id`)\n);",
|
||||||
|
"rows": [],
|
||||||
|
"messages": [],
|
||||||
|
"stdout": "",
|
||||||
|
"stderr": "",
|
||||||
|
"execution_time_ms": 273
|
||||||
|
}
|
||||||
@@ -27,6 +27,8 @@ import AdminQuestionnaireAnalyse from "./pages/AdminQuestionnaireAnalyse";
|
|||||||
import AdminQuestionnaireSuivi from "./pages/AdminQuestionnaireSuivi";
|
import AdminQuestionnaireSuivi from "./pages/AdminQuestionnaireSuivi";
|
||||||
import AdminRappelsHistorique from "./pages/admin/AdminRappelsHistorique";
|
import AdminRappelsHistorique from "./pages/admin/AdminRappelsHistorique";
|
||||||
import AdminRappelsStats from "./pages/admin/AdminRappelsStats";
|
import AdminRappelsStats from "./pages/admin/AdminRappelsStats";
|
||||||
|
import AdminFormateurs from "./pages/admin/AdminFormateurs";
|
||||||
|
import AdminNotifications from "./pages/admin/AdminNotifications";
|
||||||
import QuestionnaireReponse from "./pages/QuestionnaireReponse";
|
import QuestionnaireReponse from "./pages/QuestionnaireReponse";
|
||||||
import Inscription from "./pages/Inscription";
|
import Inscription from "./pages/Inscription";
|
||||||
import Login from "./pages/Login";
|
import Login from "./pages/Login";
|
||||||
@@ -49,6 +51,8 @@ function Router() {
|
|||||||
<Route path={"/admin/apprenants/:id"} component={AdminApprenantDetail} />
|
<Route path={"/admin/apprenants/:id"} component={AdminApprenantDetail} />
|
||||||
<Route path={"/admin/sequences/:id/inscrits"} component={AdminSequenceInscrits} />
|
<Route path={"/admin/sequences/:id/inscrits"} component={AdminSequenceInscrits} />
|
||||||
<Route path={"/admin/users"} component={AdminUsers} />
|
<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-templates"} component={AdminEmailTemplates} />
|
||||||
<Route path={"/admin/email-config"} component={AdminEmailConfig} />
|
<Route path={"/admin/email-config"} component={AdminEmailConfig} />
|
||||||
<Route path={"/admin/calendrier"} component={AdminCalendrier} />
|
<Route path={"/admin/calendrier"} component={AdminCalendrier} />
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import {
|
|||||||
} from "@/components/ui/sidebar";
|
} from "@/components/ui/sidebar";
|
||||||
import { APP_LOGO, APP_TITLE, getLoginUrl } from "@/const";
|
import { APP_LOGO, APP_TITLE, getLoginUrl } from "@/const";
|
||||||
import { useIsMobile } from "@/hooks/useMobile";
|
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 { CSSProperties, useEffect, useRef, useState } from "react";
|
||||||
import { useLocation } from "wouter";
|
import { useLocation } from "wouter";
|
||||||
import { DashboardLayoutSkeleton } from './DashboardLayoutSkeleton';
|
import { DashboardLayoutSkeleton } from './DashboardLayoutSkeleton';
|
||||||
@@ -47,6 +47,7 @@ const menuSections = [
|
|||||||
title: "Configuration",
|
title: "Configuration",
|
||||||
items: [
|
items: [
|
||||||
{ icon: UserCog, label: "Utilisateurs", path: "/admin/users" },
|
{ icon: UserCog, label: "Utilisateurs", path: "/admin/users" },
|
||||||
|
{ icon: User, label: "Formateurs", path: "/admin/formateurs" },
|
||||||
{ icon: FileSpreadsheet, label: "Import Excel", path: "/admin/import-excel" },
|
{ icon: FileSpreadsheet, label: "Import Excel", path: "/admin/import-excel" },
|
||||||
{ icon: Bell, label: "Rappels", path: "/admin/rappels", subItems: [
|
{ icon: Bell, label: "Rappels", path: "/admin/rappels", subItems: [
|
||||||
{ label: "Historique", path: "/admin/rappels/historique" },
|
{ label: "Historique", path: "/admin/rappels/historique" },
|
||||||
@@ -55,6 +56,7 @@ const menuSections = [
|
|||||||
{ icon: ClipboardList, label: "Questionnaires", path: "/admin/questionnaires" },
|
{ icon: ClipboardList, label: "Questionnaires", path: "/admin/questionnaires" },
|
||||||
{ icon: Mail, label: "Templates d'emails", path: "/admin/email-templates" },
|
{ icon: Mail, label: "Templates d'emails", path: "/admin/email-templates" },
|
||||||
{ icon: Settings, label: "Configuration SMTP", path: "/admin/email-config" },
|
{ 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>
|
||||||
|
);
|
||||||
|
}
|
||||||
1848
drizzle/meta/0023_snapshot.json
Normal file
1848
drizzle/meta/0023_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -162,6 +162,13 @@
|
|||||||
"when": 1765828479906,
|
"when": 1765828479906,
|
||||||
"tag": "0022_closed_lucky_pierre",
|
"tag": "0022_closed_lucky_pierre",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 23,
|
||||||
|
"version": "5",
|
||||||
|
"when": 1765830109012,
|
||||||
|
"tag": "0023_jittery_gorgon",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -482,3 +482,41 @@ export const logsRappels = mysqlTable("logsRappels", {
|
|||||||
|
|
||||||
export type LogRappel = typeof logsRappels.$inferSelect;
|
export type LogRappel = typeof logsRappels.$inferSelect;
|
||||||
export type InsertLogRappel = typeof logsRappels.$inferInsert;
|
export type InsertLogRappel = typeof logsRappels.$inferInsert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table des logs des notifications envoyées
|
||||||
|
* Stocke l'historique de toutes les notifications (remerciements, alertes formateurs, etc.)
|
||||||
|
*/
|
||||||
|
export const logsNotifications = mysqlTable("logsNotifications", {
|
||||||
|
id: int("id").autoincrement().primaryKey(),
|
||||||
|
/** Type de notification (remerciement, notification_formateur_inscription, notification_formateur_annulation, alerte_capacite, notification_liste_attente) */
|
||||||
|
type: mysqlEnum("type", [
|
||||||
|
"remerciement",
|
||||||
|
"notification_formateur_inscription",
|
||||||
|
"notification_formateur_annulation",
|
||||||
|
"alerte_capacite",
|
||||||
|
"notification_liste_attente"
|
||||||
|
]).notNull(),
|
||||||
|
/** ID de la séquence concernée (si applicable) */
|
||||||
|
sequenceId: int("sequenceId"),
|
||||||
|
/** ID de l'apprenant concerné (si applicable) */
|
||||||
|
apprenantId: int("apprenantId"),
|
||||||
|
/** ID du formateur concerné (si applicable) */
|
||||||
|
formateurId: int("formateurId"),
|
||||||
|
/** Email du destinataire */
|
||||||
|
emailDestinataire: varchar("emailDestinataire", { length: 320 }).notNull(),
|
||||||
|
/** Sujet de l'email */
|
||||||
|
sujet: varchar("sujet", { length: 500 }).notNull(),
|
||||||
|
/** Date d'envoi */
|
||||||
|
dateEnvoi: timestamp("dateEnvoi").defaultNow().notNull(),
|
||||||
|
/** Statut de l'envoi (success, failed) */
|
||||||
|
statut: mysqlEnum("statut", ["success", "failed"]).notNull(),
|
||||||
|
/** Message d'erreur en cas d'échec */
|
||||||
|
messageErreur: text("messageErreur"),
|
||||||
|
/** Informations supplémentaires (JSON) */
|
||||||
|
metadata: text("metadata"),
|
||||||
|
createdAt: timestamp("createdAt").defaultNow().notNull(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type LogNotification = typeof logsNotifications.$inferSelect;
|
||||||
|
export type InsertLogNotification = typeof logsNotifications.$inferInsert;
|
||||||
|
|||||||
210
server/notificationLogsDb.ts
Normal file
210
server/notificationLogsDb.ts
Normal file
@@ -0,0 +1,210 @@
|
|||||||
|
import { eq, desc, and, gte, lte, sql, like } from "drizzle-orm";
|
||||||
|
import { getDb } from "./db";
|
||||||
|
import { logsNotifications, sequences, apprenants, formateurs, formations } from "../drizzle/schema";
|
||||||
|
|
||||||
|
export type NotificationType =
|
||||||
|
| "remerciement"
|
||||||
|
| "notification_formateur_inscription"
|
||||||
|
| "notification_formateur_annulation"
|
||||||
|
| "alerte_capacite"
|
||||||
|
| "notification_liste_attente";
|
||||||
|
|
||||||
|
export interface LogNotificationInput {
|
||||||
|
type: NotificationType;
|
||||||
|
sequenceId?: number;
|
||||||
|
apprenantId?: number;
|
||||||
|
formateurId?: number;
|
||||||
|
emailDestinataire: string;
|
||||||
|
sujet: string;
|
||||||
|
statut: "success" | "failed";
|
||||||
|
messageErreur?: string;
|
||||||
|
metadata?: Record<string, unknown>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enregistre un log de notification
|
||||||
|
*/
|
||||||
|
export async function logNotification(input: LogNotificationInput) {
|
||||||
|
const db = await getDb();
|
||||||
|
if (!db) {
|
||||||
|
console.warn("[NotificationLogs] Database not available");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await db.insert(logsNotifications).values({
|
||||||
|
type: input.type,
|
||||||
|
sequenceId: input.sequenceId || null,
|
||||||
|
apprenantId: input.apprenantId || null,
|
||||||
|
formateurId: input.formateurId || null,
|
||||||
|
emailDestinataire: input.emailDestinataire,
|
||||||
|
sujet: input.sujet,
|
||||||
|
statut: input.statut,
|
||||||
|
messageErreur: input.messageErreur || null,
|
||||||
|
metadata: input.metadata ? JSON.stringify(input.metadata) : null,
|
||||||
|
});
|
||||||
|
console.log(`[NotificationLogs] Log créé: ${input.type} -> ${input.emailDestinataire} (${input.statut})`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("[NotificationLogs] Erreur lors de la création du log:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère l'historique des notifications avec filtres
|
||||||
|
*/
|
||||||
|
export async function getNotificationLogs(filters?: {
|
||||||
|
type?: NotificationType;
|
||||||
|
dateDebut?: Date;
|
||||||
|
dateFin?: Date;
|
||||||
|
statut?: "success" | "failed";
|
||||||
|
email?: string;
|
||||||
|
sequenceId?: number;
|
||||||
|
limit?: number;
|
||||||
|
offset?: number;
|
||||||
|
}) {
|
||||||
|
const db = await getDb();
|
||||||
|
if (!db) return { logs: [], total: 0 };
|
||||||
|
|
||||||
|
const conditions = [];
|
||||||
|
|
||||||
|
if (filters?.type) {
|
||||||
|
conditions.push(eq(logsNotifications.type, filters.type));
|
||||||
|
}
|
||||||
|
if (filters?.dateDebut) {
|
||||||
|
conditions.push(gte(logsNotifications.dateEnvoi, filters.dateDebut));
|
||||||
|
}
|
||||||
|
if (filters?.dateFin) {
|
||||||
|
conditions.push(lte(logsNotifications.dateEnvoi, filters.dateFin));
|
||||||
|
}
|
||||||
|
if (filters?.statut) {
|
||||||
|
conditions.push(eq(logsNotifications.statut, filters.statut));
|
||||||
|
}
|
||||||
|
if (filters?.email) {
|
||||||
|
conditions.push(like(logsNotifications.emailDestinataire, `%${filters.email}%`));
|
||||||
|
}
|
||||||
|
if (filters?.sequenceId) {
|
||||||
|
conditions.push(eq(logsNotifications.sequenceId, filters.sequenceId));
|
||||||
|
}
|
||||||
|
|
||||||
|
const whereClause = conditions.length > 0 ? and(...conditions) : undefined;
|
||||||
|
|
||||||
|
// Récupérer les logs avec les informations associées
|
||||||
|
const logs = await db
|
||||||
|
.select({
|
||||||
|
id: logsNotifications.id,
|
||||||
|
type: logsNotifications.type,
|
||||||
|
sequenceId: logsNotifications.sequenceId,
|
||||||
|
apprenantId: logsNotifications.apprenantId,
|
||||||
|
formateurId: logsNotifications.formateurId,
|
||||||
|
emailDestinataire: logsNotifications.emailDestinataire,
|
||||||
|
sujet: logsNotifications.sujet,
|
||||||
|
dateEnvoi: logsNotifications.dateEnvoi,
|
||||||
|
statut: logsNotifications.statut,
|
||||||
|
messageErreur: logsNotifications.messageErreur,
|
||||||
|
metadata: logsNotifications.metadata,
|
||||||
|
sequenceNom: sequences.nom,
|
||||||
|
formationNom: formations.nom,
|
||||||
|
apprenantNom: apprenants.nom,
|
||||||
|
apprenantPrenom: apprenants.prenom,
|
||||||
|
formateurNom: formateurs.nom,
|
||||||
|
})
|
||||||
|
.from(logsNotifications)
|
||||||
|
.leftJoin(sequences, eq(logsNotifications.sequenceId, sequences.id))
|
||||||
|
.leftJoin(formations, eq(sequences.formationId, formations.id))
|
||||||
|
.leftJoin(apprenants, eq(logsNotifications.apprenantId, apprenants.id))
|
||||||
|
.leftJoin(formateurs, eq(logsNotifications.formateurId, formateurs.id))
|
||||||
|
.where(whereClause)
|
||||||
|
.orderBy(desc(logsNotifications.dateEnvoi))
|
||||||
|
.limit(filters?.limit || 50)
|
||||||
|
.offset(filters?.offset || 0);
|
||||||
|
|
||||||
|
// Compter le total
|
||||||
|
const [countResult] = await db
|
||||||
|
.select({ count: sql<number>`COUNT(*)` })
|
||||||
|
.from(logsNotifications)
|
||||||
|
.where(whereClause);
|
||||||
|
|
||||||
|
return {
|
||||||
|
logs,
|
||||||
|
total: countResult?.count || 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère les statistiques des notifications
|
||||||
|
*/
|
||||||
|
export async function getNotificationStats(filters?: {
|
||||||
|
dateDebut?: Date;
|
||||||
|
dateFin?: Date;
|
||||||
|
}) {
|
||||||
|
const db = await getDb();
|
||||||
|
if (!db) return null;
|
||||||
|
|
||||||
|
const conditions = [];
|
||||||
|
if (filters?.dateDebut) {
|
||||||
|
conditions.push(gte(logsNotifications.dateEnvoi, filters.dateDebut));
|
||||||
|
}
|
||||||
|
if (filters?.dateFin) {
|
||||||
|
conditions.push(lte(logsNotifications.dateEnvoi, filters.dateFin));
|
||||||
|
}
|
||||||
|
|
||||||
|
const whereClause = conditions.length > 0 ? and(...conditions) : undefined;
|
||||||
|
|
||||||
|
// Statistiques globales
|
||||||
|
const [globalStats] = await db
|
||||||
|
.select({
|
||||||
|
total: sql<number>`COUNT(*)`,
|
||||||
|
success: sql<number>`SUM(CASE WHEN statut = 'success' THEN 1 ELSE 0 END)`,
|
||||||
|
failed: sql<number>`SUM(CASE WHEN statut = 'failed' THEN 1 ELSE 0 END)`,
|
||||||
|
})
|
||||||
|
.from(logsNotifications)
|
||||||
|
.where(whereClause);
|
||||||
|
|
||||||
|
// Statistiques par type
|
||||||
|
const statsByType = await db
|
||||||
|
.select({
|
||||||
|
type: logsNotifications.type,
|
||||||
|
total: sql<number>`COUNT(*)`,
|
||||||
|
success: sql<number>`SUM(CASE WHEN statut = 'success' THEN 1 ELSE 0 END)`,
|
||||||
|
failed: sql<number>`SUM(CASE WHEN statut = 'failed' THEN 1 ELSE 0 END)`,
|
||||||
|
})
|
||||||
|
.from(logsNotifications)
|
||||||
|
.where(whereClause)
|
||||||
|
.groupBy(logsNotifications.type);
|
||||||
|
|
||||||
|
// Évolution par jour (7 derniers jours)
|
||||||
|
const evolutionParJour = await db
|
||||||
|
.select({
|
||||||
|
date: sql<string>`DATE(dateEnvoi)`,
|
||||||
|
total: sql<number>`COUNT(*)`,
|
||||||
|
success: sql<number>`SUM(CASE WHEN statut = 'success' THEN 1 ELSE 0 END)`,
|
||||||
|
failed: sql<number>`SUM(CASE WHEN statut = 'failed' THEN 1 ELSE 0 END)`,
|
||||||
|
})
|
||||||
|
.from(logsNotifications)
|
||||||
|
.where(whereClause)
|
||||||
|
.groupBy(sql`DATE(dateEnvoi)`)
|
||||||
|
.orderBy(sql`DATE(dateEnvoi)`)
|
||||||
|
.limit(30);
|
||||||
|
|
||||||
|
return {
|
||||||
|
global: {
|
||||||
|
total: globalStats?.total || 0,
|
||||||
|
success: globalStats?.success || 0,
|
||||||
|
failed: globalStats?.failed || 0,
|
||||||
|
tauxSucces: globalStats?.total ? Math.round((globalStats.success / globalStats.total) * 100) : 0,
|
||||||
|
},
|
||||||
|
parType: statsByType,
|
||||||
|
evolutionParJour,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Labels pour les types de notifications
|
||||||
|
*/
|
||||||
|
export const notificationTypeLabels: Record<NotificationType, 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",
|
||||||
|
};
|
||||||
@@ -1,7 +1,82 @@
|
|||||||
import { getDb } from "./db";
|
import { getDb } from "./db";
|
||||||
import { sequences, inscriptions, apprenants, formations, datesFormation, formateurs } from "../drizzle/schema";
|
import { sequences, inscriptions, apprenants, formations, datesFormation, formateurs, questionnaires, envoisQuestionnaires } from "../drizzle/schema";
|
||||||
import { eq, and, lte, sql } from "drizzle-orm";
|
import { eq, and, lte, sql } from "drizzle-orm";
|
||||||
import { sendRemerciementPostFormation } from "./emailService";
|
import { sendRemerciementPostFormation } from "./emailService";
|
||||||
|
import { logNotification } from "./notificationLogsDb";
|
||||||
|
import crypto from "crypto";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Génère un token unique pour accéder au questionnaire
|
||||||
|
*/
|
||||||
|
function generateToken(): string {
|
||||||
|
return crypto.randomBytes(32).toString("hex");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère ou crée un lien questionnaire pour un apprenant
|
||||||
|
*/
|
||||||
|
async function getOrCreateQuestionnaireLink(
|
||||||
|
apprenantId: number,
|
||||||
|
sequenceId: number
|
||||||
|
): Promise<string | null> {
|
||||||
|
const db = await getDb();
|
||||||
|
if (!db) return null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Chercher un questionnaire de satisfaction actif
|
||||||
|
const [questionnaire] = await db
|
||||||
|
.select()
|
||||||
|
.from(questionnaires)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(questionnaires.type, "satisfaction"),
|
||||||
|
eq(questionnaires.actif, true)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!questionnaire) {
|
||||||
|
console.log("[Remerciements] Aucun questionnaire de satisfaction actif trouvé");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérifier si un envoi existe déjà
|
||||||
|
const [envoiExistant] = await db
|
||||||
|
.select()
|
||||||
|
.from(envoisQuestionnaires)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(envoisQuestionnaires.questionnaireId, questionnaire.id),
|
||||||
|
eq(envoisQuestionnaires.apprenantId, apprenantId),
|
||||||
|
eq(envoisQuestionnaires.sequenceId, sequenceId)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (envoiExistant) {
|
||||||
|
// Retourner le lien existant
|
||||||
|
const baseUrl = process.env.VITE_FRONTEND_URL || "http://localhost:3000";
|
||||||
|
return `${baseUrl}/questionnaire/${envoiExistant.token}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Créer un nouvel envoi
|
||||||
|
const token = generateToken();
|
||||||
|
await db.insert(envoisQuestionnaires).values({
|
||||||
|
questionnaireId: questionnaire.id,
|
||||||
|
apprenantId,
|
||||||
|
sequenceId,
|
||||||
|
token,
|
||||||
|
dateEnvoi: new Date(),
|
||||||
|
dateReponse: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
const baseUrl = process.env.VITE_FRONTEND_URL || "http://localhost:3000";
|
||||||
|
return `${baseUrl}/questionnaire/${token}`;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("[Remerciements] Erreur lors de la création du lien questionnaire:", error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table pour suivre les remerciements déjà envoyés
|
* Table pour suivre les remerciements déjà envoyés
|
||||||
@@ -111,6 +186,9 @@ async function processRemerciementSequence(
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Générer le lien questionnaire
|
||||||
|
const lienQuestionnaire = await getOrCreateQuestionnaireLink(apprenant.id, sequence.id);
|
||||||
|
|
||||||
await sendRemerciementPostFormation({
|
await sendRemerciementPostFormation({
|
||||||
apprenantEmail: apprenant.email,
|
apprenantEmail: apprenant.email,
|
||||||
apprenantNom: apprenant.nom,
|
apprenantNom: apprenant.nom,
|
||||||
@@ -119,12 +197,35 @@ async function processRemerciementSequence(
|
|||||||
formationNom: formation.nom,
|
formationNom: formation.nom,
|
||||||
sequenceNom: sequence.nom,
|
sequenceNom: sequence.nom,
|
||||||
formateurNom: formateur?.nom,
|
formateurNom: formateur?.nom,
|
||||||
|
lienQuestionnaire: lienQuestionnaire || undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Logger la notification
|
||||||
|
await logNotification({
|
||||||
|
type: "remerciement",
|
||||||
|
sequenceId: sequence.id,
|
||||||
|
apprenantId: apprenant.id,
|
||||||
|
emailDestinataire: apprenant.email,
|
||||||
|
sujet: `Merci pour votre participation - ${formation.nom}`,
|
||||||
|
statut: "success",
|
||||||
|
metadata: { lienQuestionnaire },
|
||||||
});
|
});
|
||||||
|
|
||||||
marquerRemerciementEnvoye(inscription.id, sequence.id);
|
marquerRemerciementEnvoye(inscription.id, sequence.id);
|
||||||
envoyesCount++;
|
envoyesCount++;
|
||||||
console.log(`[Remerciements] Email envoyé à ${apprenant.email}`);
|
console.log(`[Remerciements] Email envoyé à ${apprenant.email}`);
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
|
// Logger l'échec
|
||||||
|
await logNotification({
|
||||||
|
type: "remerciement",
|
||||||
|
sequenceId: sequence.id,
|
||||||
|
apprenantId: apprenant.id,
|
||||||
|
emailDestinataire: apprenant.email,
|
||||||
|
sujet: `Merci pour votre participation - ${formation.nom}`,
|
||||||
|
statut: "failed",
|
||||||
|
messageErreur: error.message,
|
||||||
|
});
|
||||||
|
|
||||||
errorsCount++;
|
errorsCount++;
|
||||||
console.error(`[Remerciements] Erreur envoi à ${apprenant.email}:`, error);
|
console.error(`[Remerciements] Erreur envoi à ${apprenant.email}:`, error);
|
||||||
}
|
}
|
||||||
@@ -189,6 +290,9 @@ export async function envoyerRemerciementsSequence(sequenceId: number): Promise<
|
|||||||
|
|
||||||
for (const { inscription, apprenant } of inscriptionsConfirmees) {
|
for (const { inscription, apprenant } of inscriptionsConfirmees) {
|
||||||
try {
|
try {
|
||||||
|
// Générer le lien questionnaire
|
||||||
|
const lienQuestionnaire = await getOrCreateQuestionnaireLink(apprenant.id, sequenceId);
|
||||||
|
|
||||||
await sendRemerciementPostFormation({
|
await sendRemerciementPostFormation({
|
||||||
apprenantEmail: apprenant.email,
|
apprenantEmail: apprenant.email,
|
||||||
apprenantNom: apprenant.nom,
|
apprenantNom: apprenant.nom,
|
||||||
@@ -197,9 +301,33 @@ export async function envoyerRemerciementsSequence(sequenceId: number): Promise<
|
|||||||
formationNom: formation.nom,
|
formationNom: formation.nom,
|
||||||
sequenceNom: sequence.nom,
|
sequenceNom: sequence.nom,
|
||||||
formateurNom: formateur?.nom,
|
formateurNom: formateur?.nom,
|
||||||
|
lienQuestionnaire: lienQuestionnaire || undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Logger la notification
|
||||||
|
await logNotification({
|
||||||
|
type: "remerciement",
|
||||||
|
sequenceId,
|
||||||
|
apprenantId: apprenant.id,
|
||||||
|
emailDestinataire: apprenant.email,
|
||||||
|
sujet: `Merci pour votre participation - ${formation.nom}`,
|
||||||
|
statut: "success",
|
||||||
|
metadata: { lienQuestionnaire },
|
||||||
|
});
|
||||||
|
|
||||||
sent++;
|
sent++;
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
|
// Logger l'échec
|
||||||
|
await logNotification({
|
||||||
|
type: "remerciement",
|
||||||
|
sequenceId,
|
||||||
|
apprenantId: apprenant.id,
|
||||||
|
emailDestinataire: apprenant.email,
|
||||||
|
sujet: `Merci pour votre participation - ${formation.nom}`,
|
||||||
|
statut: "failed",
|
||||||
|
messageErreur: error.message,
|
||||||
|
});
|
||||||
|
|
||||||
console.error(`[Remerciements] Erreur envoi à ${apprenant.email}:`, error);
|
console.error(`[Remerciements] Erreur envoi à ${apprenant.email}:`, error);
|
||||||
failed++;
|
failed++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import * as analyticsDb from "./analyticsDb";
|
|||||||
import { generateAnalyticsExcel, generateAnalyticsPDF } from "./analyticsExportService";
|
import { generateAnalyticsExcel, generateAnalyticsPDF } from "./analyticsExportService";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import { sendInscriptionConfirmation, sendGroupEmail, sendNotificationFormateurNouvelleInscription, sendNotificationFormateurAnnulation, sendAlerteCapaciteAtteinte, sendNotificationPlaceDisponible, sendRemerciementPostFormation } from "./emailService";
|
import { sendInscriptionConfirmation, sendGroupEmail, sendNotificationFormateurNouvelleInscription, sendNotificationFormateurAnnulation, sendAlerteCapaciteAtteinte, sendNotificationPlaceDisponible, sendRemerciementPostFormation } from "./emailService";
|
||||||
|
import { logNotification } from "./notificationLogsDb";
|
||||||
import { generateExcelExport, generatePDFExport, generateFeuillePresence } from "./exportService";
|
import { generateExcelExport, generatePDFExport, generateFeuillePresence } from "./exportService";
|
||||||
import { parseExcelFile, validateImportData, importToDatabase } from "./importExcel";
|
import { parseExcelFile, validateImportData, importToDatabase } from "./importExcel";
|
||||||
|
|
||||||
@@ -226,6 +227,7 @@ export const appRouter = router({
|
|||||||
|
|
||||||
create: adminProcedure.input(z.object({
|
create: adminProcedure.input(z.object({
|
||||||
nom: z.string().min(1),
|
nom: z.string().min(1),
|
||||||
|
email: z.string().email().optional(),
|
||||||
})).mutation(async ({ input }) => {
|
})).mutation(async ({ input }) => {
|
||||||
await db.createFormateur(input);
|
await db.createFormateur(input);
|
||||||
return { success: true };
|
return { success: true };
|
||||||
@@ -234,6 +236,7 @@ export const appRouter = router({
|
|||||||
update: adminProcedure.input(z.object({
|
update: adminProcedure.input(z.object({
|
||||||
id: z.number(),
|
id: z.number(),
|
||||||
nom: z.string().min(1).optional(),
|
nom: z.string().min(1).optional(),
|
||||||
|
email: z.string().email().nullable().optional(),
|
||||||
})).mutation(async ({ input }) => {
|
})).mutation(async ({ input }) => {
|
||||||
const { id, ...data } = input;
|
const { id, ...data } = input;
|
||||||
await db.updateFormateur(id, data);
|
await db.updateFormateur(id, data);
|
||||||
@@ -487,8 +490,29 @@ export const appRouter = router({
|
|||||||
ordre: d.ordre,
|
ordre: d.ordre,
|
||||||
})),
|
})),
|
||||||
});
|
});
|
||||||
|
// Logger la notification
|
||||||
|
await logNotification({
|
||||||
|
type: "notification_formateur_inscription",
|
||||||
|
sequenceId: input.sequenceId,
|
||||||
|
apprenantId: inscriptionApprenant.id,
|
||||||
|
formateurId: formateur.id,
|
||||||
|
emailDestinataire: formateur.email,
|
||||||
|
sujet: `Nouvelle inscription - ${inscriptionFormation.nom}`,
|
||||||
|
statut: "success",
|
||||||
|
});
|
||||||
console.log(`[Notification] Email envoyé au formateur ${formateur.email} pour nouvelle inscription`);
|
console.log(`[Notification] Email envoyé au formateur ${formateur.email} pour nouvelle inscription`);
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
|
// Logger l'échec
|
||||||
|
await logNotification({
|
||||||
|
type: "notification_formateur_inscription",
|
||||||
|
sequenceId: input.sequenceId,
|
||||||
|
apprenantId: inscriptionApprenant.id,
|
||||||
|
formateurId: formateur.id,
|
||||||
|
emailDestinataire: formateur.email,
|
||||||
|
sujet: `Nouvelle inscription - ${inscriptionFormation.nom}`,
|
||||||
|
statut: "failed",
|
||||||
|
messageErreur: e.message,
|
||||||
|
});
|
||||||
console.error(`[Notification] Erreur envoi email formateur:`, e);
|
console.error(`[Notification] Erreur envoi email formateur:`, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -582,8 +606,29 @@ export const appRouter = router({
|
|||||||
nbInscrits: nbInscritsApres,
|
nbInscrits: nbInscritsApres,
|
||||||
capaciteMax: sequence.capaciteMax,
|
capaciteMax: sequence.capaciteMax,
|
||||||
});
|
});
|
||||||
|
// Logger la notification
|
||||||
|
await logNotification({
|
||||||
|
type: "notification_formateur_annulation",
|
||||||
|
sequenceId: input.sequenceId,
|
||||||
|
apprenantId: apprenant.id,
|
||||||
|
formateurId: formateur.id,
|
||||||
|
emailDestinataire: formateur.email,
|
||||||
|
sujet: `Annulation d'inscription - ${formation.nom}`,
|
||||||
|
statut: "success",
|
||||||
|
});
|
||||||
console.log(`[Notification] Email d'annulation envoyé au formateur ${formateur.email}`);
|
console.log(`[Notification] Email d'annulation envoyé au formateur ${formateur.email}`);
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
|
// Logger l'échec
|
||||||
|
await logNotification({
|
||||||
|
type: "notification_formateur_annulation",
|
||||||
|
sequenceId: input.sequenceId,
|
||||||
|
apprenantId: apprenant.id,
|
||||||
|
formateurId: formateur.id,
|
||||||
|
emailDestinataire: formateur.email,
|
||||||
|
sujet: `Annulation d'inscription - ${formation.nom}`,
|
||||||
|
statut: "failed",
|
||||||
|
messageErreur: e.message,
|
||||||
|
});
|
||||||
console.error(`[Notification] Erreur envoi email formateur:`, e);
|
console.error(`[Notification] Erreur envoi email formateur:`, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -607,8 +652,27 @@ export const appRouter = router({
|
|||||||
positionListeAttente: 1,
|
positionListeAttente: 1,
|
||||||
delaiReponse: 48,
|
delaiReponse: 48,
|
||||||
});
|
});
|
||||||
|
// Logger la notification
|
||||||
|
await logNotification({
|
||||||
|
type: "notification_liste_attente",
|
||||||
|
sequenceId: input.sequenceId,
|
||||||
|
apprenantId: premierEnAttente.apprenant.id,
|
||||||
|
emailDestinataire: premierEnAttente.apprenant.email,
|
||||||
|
sujet: `Place disponible - ${formation.nom}`,
|
||||||
|
statut: "success",
|
||||||
|
});
|
||||||
console.log(`[Notification] Email place disponible envoyé à ${premierEnAttente.apprenant.email}`);
|
console.log(`[Notification] Email place disponible envoyé à ${premierEnAttente.apprenant.email}`);
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
|
// Logger l'échec
|
||||||
|
await logNotification({
|
||||||
|
type: "notification_liste_attente",
|
||||||
|
sequenceId: input.sequenceId,
|
||||||
|
apprenantId: premierEnAttente.apprenant.id,
|
||||||
|
emailDestinataire: premierEnAttente.apprenant.email,
|
||||||
|
sujet: `Place disponible - ${formation.nom}`,
|
||||||
|
statut: "failed",
|
||||||
|
messageErreur: e.message,
|
||||||
|
});
|
||||||
console.error(`[Notification] Erreur envoi email liste d'attente:`, e);
|
console.error(`[Notification] Erreur envoi email liste d'attente:`, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1631,6 +1695,46 @@ export const appRouter = router({
|
|||||||
await processRemerciementsAutomatiques();
|
await processRemerciementsAutomatiques();
|
||||||
return { success: true };
|
return { success: true };
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
// Historique des notifications
|
||||||
|
historique: adminProcedure
|
||||||
|
.input(z.object({
|
||||||
|
type: z.enum(["remerciement", "notification_formateur_inscription", "notification_formateur_annulation", "alerte_capacite", "notification_liste_attente"]).optional(),
|
||||||
|
dateDebut: z.string().optional(),
|
||||||
|
dateFin: z.string().optional(),
|
||||||
|
statut: z.enum(["success", "failed"]).optional(),
|
||||||
|
email: z.string().optional(),
|
||||||
|
sequenceId: z.number().optional(),
|
||||||
|
limit: z.number().default(50),
|
||||||
|
offset: z.number().default(0),
|
||||||
|
}))
|
||||||
|
.query(async ({ input }) => {
|
||||||
|
const { getNotificationLogs } = await import("./notificationLogsDb");
|
||||||
|
return getNotificationLogs({
|
||||||
|
type: input.type,
|
||||||
|
dateDebut: input.dateDebut ? new Date(input.dateDebut) : undefined,
|
||||||
|
dateFin: input.dateFin ? new Date(input.dateFin) : undefined,
|
||||||
|
statut: input.statut,
|
||||||
|
email: input.email,
|
||||||
|
sequenceId: input.sequenceId,
|
||||||
|
limit: input.limit,
|
||||||
|
offset: input.offset,
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Statistiques des notifications
|
||||||
|
statistiques: adminProcedure
|
||||||
|
.input(z.object({
|
||||||
|
dateDebut: z.string().optional(),
|
||||||
|
dateFin: z.string().optional(),
|
||||||
|
}))
|
||||||
|
.query(async ({ input }) => {
|
||||||
|
const { getNotificationStats } = await import("./notificationLogsDb");
|
||||||
|
return getNotificationStats({
|
||||||
|
dateDebut: input.dateDebut ? new Date(input.dateDebut) : undefined,
|
||||||
|
dateFin: input.dateFin ? new Date(input.dateFin) : undefined,
|
||||||
|
});
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
5
todo.md
5
todo.md
@@ -437,3 +437,8 @@
|
|||||||
- [x] Ajout du champ email pour les formateurs
|
- [x] Ajout du champ email pour les formateurs
|
||||||
- [x] Scheduler automatique pour les remerciements post-formation
|
- [x] Scheduler automatique pour les remerciements post-formation
|
||||||
- [x] Procédure tRPC pour envoi manuel des remerciements
|
- [x] Procédure tRPC pour envoi manuel des remerciements
|
||||||
|
|
||||||
|
## Améliorations notifications (15/12/2025)
|
||||||
|
- [x] Interface de gestion des emails formateurs dans Configuration
|
||||||
|
- [x] Tableau de bord des notifications avec historique des emails envoyés
|
||||||
|
- [x] Lien vers questionnaire de satisfaction dans l'email de remerciement
|
||||||
|
|||||||
Reference in New Issue
Block a user