"use client"; import { useState, useEffect } from "react"; import { useParams, useRouter } from "next/navigation"; import Link from "next/link"; import { useForm } from "react-hook-form"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { ArrowLeft, Loader2, Save } from "lucide-react"; import { toast } from "sonner"; // Type definitions interface ProjectFormData { name: string; description: string; } // Mock project data const getProjectData = (id: string) => { return { id: parseInt(id), name: "Projet Formation Dev Web", description: "Création de groupes pour la formation développement web", date: "2025-05-15", }; }; export default function EditProjectPage() { const params = useParams(); const router = useRouter(); const projectId = params.id as string; const [project, setProject] = useState(null); const [loading, setLoading] = useState(true); const [isSubmitting, setIsSubmitting] = useState(false); const { register, handleSubmit, formState: { errors }, reset } = useForm(); useEffect(() => { // Simulate API call to fetch project data const fetchProject = async () => { setLoading(true); try { // In a real app, this would be an API call await new Promise(resolve => setTimeout(resolve, 1000)); const data = getProjectData(projectId); setProject(data); // Reset form with project data reset({ name: data.name, description: data.description }); } catch (error) { console.error("Error fetching project:", error); toast.error("Erreur lors du chargement du projet"); } finally { setLoading(false); } }; fetchProject(); }, [projectId, reset]); const onSubmit = async (data: ProjectFormData) => { setIsSubmitting(true); try { // In a real app, this would be an API call to update the project await new Promise(resolve => setTimeout(resolve, 1000)); toast.success("Projet mis à jour avec succès"); router.push(`/projects/${projectId}`); } catch (error) { console.error("Error updating project:", error); toast.error("Erreur lors de la mise à jour du projet"); } finally { setIsSubmitting(false); } }; if (loading) { return (
); } if (!project) { return (

Projet non trouvé

); } return (

Modifier le projet

Informations du projet Modifiez les informations de votre projet
{errors.name && (

{errors.name.message}

)}