Checkpoint: Trois améliorations majeures du champ formateur :
✅ **1. Affichage dans le tableau des séquences** - Nouvelle colonne "Formateur" ajoutée au tableau de gestion - Affiche le nom du formateur ou "-" si non renseigné ✅ **2. Liste prédéfinie avec autocomplétion** - Nouvelle table `formateurs` dans la base de données - Procédures tRPC (list, create, delete) pour gérer les formateurs - Composant `FormateurCombobox` avec autocomplétion intelligente - Possibilité d'ajouter rapidement un nouveau formateur depuis le formulaire - Recherche en temps réel parmi les formateurs existants ✅ **3. Inclusion dans les emails d'invitation** - Le nom du formateur est maintenant affiché dans les emails de confirmation d'inscription - Affichage conditionnel (uniquement si un formateur est renseigné) - Améliore la communication avec les apprenants Ces améliorations standardisent la gestion des formateurs, évitent les doublons/fautes de frappe, et enrichissent l'information transmise aux apprenants.
This commit is contained in:
135
client/src/components/FormateurCombobox.tsx
Normal file
135
client/src/components/FormateurCombobox.tsx
Normal file
@@ -0,0 +1,135 @@
|
||||
import { useState } from "react";
|
||||
import { Check, ChevronsUpDown, Plus } from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Command,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandInput,
|
||||
CommandItem,
|
||||
CommandList,
|
||||
} from "@/components/ui/command";
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover";
|
||||
import { trpc } from "@/lib/trpc";
|
||||
import { toast } from "sonner";
|
||||
|
||||
interface FormateurComboboxProps {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
placeholder?: string;
|
||||
}
|
||||
|
||||
export function FormateurCombobox({ value, onChange, placeholder = "Sélectionner un formateur..." }: FormateurComboboxProps) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [searchValue, setSearchValue] = useState("");
|
||||
|
||||
const { data: formateurs = [], refetch } = trpc.formateurs.list.useQuery();
|
||||
const createMutation = trpc.formateurs.create.useMutation({
|
||||
onSuccess: () => {
|
||||
toast.success("Formateur ajouté");
|
||||
refetch();
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error(error.message || "Erreur lors de l'ajout du formateur");
|
||||
},
|
||||
});
|
||||
|
||||
const handleAddNew = () => {
|
||||
if (!searchValue.trim()) {
|
||||
toast.error("Veuillez entrer un nom de formateur");
|
||||
return;
|
||||
}
|
||||
|
||||
// Vérifier si le formateur existe déjà
|
||||
const exists = formateurs.some(f => f.nom.toLowerCase() === searchValue.toLowerCase());
|
||||
if (exists) {
|
||||
toast.error("Ce formateur existe déjà");
|
||||
return;
|
||||
}
|
||||
|
||||
createMutation.mutate({ nom: searchValue.trim() });
|
||||
onChange(searchValue.trim());
|
||||
setSearchValue("");
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
className="w-full justify-between"
|
||||
>
|
||||
{value || placeholder}
|
||||
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-full p-0">
|
||||
<Command>
|
||||
<CommandInput
|
||||
placeholder="Rechercher ou ajouter un formateur..."
|
||||
value={searchValue}
|
||||
onValueChange={setSearchValue}
|
||||
/>
|
||||
<CommandList>
|
||||
<CommandEmpty>
|
||||
<div className="flex flex-col items-center gap-2 py-2">
|
||||
<p className="text-sm text-muted-foreground">Aucun formateur trouvé</p>
|
||||
{searchValue && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={handleAddNew}
|
||||
disabled={createMutation.isPending}
|
||||
>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
Ajouter "{searchValue}"
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{formateurs.map((formateur) => (
|
||||
<CommandItem
|
||||
key={formateur.id}
|
||||
value={formateur.nom}
|
||||
onSelect={(currentValue) => {
|
||||
onChange(currentValue === value ? "" : currentValue);
|
||||
setOpen(false);
|
||||
setSearchValue("");
|
||||
}}
|
||||
>
|
||||
<Check
|
||||
className={cn(
|
||||
"mr-2 h-4 w-4",
|
||||
value === formateur.nom ? "opacity-100" : "opacity-0"
|
||||
)}
|
||||
/>
|
||||
{formateur.nom}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
{searchValue && !formateurs.some(f => f.nom.toLowerCase() === searchValue.toLowerCase()) && (
|
||||
<CommandGroup>
|
||||
<CommandItem
|
||||
onSelect={handleAddNew}
|
||||
className="text-primary"
|
||||
>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
Ajouter "{searchValue}"
|
||||
</CommandItem>
|
||||
</CommandGroup>
|
||||
)}
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useState, useMemo } from "react";
|
||||
import { useState } from "react";
|
||||
import DashboardLayout from "@/components/DashboardLayout";
|
||||
import { FormateurCombobox } from "@/components/FormateurCombobox";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
||||
@@ -402,11 +403,10 @@ export default function AdminSequences() {
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="formateur">Formateur</Label>
|
||||
<Input
|
||||
id="formateur"
|
||||
<FormateurCombobox
|
||||
value={formData.formateur}
|
||||
onChange={(e) => setFormData({ ...formData, formateur: e.target.value })}
|
||||
placeholder="Nom du formateur (optionnel)"
|
||||
onChange={(value) => setFormData({ ...formData, formateur: value })}
|
||||
placeholder="Sélectionner un formateur (optionnel)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -636,6 +636,7 @@ export default function AdminSequences() {
|
||||
<TableHead>Dates</TableHead>
|
||||
<TableHead>Lieu</TableHead>
|
||||
<TableHead>Public cible</TableHead>
|
||||
<TableHead>Formateur</TableHead>
|
||||
<TableHead>Capacité</TableHead>
|
||||
<TableHead>Statut</TableHead>
|
||||
<TableHead className="text-right">Actions</TableHead>
|
||||
@@ -662,6 +663,7 @@ export default function AdminSequences() {
|
||||
{getPublicCibleLabel(sequence.publicCible)}
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell className="max-w-xs truncate">{sequence.formateur || "-"}</TableCell>
|
||||
<TableCell>{sequence.nbInscrits || 0} / {sequence.capaciteMax}</TableCell>
|
||||
<TableCell>
|
||||
<span className={`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${getStatutBadge(sequence.statut)}`}>
|
||||
@@ -775,11 +777,10 @@ export default function AdminSequences() {
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="edit-formateur">Formateur</Label>
|
||||
<Input
|
||||
id="edit-formateur"
|
||||
<FormateurCombobox
|
||||
value={formData.formateur}
|
||||
onChange={(e) => setFormData({ ...formData, formateur: e.target.value })}
|
||||
placeholder="Nom du formateur (optionnel)"
|
||||
onChange={(value) => setFormData({ ...formData, formateur: value })}
|
||||
placeholder="Sélectionner un formateur (optionnel)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user