refactor: remove unused components and clean up evaluation client
- Deleted CreateSkillForm and ProfileForm components as they are no longer needed. - Removed the initializeEmptyEvaluation method from EvaluationClient, as the backend handles evaluation creation. - Updated exports in evaluation index to reflect the removal of WelcomeEvaluationScreen.
This commit is contained in:
@@ -1,226 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Plus, X, Link as LinkIcon, Loader2 } from "lucide-react";
|
||||
import { skillsClient } from "@/clients";
|
||||
|
||||
interface CreateSkillFormProps {
|
||||
categoryName: string;
|
||||
onSuccess: (skillId: string) => void;
|
||||
onCancel: () => void;
|
||||
}
|
||||
|
||||
export function CreateSkillForm({
|
||||
categoryName,
|
||||
onSuccess,
|
||||
onCancel,
|
||||
}: CreateSkillFormProps) {
|
||||
const [formData, setFormData] = useState({
|
||||
name: "",
|
||||
description: "",
|
||||
icon: "",
|
||||
links: [""],
|
||||
});
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
const addLink = () => {
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
links: [...prev.links, ""],
|
||||
}));
|
||||
};
|
||||
|
||||
const removeLink = (index: number) => {
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
links: prev.links.filter((_, i) => i !== index),
|
||||
}));
|
||||
};
|
||||
|
||||
const updateLink = (index: number, value: string) => {
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
links: prev.links.map((link, i) => (i === index ? value : link)),
|
||||
}));
|
||||
};
|
||||
|
||||
const generateSkillId = (name: string) => {
|
||||
return name
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9\s]/g, "")
|
||||
.replace(/\s+/g, "-")
|
||||
.trim();
|
||||
};
|
||||
|
||||
const getCategoryId = (categoryName: string) => {
|
||||
// Convertir le nom de catégorie en ID (ex: "Cloud" -> "cloud")
|
||||
return categoryName.toLowerCase();
|
||||
};
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setError("");
|
||||
setIsLoading(true);
|
||||
|
||||
try {
|
||||
// Validation
|
||||
if (!formData.name.trim()) {
|
||||
throw new Error("Le nom de la compétence est requis");
|
||||
}
|
||||
if (!formData.description.trim()) {
|
||||
throw new Error("La description est requise");
|
||||
}
|
||||
|
||||
const skillId = generateSkillId(formData.name);
|
||||
const categoryId = getCategoryId(categoryName);
|
||||
|
||||
// Filtrer les liens vides
|
||||
const validLinks = formData.links.filter((link) => link.trim());
|
||||
|
||||
const skillData = {
|
||||
id: skillId,
|
||||
name: formData.name.trim(),
|
||||
description: formData.description.trim(),
|
||||
icon: formData.icon.trim() || "fas-cog",
|
||||
links: validLinks,
|
||||
};
|
||||
|
||||
const success = await skillsClient.createSkill(categoryId, skillData);
|
||||
|
||||
if (success) {
|
||||
onSuccess(skillId);
|
||||
} else {
|
||||
throw new Error("Erreur lors de la création de la compétence");
|
||||
}
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : "Une erreur est survenue");
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
{error && (
|
||||
<div className="p-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded-md">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="skill-name">Nom de la compétence *</Label>
|
||||
<Input
|
||||
id="skill-name"
|
||||
placeholder="ex: Next.js, Docker, Figma..."
|
||||
value={formData.name}
|
||||
onChange={(e) =>
|
||||
setFormData((prev) => ({ ...prev, name: e.target.value }))
|
||||
}
|
||||
disabled={isLoading}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="skill-description">Description *</Label>
|
||||
<Textarea
|
||||
id="skill-description"
|
||||
placeholder="Décrivez brièvement cette compétence..."
|
||||
value={formData.description}
|
||||
onChange={(e) =>
|
||||
setFormData((prev) => ({ ...prev, description: e.target.value }))
|
||||
}
|
||||
disabled={isLoading}
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="skill-icon">Icône (optionnel)</Label>
|
||||
<Input
|
||||
id="skill-icon"
|
||||
placeholder="ex: fab-react, fas-database..."
|
||||
value={formData.icon}
|
||||
onChange={(e) =>
|
||||
setFormData((prev) => ({ ...prev, icon: e.target.value }))
|
||||
}
|
||||
disabled={isLoading}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Utilisez les classes FontAwesome (fab-, fas-, far-) ou laissez vide
|
||||
pour l'icône par défaut
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label>Liens de référence (optionnel)</Label>
|
||||
{formData.links.map((link, index) => (
|
||||
<div key={index} className="flex gap-2">
|
||||
<div className="relative flex-1">
|
||||
<LinkIcon className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
||||
<Input
|
||||
placeholder="https://..."
|
||||
value={link}
|
||||
onChange={(e) => updateLink(index, e.target.value)}
|
||||
disabled={isLoading}
|
||||
className="pl-10"
|
||||
/>
|
||||
</div>
|
||||
{formData.links.length > 1 && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => removeLink(index)}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
{formData.links.length < 5 && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={addLink}
|
||||
disabled={isLoading}
|
||||
className="gap-2"
|
||||
>
|
||||
<Plus className="h-3 w-3" />
|
||||
Ajouter un lien
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex gap-3 pt-4">
|
||||
<Button type="submit" disabled={isLoading} className="flex-1">
|
||||
{isLoading ? (
|
||||
<>
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
Création...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
Créer la compétence
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={onCancel}
|
||||
disabled={isLoading}
|
||||
>
|
||||
Annuler
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -2,7 +2,7 @@ export {
|
||||
EvaluationClientWrapper,
|
||||
useEvaluationContext,
|
||||
} from "./client-wrapper";
|
||||
export { WelcomeEvaluationScreen } from "./welcome-screen";
|
||||
|
||||
export { EvaluationHeader } from "./evaluation-header";
|
||||
export { CategoryTabs } from "./category-tabs";
|
||||
export { SkillEvaluationGrid } from "./skill-evaluation-grid";
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { ProfileForm } from "@/components/profile-form";
|
||||
import { evaluationClient } from "@/clients";
|
||||
import { Team, UserProfile } from "@/lib/types";
|
||||
import { Code2 } from "lucide-react";
|
||||
|
||||
interface WelcomeEvaluationScreenProps {
|
||||
teams: Team[];
|
||||
}
|
||||
|
||||
export function WelcomeEvaluationScreen({
|
||||
teams,
|
||||
}: WelcomeEvaluationScreenProps) {
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const router = useRouter();
|
||||
|
||||
const handleProfileSubmit = async (profile: UserProfile) => {
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
await evaluationClient.initializeEmptyEvaluation(profile);
|
||||
// Rafraîchir la page pour que le SSR prenne en compte la nouvelle évaluation
|
||||
router.refresh();
|
||||
} catch (error) {
|
||||
console.error("Failed to initialize evaluation:", error);
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-slate-950 via-slate-900 to-slate-950 relative overflow-hidden">
|
||||
<div className="absolute inset-0 bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-blue-900/20 via-slate-900 to-slate-950" />
|
||||
<div className="absolute inset-0 bg-grid-white/5 bg-[size:50px_50px]" />
|
||||
|
||||
<div className="relative z-10 container mx-auto py-16 px-6">
|
||||
<div className="text-center mb-12">
|
||||
<div className="inline-flex items-center gap-2 px-4 py-2 rounded-full bg-white/5 border border-white/10 backdrop-blur-sm mb-6">
|
||||
<Code2 className="h-4 w-4 text-blue-400" />
|
||||
<span className="text-sm font-medium text-slate-200">
|
||||
PeakSkills - Évaluation
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<h1 className="text-4xl font-bold mb-4 text-white">
|
||||
Commencer l'évaluation
|
||||
</h1>
|
||||
<p className="text-lg text-slate-400 mb-8">
|
||||
Renseignez vos informations pour débuter votre auto-évaluation
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="max-w-2xl mx-auto">
|
||||
<div className="relative">
|
||||
{isSubmitting && (
|
||||
<div className="absolute inset-0 bg-black/20 backdrop-blur-sm z-10 flex items-center justify-center rounded-lg">
|
||||
<div className="text-center">
|
||||
<div className="animate-spin rounded-full h-6 w-6 border-b-2 border-blue-400 mx-auto mb-2"></div>
|
||||
<p className="text-white text-sm">
|
||||
Initialisation de l'évaluation...
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<ProfileForm teams={teams} onSubmit={handleProfileSubmit} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
export { LoginFormWrapper } from "./login-form-wrapper";
|
||||
export { LoginForm } from "./login-form";
|
||||
export { RegisterForm } from "./register-form";
|
||||
export { AuthWrapper } from "./auth-wrapper";
|
||||
|
||||
@@ -1,213 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { ProfileForm } from "@/components/profile-form";
|
||||
import { authClient } from "@/clients";
|
||||
import { UserProfile, Team } from "@/lib/types";
|
||||
import { Code2, LogOut, Edit, X, Home } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
|
||||
interface LoginFormWrapperProps {
|
||||
teams: Team[];
|
||||
initialUser?: UserProfile | null;
|
||||
}
|
||||
|
||||
export function LoginFormWrapper({
|
||||
teams,
|
||||
initialUser,
|
||||
}: LoginFormWrapperProps) {
|
||||
const [authenticating, setAuthenticating] = useState(false);
|
||||
const [currentUser, setCurrentUser] = useState<UserProfile | null>(
|
||||
initialUser || null
|
||||
);
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
if (initialUser) {
|
||||
setCurrentUser(initialUser);
|
||||
}
|
||||
}, [initialUser]);
|
||||
|
||||
const handleSubmit = async (profile: UserProfile) => {
|
||||
setAuthenticating(true);
|
||||
try {
|
||||
await authClient.login(profile);
|
||||
if (isEditing) {
|
||||
// Si on modifie le profil existant, mettre à jour l'état
|
||||
setCurrentUser(profile);
|
||||
setIsEditing(false);
|
||||
} else {
|
||||
// Si c'est un nouveau login, rediriger
|
||||
router.push("/");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Login failed:", error);
|
||||
// Vous pouvez ajouter une notification d'erreur ici
|
||||
} finally {
|
||||
setAuthenticating(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleLogout = async () => {
|
||||
try {
|
||||
await authClient.logout();
|
||||
setCurrentUser(null);
|
||||
setIsEditing(false);
|
||||
} catch (error) {
|
||||
console.error("Logout failed:", error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleEdit = () => {
|
||||
setIsEditing(true);
|
||||
};
|
||||
|
||||
const handleCancelEdit = () => {
|
||||
setIsEditing(false);
|
||||
};
|
||||
|
||||
// Si l'utilisateur est connecté et qu'on ne modifie pas
|
||||
if (currentUser && !isEditing) {
|
||||
const currentTeam = teams.find((t) => t.id === currentUser.teamId);
|
||||
|
||||
return (
|
||||
<div className="text-center mb-12">
|
||||
<div className="inline-flex items-center gap-2 px-4 py-2 rounded-full bg-white/5 border border-white/10 backdrop-blur-sm mb-6">
|
||||
<Code2 className="h-4 w-4 text-blue-400" />
|
||||
<span className="text-sm font-medium text-slate-200">PeakSkills</span>
|
||||
</div>
|
||||
|
||||
<h1 className="text-4xl font-bold mb-4 text-white">
|
||||
Vous êtes connecté
|
||||
</h1>
|
||||
<p className="text-lg text-slate-400 mb-8">
|
||||
Gérez votre profil ou retournez à l'application
|
||||
</p>
|
||||
|
||||
<div className="max-w-2xl mx-auto space-y-6">
|
||||
{/* Informations utilisateur */}
|
||||
<Card className="bg-white/5 border-white/10 backdrop-blur-sm">
|
||||
<CardHeader>
|
||||
<CardTitle className="text-white">Vos informations</CardTitle>
|
||||
<CardDescription className="text-slate-400">
|
||||
Profil actuellement connecté
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="text-sm font-medium text-slate-300">
|
||||
Prénom
|
||||
</label>
|
||||
<p className="text-white">{currentUser.firstName}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label className="text-sm font-medium text-slate-300">
|
||||
Nom
|
||||
</label>
|
||||
<p className="text-white">{currentUser.lastName}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="text-sm font-medium text-slate-300">
|
||||
Équipe
|
||||
</label>
|
||||
<p className="text-white">
|
||||
{currentTeam?.name || "Équipe non trouvée"}
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex gap-4 justify-center">
|
||||
<Button
|
||||
onClick={() => router.push("/")}
|
||||
className="bg-blue-500 hover:bg-blue-600 text-white"
|
||||
>
|
||||
<Home className="w-4 h-4 mr-2" />
|
||||
Retour à l'accueil
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleEdit}
|
||||
variant="outline"
|
||||
className="border-white/20 text-white hover:bg-white/10"
|
||||
>
|
||||
<Edit className="w-4 h-4 mr-2" />
|
||||
Modifier le profil
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleLogout}
|
||||
variant="outline"
|
||||
className="border-red-500/50 text-red-400 hover:bg-red-500/10"
|
||||
>
|
||||
<LogOut className="w-4 h-4 mr-2" />
|
||||
Se déconnecter
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Sinon, afficher le formulaire (nouvel utilisateur ou modification)
|
||||
return (
|
||||
<div className="text-center mb-12">
|
||||
<div className="inline-flex items-center gap-2 px-4 py-2 rounded-full bg-white/5 border border-white/10 backdrop-blur-sm mb-6">
|
||||
<Code2 className="h-4 w-4 text-blue-400" />
|
||||
<span className="text-sm font-medium text-slate-200">PeakSkills</span>
|
||||
</div>
|
||||
|
||||
<h1 className="text-4xl font-bold mb-4 text-white">
|
||||
{isEditing ? "Modifier vos informations" : "Bienvenue sur PeakSkills"}
|
||||
</h1>
|
||||
<p className="text-lg text-slate-400 mb-8">
|
||||
{isEditing
|
||||
? "Mettez à jour vos informations personnelles"
|
||||
: "Évaluez vos compétences techniques et suivez votre progression"}
|
||||
</p>
|
||||
|
||||
{isEditing && (
|
||||
<Button
|
||||
onClick={handleCancelEdit}
|
||||
variant="outline"
|
||||
className="mb-8 border-white/20 text-white hover:bg-white/10"
|
||||
>
|
||||
<X className="w-4 h-4 mr-2" />
|
||||
Annuler
|
||||
</Button>
|
||||
)}
|
||||
|
||||
<div className="max-w-2xl mx-auto">
|
||||
<div className="relative">
|
||||
{authenticating && (
|
||||
<div className="absolute inset-0 bg-black/20 backdrop-blur-sm z-10 flex items-center justify-center rounded-lg">
|
||||
<div className="text-center">
|
||||
<div className="animate-spin rounded-full h-6 w-6 border-b-2 border-blue-400 mx-auto mb-2"></div>
|
||||
<p className="text-white text-sm">
|
||||
{isEditing
|
||||
? "Mise à jour en cours..."
|
||||
: "Connexion en cours..."}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<ProfileForm
|
||||
teams={teams}
|
||||
onSubmit={handleSubmit}
|
||||
initialProfile={isEditing && currentUser ? currentUser : undefined}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,226 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useMemo, useRef, useEffect } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { UserProfile, Team } from "@/lib/types";
|
||||
import { Search, Building2, ChevronDown, Check } from "lucide-react";
|
||||
|
||||
interface ProfileFormProps {
|
||||
teams: Team[];
|
||||
initialProfile?: UserProfile;
|
||||
onSubmit: (profile: UserProfile) => void;
|
||||
}
|
||||
|
||||
export function ProfileForm({
|
||||
teams,
|
||||
initialProfile,
|
||||
onSubmit,
|
||||
}: ProfileFormProps) {
|
||||
const [firstName, setFirstName] = useState(initialProfile?.firstName || "");
|
||||
const [lastName, setLastName] = useState(initialProfile?.lastName || "");
|
||||
const [teamId, setTeamId] = useState(initialProfile?.teamId || "");
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
const [isTeamDropdownOpen, setIsTeamDropdownOpen] = useState(false);
|
||||
const teamDropdownRef = useRef<HTMLDivElement>(null);
|
||||
const [dropdownPosition, setDropdownPosition] = useState<"below" | "above">(
|
||||
"below"
|
||||
);
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (firstName && lastName && teamId) {
|
||||
onSubmit({ firstName, lastName, teamId });
|
||||
}
|
||||
};
|
||||
|
||||
const isValid =
|
||||
firstName.length > 0 && lastName.length > 0 && teamId.length > 0;
|
||||
|
||||
// Group teams by direction and filter by search term
|
||||
const teamsByDirection = useMemo(() => {
|
||||
const filteredTeams = teams.filter(
|
||||
(team) =>
|
||||
team.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
||||
team.direction.toLowerCase().includes(searchTerm.toLowerCase())
|
||||
);
|
||||
|
||||
return filteredTeams.reduce((acc, team) => {
|
||||
if (!acc[team.direction]) {
|
||||
acc[team.direction] = [];
|
||||
}
|
||||
acc[team.direction].push(team);
|
||||
return acc;
|
||||
}, {} as Record<string, Team[]>);
|
||||
}, [teams, searchTerm]);
|
||||
|
||||
// Calculate dropdown position when opening
|
||||
const handleDropdownToggle = () => {
|
||||
if (!isTeamDropdownOpen && teamDropdownRef.current) {
|
||||
const rect = teamDropdownRef.current.getBoundingClientRect();
|
||||
const viewportHeight = window.innerHeight;
|
||||
const spaceBelow = viewportHeight - rect.bottom;
|
||||
const spaceAbove = rect.top;
|
||||
const dropdownHeight = 300; // max-height of dropdown
|
||||
|
||||
setDropdownPosition(
|
||||
spaceBelow >= dropdownHeight || spaceBelow > spaceAbove
|
||||
? "below"
|
||||
: "above"
|
||||
);
|
||||
}
|
||||
setIsTeamDropdownOpen(!isTeamDropdownOpen);
|
||||
};
|
||||
|
||||
// Close dropdown when clicking outside
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
if (
|
||||
teamDropdownRef.current &&
|
||||
!teamDropdownRef.current.contains(event.target as Node)
|
||||
) {
|
||||
setIsTeamDropdownOpen(false);
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener("mousedown", handleClickOutside);
|
||||
return () => document.removeEventListener("mousedown", handleClickOutside);
|
||||
}, []);
|
||||
|
||||
const selectedTeam = teams.find((team) => team.id === teamId);
|
||||
|
||||
return (
|
||||
<Card className="w-full max-w-md mx-auto">
|
||||
<CardHeader>
|
||||
<CardTitle>Informations personnelles</CardTitle>
|
||||
<CardDescription>
|
||||
Renseignez vos informations pour commencer votre auto-évaluation
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="firstName">Prénom</Label>
|
||||
<Input
|
||||
id="firstName"
|
||||
value={firstName}
|
||||
onChange={(e) => setFirstName(e.target.value)}
|
||||
placeholder="Votre prénom"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="lastName">Nom</Label>
|
||||
<Input
|
||||
id="lastName"
|
||||
value={lastName}
|
||||
onChange={(e) => setLastName(e.target.value)}
|
||||
placeholder="Votre nom"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="team">Équipe</Label>
|
||||
<div className="relative" ref={teamDropdownRef}>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
className="w-full justify-between"
|
||||
onClick={handleDropdownToggle}
|
||||
>
|
||||
<span
|
||||
className={
|
||||
selectedTeam ? "text-foreground" : "text-muted-foreground"
|
||||
}
|
||||
>
|
||||
{selectedTeam
|
||||
? selectedTeam.name
|
||||
: "Sélectionnez votre équipe"}
|
||||
</span>
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
</Button>
|
||||
|
||||
{isTeamDropdownOpen && (
|
||||
<div
|
||||
className={`absolute left-0 right-0 bg-background border border-border rounded-md shadow-lg z-50 max-h-[300px] overflow-y-auto ${
|
||||
dropdownPosition === "below"
|
||||
? "top-full mt-1"
|
||||
: "bottom-full mb-1"
|
||||
}`}
|
||||
>
|
||||
{/* Barre de recherche */}
|
||||
<div className="sticky top-0 bg-background border-b p-2">
|
||||
<div className="relative">
|
||||
<Search className="absolute left-2 top-2.5 h-4 w-4 text-muted-foreground" />
|
||||
<Input
|
||||
placeholder="Rechercher une équipe ou direction..."
|
||||
value={searchTerm}
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
className="pl-8 h-8 text-sm"
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Liste des équipes groupées par direction */}
|
||||
{Object.entries(teamsByDirection).map(
|
||||
([direction, directionTeams]) => (
|
||||
<div key={direction}>
|
||||
{/* En-tête de direction (non-cliquable) */}
|
||||
<div className="px-3 py-2 text-sm font-semibold text-muted-foreground bg-muted/30 border-b border-border flex items-center gap-2">
|
||||
<Building2 className="h-3 w-3" />
|
||||
{direction}
|
||||
</div>
|
||||
{/* Équipes de cette direction */}
|
||||
{directionTeams.map((team) => (
|
||||
<button
|
||||
key={team.id}
|
||||
type="button"
|
||||
className={`w-full px-3 py-2 text-left hover:bg-muted/50 flex items-center justify-between ${
|
||||
team.id === teamId ? "bg-muted" : ""
|
||||
}`}
|
||||
onClick={() => {
|
||||
setTeamId(team.id);
|
||||
setIsTeamDropdownOpen(false);
|
||||
setSearchTerm("");
|
||||
}}
|
||||
>
|
||||
<span>{team.name}</span>
|
||||
{team.id === teamId && (
|
||||
<Check className="h-4 w-4 text-primary" />
|
||||
)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
|
||||
{/* Message si aucune équipe trouvée */}
|
||||
{Object.keys(teamsByDirection).length === 0 && (
|
||||
<div className="px-3 py-4 text-center text-sm text-muted-foreground">
|
||||
Aucune équipe trouvée pour "{searchTerm}"
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Button type="submit" className="w-full" disabled={!isValid}>
|
||||
{initialProfile ? "Mettre à jour" : "Commencer l'évaluation"}
|
||||
</Button>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user