Checkpoint: Ajout d'un bouton "Tout renvoyer" dans la page de gestion des attestations pour envoyer en masse toutes les attestations d'une formation. Création de la procédure backend sendAllAttestations qui envoie toutes les attestations disponibles et enregistre chaque envoi dans l'historique. Correction du scheduler de rappels pour vérifier l'heure configurée (intervalle 15 min au lieu de 1h).

This commit is contained in:
Manus
2026-01-18 08:39:13 -05:00
parent 6c4ca249a9
commit 2c0f379c52
3 changed files with 143 additions and 4 deletions

View File

@@ -193,6 +193,17 @@ export default function AdminGestionAttestations() {
},
});
// Mutation pour envoyer toutes les attestations
const sendAllMutation = trpc.gestionAttestations.sendAllAttestations.useMutation({
onSuccess: (result) => {
toast.success(`${result.succes} attestation(s) envoyée(s) avec succès${result.echecs > 0 ? `, ${result.echecs} échec(s)` : ''}`);
refetchApprenants();
},
onError: (error) => {
toast.error(`Erreur lors de l'envoi en masse : ${error.message}`);
},
});
// Charger la configuration quand une formation est sélectionnée
const handleFormationChange = (formationId: string) => {
const id = parseInt(formationId);
@@ -251,6 +262,26 @@ export default function AdminGestionAttestations() {
}
};
// Envoyer toutes les attestations
const handleSendAll = () => {
if (!selectedFormationId) return;
// Compter le nombre d'attestations prêtes à envoyer
const attestationsReady = apprenants?.filter(item => {
const hasDocument = item.attestation && (item.attestation.urlPdf || item.attestation.documentUrl);
return hasDocument;
}).length || 0;
if (attestationsReady === 0) {
toast.error("Aucune attestation prête à envoyer");
return;
}
if (confirm(`Êtes-vous sûr de vouloir envoyer ${attestationsReady} attestation(s) ?`)) {
sendAllMutation.mutate({ formationId: selectedFormationId });
}
};
// Ouvrir le dialogue d'upload
const handleOpenUpload = (inscriptionId: number) => {
setSelectedInscriptionId(inscriptionId);
@@ -373,10 +404,24 @@ export default function AdminGestionAttestations() {
{selectedFormationId && (
<Card>
<CardHeader>
<CardTitle>Apprenants inscrits</CardTitle>
<CardDescription>
Gérez les attestations pour chaque apprenant inscrit à cette formation
</CardDescription>
<div className="flex items-center justify-between">
<div>
<CardTitle>Apprenants inscrits</CardTitle>
<CardDescription>
Gérez les attestations pour chaque apprenant inscrit à cette formation
</CardDescription>
</div>
{modeEnvoi === "manuel" && apprenants && apprenants.length > 0 && (
<Button
onClick={handleSendAll}
disabled={sendAllMutation.isPending}
variant="default"
>
<Send className="h-4 w-4 mr-2" />
{sendAllMutation.isPending ? "Envoi en cours..." : "Tout renvoyer"}
</Button>
)}
</div>
</CardHeader>
<CardContent>
{loadingApprenants ? (