missions api2 gitea
This commit is contained in:
parent
4aaf4e8016
commit
c4026709cb
59
app/missions/[missionId]/edit/page.tsx
Normal file
59
app/missions/[missionId]/edit/page.tsx
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
|
import { useParams, useRouter } from "next/navigation";
|
||||||
|
|
||||||
|
export default function EditMissionPage() {
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const { toast } = useToast();
|
||||||
|
const params = useParams();
|
||||||
|
const router = useRouter();
|
||||||
|
const missionId = params.missionId as string;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
toast({
|
||||||
|
title: "Fonctionnalité en développement",
|
||||||
|
description: "L'édition de mission sera bientôt disponible.",
|
||||||
|
variant: "default",
|
||||||
|
});
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
|
}, [toast]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="bg-gray-50 min-h-screen p-6">
|
||||||
|
<div className="bg-white rounded-lg shadow-sm border border-gray-100 mb-6 p-6">
|
||||||
|
<h1 className="text-2xl font-bold text-gray-900 mb-6">Modifier la mission</h1>
|
||||||
|
|
||||||
|
{loading ? (
|
||||||
|
<div className="flex justify-center my-12">
|
||||||
|
<div className="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-blue-600"></div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="space-y-6">
|
||||||
|
<p className="text-gray-500">
|
||||||
|
La fonctionnalité d'édition de mission est en cours de développement et sera disponible prochainement.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="flex gap-4">
|
||||||
|
<Button
|
||||||
|
onClick={() => router.push(`/missions/${missionId}`)}
|
||||||
|
variant="outline"
|
||||||
|
>
|
||||||
|
Retour à la mission
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
onClick={() => router.push("/missions")}
|
||||||
|
>
|
||||||
|
Voir toutes les missions
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { FileIcon, Calendar, Eye, MapPin, Users, Clock, ThumbsUp, Languages, BarChart } from "lucide-react";
|
import { FileIcon, Calendar, Eye, MapPin, Users, Clock, ThumbsUp, Languages, BarChart, Edit, Trash2 } from "lucide-react";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
import { useParams } from "next/navigation";
|
import { useParams, useRouter } from "next/navigation";
|
||||||
|
|
||||||
// Define types for mission details
|
// Define types for mission details
|
||||||
interface User {
|
interface User {
|
||||||
@ -45,8 +45,10 @@ interface Mission {
|
|||||||
export default function MissionDetailPage() {
|
export default function MissionDetailPage() {
|
||||||
const [mission, setMission] = useState<Mission | null>(null);
|
const [mission, setMission] = useState<Mission | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [deleting, setDeleting] = useState(false);
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
|
const router = useRouter();
|
||||||
const missionId = params.missionId as string;
|
const missionId = params.missionId as string;
|
||||||
|
|
||||||
// Fetch mission details
|
// Fetch mission details
|
||||||
@ -133,6 +135,46 @@ export default function MissionDetailPage() {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handle edit mission
|
||||||
|
const handleEditMission = () => {
|
||||||
|
router.push(`/missions/${missionId}/edit`);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Handle delete mission
|
||||||
|
const handleDeleteMission = async () => {
|
||||||
|
if (!confirm("Êtes-vous sûr de vouloir supprimer cette mission ? Cette action est irréversible.")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
setDeleting(true);
|
||||||
|
const response = await fetch(`/api/missions/${missionId}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Failed to delete mission');
|
||||||
|
}
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: "Mission supprimée",
|
||||||
|
description: "La mission a été supprimée avec succès",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Redirect back to missions list
|
||||||
|
router.push('/missions');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error deleting mission:', error);
|
||||||
|
toast({
|
||||||
|
title: "Erreur",
|
||||||
|
description: "Impossible de supprimer la mission",
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setDeleting(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Loading state
|
// Loading state
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return (
|
return (
|
||||||
@ -349,6 +391,32 @@ export default function MissionDetailPage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Action Buttons */}
|
||||||
|
<div className="flex justify-end gap-4 mb-8">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className="flex items-center gap-2 border-blue-600 text-blue-600 hover:bg-blue-50"
|
||||||
|
onClick={handleEditMission}
|
||||||
|
>
|
||||||
|
<Edit className="h-4 w-4" />
|
||||||
|
Modifier
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className="flex items-center gap-2 border-red-600 text-red-600 hover:bg-red-50"
|
||||||
|
onClick={handleDeleteMission}
|
||||||
|
disabled={deleting}
|
||||||
|
>
|
||||||
|
{deleting ? (
|
||||||
|
<div className="animate-spin rounded-full h-4 w-4 border-t-2 border-b-2 border-red-600"></div>
|
||||||
|
) : (
|
||||||
|
<Trash2 className="h-4 w-4" />
|
||||||
|
)}
|
||||||
|
Supprimer
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user