Checkpoint: Ajout manuel d'apprenant : Bouton et dialogue pour inscrire manuellement un apprenant à une séquence.
**Fonctionnalité ajoutée :** - Bouton "Ajouter un inscrit" avec icône UserPlus dans le header de la liste des inscrits - Dialogue de sélection avec liste déroulante des apprenants disponibles (filtrés pour exclure ceux déjà inscrits) - Sélection du statut (Confirmé / Liste d'attente) - Mutation backend `inscriptions.create` pour l'ajout manuel par l'admin (sans vérifications de blocage/capacité) **Fichiers modifiés :** - client/src/pages/AdminSequenceInscrits.tsx : Ajout du bouton et du dialogue - client/src/components/AddInscritForm.tsx : Nouveau composant de formulaire - server/routers.ts : Ajout de la mutation inscriptions.create **Résultat :** Les administrateurs peuvent maintenant ajouter manuellement des apprenants à une séquence depuis l'interface des inscrits.
This commit is contained in:
106
client/src/components/AddInscritForm.tsx
Normal file
106
client/src/components/AddInscritForm.tsx
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||||
|
import { trpc } from "@/lib/trpc";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
|
||||||
|
interface AddInscritFormProps {
|
||||||
|
sequenceId: number;
|
||||||
|
onSuccess: () => void;
|
||||||
|
onCancel: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AddInscritForm({ sequenceId, onSuccess, onCancel }: AddInscritFormProps) {
|
||||||
|
const [selectedApprenantId, setSelectedApprenantId] = useState<string>("");
|
||||||
|
const [statut, setStatut] = useState<"confirme" | "liste_attente">("confirme");
|
||||||
|
|
||||||
|
// Récupérer tous les apprenants
|
||||||
|
const { data: apprenants, isLoading: loadingApprenants } = trpc.apprenants.list.useQuery();
|
||||||
|
|
||||||
|
// Récupérer les inscrits actuels pour filtrer
|
||||||
|
const { data: inscriptions } = trpc.inscriptions.listBySequence.useQuery({ sequenceId });
|
||||||
|
|
||||||
|
// Mutation pour créer l'inscription
|
||||||
|
const createInscription = trpc.inscriptions.create.useMutation({
|
||||||
|
onSuccess: () => {
|
||||||
|
onSuccess();
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
toast.error(`Erreur : ${error.message}`);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Filtrer les apprenants déjà inscrits
|
||||||
|
const apprenantsDisponibles = apprenants?.filter(
|
||||||
|
(apprenant) => !inscriptions?.some((inscription) => inscription.apprenantId === apprenant.id)
|
||||||
|
) || [];
|
||||||
|
|
||||||
|
const handleSubmit = (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
if (!selectedApprenantId) {
|
||||||
|
toast.error("Veuillez sélectionner un apprenant");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
createInscription.mutate({
|
||||||
|
sequenceId,
|
||||||
|
apprenantId: parseInt(selectedApprenantId),
|
||||||
|
statut,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form onSubmit={handleSubmit} className="space-y-6">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="apprenant">Apprenant *</Label>
|
||||||
|
{loadingApprenants ? (
|
||||||
|
<div className="text-sm text-muted-foreground">Chargement...</div>
|
||||||
|
) : apprenantsDisponibles.length === 0 ? (
|
||||||
|
<div className="text-sm text-muted-foreground">
|
||||||
|
Tous les apprenants sont déjà inscrits à cette séquence
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<Select value={selectedApprenantId} onValueChange={setSelectedApprenantId}>
|
||||||
|
<SelectTrigger id="apprenant">
|
||||||
|
<SelectValue placeholder="Sélectionnez un apprenant" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{apprenantsDisponibles.map((apprenant) => (
|
||||||
|
<SelectItem key={apprenant.id} value={apprenant.id.toString()}>
|
||||||
|
{apprenant.prenom} {apprenant.nom} ({apprenant.email})
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="statut">Statut *</Label>
|
||||||
|
<Select value={statut} onValueChange={(value) => setStatut(value as "confirme" | "liste_attente")}>
|
||||||
|
<SelectTrigger id="statut">
|
||||||
|
<SelectValue />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="confirme">Confirmé</SelectItem>
|
||||||
|
<SelectItem value="liste_attente">Liste d'attente</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex justify-end gap-2">
|
||||||
|
<Button type="button" variant="outline" onClick={onCancel}>
|
||||||
|
Annuler
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
disabled={!selectedApprenantId || createInscription.isPending || apprenantsDisponibles.length === 0}
|
||||||
|
>
|
||||||
|
{createInscription.isPending ? "Inscription..." : "Inscrire"}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -30,8 +30,8 @@ import { DateFormationMultiSelect } from "@/components/DateFormationMultiSelect"
|
|||||||
|
|
||||||
// Types de templates disponibles pour les rappels
|
// Types de templates disponibles pour les rappels
|
||||||
const TEMPLATE_TYPES = [
|
const TEMPLATE_TYPES = [
|
||||||
{ value: "rappel", label: "Rappel 1", joursAvant: 7 },
|
{ value: "rappel1", label: "Rappel 1", joursAvant: 7 },
|
||||||
{ value: "rappelJ1", label: "Rappel 2", joursAvant: 1 },
|
{ value: "rappel2", label: "Rappel 2", joursAvant: 1 },
|
||||||
{ value: "rappel3", label: "Rappel 3", joursAvant: 14 },
|
{ value: "rappel3", label: "Rappel 3", joursAvant: 14 },
|
||||||
{ value: "rappel4", label: "Rappel 4", joursAvant: 21 },
|
{ value: "rappel4", label: "Rappel 4", joursAvant: 21 },
|
||||||
{ value: "rappel5", label: "Rappel 5", joursAvant: 30 },
|
{ value: "rappel5", label: "Rappel 5", joursAvant: 30 },
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/com
|
|||||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||||
import { trpc } from "@/lib/trpc";
|
import { trpc } from "@/lib/trpc";
|
||||||
import { ArrowLeft, Download, Mail, Search, Eye } from "lucide-react";
|
import { ArrowLeft, Download, Mail, Search, Eye, UserPlus } from "lucide-react";
|
||||||
import { useLocation, useRoute } from "wouter";
|
import { useLocation, useRoute } from "wouter";
|
||||||
import { useState, useMemo } from "react";
|
import { useState, useMemo } from "react";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { Skeleton } from "@/components/ui/skeleton";
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
|
import { AddInscritForm } from "@/components/AddInscritForm";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
@@ -48,6 +49,8 @@ export default function AdminSequenceInscrits() {
|
|||||||
const [filterEtablissement, setFilterEtablissement] = useState<string>("all");
|
const [filterEtablissement, setFilterEtablissement] = useState<string>("all");
|
||||||
const [filterFonction, setFilterFonction] = useState<string>("all");
|
const [filterFonction, setFilterFonction] = useState<string>("all");
|
||||||
const [sortBy, setSortBy] = useState<"date" | "nom">("date");
|
const [sortBy, setSortBy] = useState<"date" | "nom">("date");
|
||||||
|
const [isAddInscritOpen, setIsAddInscritOpen] = useState(false);
|
||||||
|
const [selectedApprenantId, setSelectedApprenantId] = useState<number | null>(null);
|
||||||
const [showPreviewModal, setShowPreviewModal] = useState(false);
|
const [showPreviewModal, setShowPreviewModal] = useState(false);
|
||||||
const [previewType, setPreviewType] = useState<"teaser" | "rappel" | "rappel_j1">("teaser");
|
const [previewType, setPreviewType] = useState<"teaser" | "rappel" | "rappel_j1">("teaser");
|
||||||
|
|
||||||
@@ -506,10 +509,22 @@ export default function AdminSequenceInscrits() {
|
|||||||
{/* Liste des inscrits */}
|
{/* Liste des inscrits */}
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Liste des inscrits</CardTitle>
|
<div className="flex items-center justify-between">
|
||||||
<CardDescription>
|
<div>
|
||||||
{nbConfirmes} confirmé(s), {nbListeAttente} en liste d'attente
|
<CardTitle>Liste des inscrits</CardTitle>
|
||||||
</CardDescription>
|
<CardDescription>
|
||||||
|
{nbConfirmes} confirmé(s), {nbListeAttente} en liste d'attente
|
||||||
|
</CardDescription>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
onClick={() => setIsAddInscritOpen(true)}
|
||||||
|
size="sm"
|
||||||
|
className="gap-2"
|
||||||
|
>
|
||||||
|
<UserPlus className="h-4 w-4" />
|
||||||
|
Ajouter un inscrit
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
{filteredAndSortedInscriptions.length === 0 ? (
|
{filteredAndSortedInscriptions.length === 0 ? (
|
||||||
@@ -577,6 +592,27 @@ export default function AdminSequenceInscrits() {
|
|||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Dialogue d'ajout d'inscrit */}
|
||||||
|
<Dialog open={isAddInscritOpen} onOpenChange={setIsAddInscritOpen}>
|
||||||
|
<DialogContent className="max-w-2xl">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Ajouter un inscrit à la séquence</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Sélectionnez un apprenant à inscrire à cette séquence
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<AddInscritForm
|
||||||
|
sequenceId={sequenceId}
|
||||||
|
onSuccess={() => {
|
||||||
|
setIsAddInscritOpen(false);
|
||||||
|
utils.inscriptions.getBySequence.invalidate({ sequenceId });
|
||||||
|
toast.success("Apprenant inscrit avec succès");
|
||||||
|
}}
|
||||||
|
onCancel={() => setIsAddInscritOpen(false)}
|
||||||
|
/>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
|
||||||
{/* Modal d'aperçu d'email */}
|
{/* Modal d'aperçu d'email */}
|
||||||
<Dialog open={showPreviewModal} onOpenChange={setShowPreviewModal}>
|
<Dialog open={showPreviewModal} onOpenChange={setShowPreviewModal}>
|
||||||
<DialogContent className="max-w-4xl max-h-[80vh] overflow-y-auto">
|
<DialogContent className="max-w-4xl max-h-[80vh] overflow-y-auto">
|
||||||
|
|||||||
@@ -1120,6 +1120,43 @@ export const appRouter = router({
|
|||||||
filename: `feuille_presence_${sequence.nom.replace(/\s+/g, '_')}.pdf`,
|
filename: `feuille_presence_${sequence.nom.replace(/\s+/g, '_')}.pdf`,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
// Ajout manuel d'un inscrit par l'admin (sans vérifications de blocage/capacité)
|
||||||
|
create: adminProcedure.input(z.object({
|
||||||
|
apprenantId: z.number(),
|
||||||
|
sequenceId: z.number(),
|
||||||
|
statut: z.enum(["confirme", "liste_attente"]),
|
||||||
|
})).mutation(async ({ input }) => {
|
||||||
|
// Vérifier si l'apprenant existe
|
||||||
|
const apprenant = await db.getApprenantById(input.apprenantId);
|
||||||
|
if (!apprenant) {
|
||||||
|
throw new TRPCError({ code: 'NOT_FOUND', message: 'Apprenant introuvable' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérifier si la séquence existe
|
||||||
|
const sequence = await db.getSequenceById(input.sequenceId);
|
||||||
|
if (!sequence) {
|
||||||
|
throw new TRPCError({ code: 'NOT_FOUND', message: 'Séquence introuvable' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérifier si l'apprenant est déjà inscrit
|
||||||
|
const existing = await db.checkExistingInscription(input.apprenantId, input.sequenceId);
|
||||||
|
if (existing) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: 'CONFLICT',
|
||||||
|
message: 'Cet apprenant est déjà inscrit à cette séquence'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Créer l'inscription avec le statut choisi
|
||||||
|
await db.createInscription({
|
||||||
|
apprenantId: input.apprenantId,
|
||||||
|
sequenceId: input.sequenceId,
|
||||||
|
statut: input.statut === "confirme" ? "confirmee" : "en_attente",
|
||||||
|
});
|
||||||
|
|
||||||
|
return { success: true };
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// ===== GESTION DES UTILISATEURS =====
|
// ===== GESTION DES UTILISATEURS =====
|
||||||
|
|||||||
15
todo.md
15
todo.md
@@ -949,3 +949,18 @@
|
|||||||
- [x] Corriger la validation pour accepter rappel1-6 au lieu de rappel/rappelJ1
|
- [x] Corriger la validation pour accepter rappel1-6 au lieu de rappel/rappelJ1
|
||||||
- [x] Tester la création d'un rappel
|
- [x] Tester la création d'un rappel
|
||||||
- [x] Déployer sur le VPS
|
- [x] Déployer sur le VPS
|
||||||
|
|
||||||
|
## Recherche exhaustive des enums de types de rappels
|
||||||
|
|
||||||
|
- [x] Rechercher tous les enums dans le code (backend + frontend)
|
||||||
|
- [x] Corriger tous les endroits manqués (TEMPLATE_TYPES dans AdminRappels.tsx)
|
||||||
|
- [x] Déployer et tester
|
||||||
|
|
||||||
|
## Ajout manuel d'apprenant dans la fenêtre "Inscrits à la séquence"
|
||||||
|
|
||||||
|
- [x] Analyser la fenêtre des inscrits (AdminSequenceInscrits.tsx)
|
||||||
|
- [x] Ajouter un bouton "Ajouter un inscrit" avec icône UserPlus dans le header
|
||||||
|
- [x] Créer un dialogue de sélection d'apprenant (AddInscritForm.tsx)
|
||||||
|
- [x] Implémenter la mutation backend inscriptions.create
|
||||||
|
- [x] Tester l'ajout manuel
|
||||||
|
- [x] Déployer sur le VPS
|
||||||
|
|||||||
Reference in New Issue
Block a user