missions page 2
This commit is contained in:
parent
aada0b8b5d
commit
9f37a8fdf7
391
app/mission-tab/[missionId]/page.tsx
Normal file
391
app/mission-tab/[missionId]/page.tsx
Normal file
@ -0,0 +1,391 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { FileIcon, Calendar, Eye, MapPin, Users, Clock, ThumbsUp, Languages, ArrowLeft } from "lucide-react";
|
||||
import { useToast } from "@/components/ui/use-toast";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import Link from "next/link";
|
||||
|
||||
// Define types for mission details
|
||||
interface User {
|
||||
id: string;
|
||||
email: string;
|
||||
}
|
||||
|
||||
interface Attachment {
|
||||
id: string;
|
||||
filename: string;
|
||||
filePath: string;
|
||||
fileType: string;
|
||||
fileSize: number;
|
||||
publicUrl: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
interface Mission {
|
||||
id: string;
|
||||
name: string;
|
||||
logo?: string | null;
|
||||
logoUrl?: string | null;
|
||||
oddScope: string[];
|
||||
niveau: string;
|
||||
missionType: string;
|
||||
projection: string;
|
||||
intention?: string;
|
||||
donneurDOrdre?: string;
|
||||
participation?: string;
|
||||
services?: string[];
|
||||
profils?: string[];
|
||||
attachments?: Attachment[];
|
||||
createdAt: string;
|
||||
creator: User;
|
||||
missionUsers: any[];
|
||||
}
|
||||
|
||||
export default function MissionTabDetailPage() {
|
||||
const [mission, setMission] = useState<Mission | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const { toast } = useToast();
|
||||
const params = useParams();
|
||||
const router = useRouter();
|
||||
const missionId = params.missionId as string;
|
||||
|
||||
// Fetch mission details
|
||||
useEffect(() => {
|
||||
const fetchMissionDetails = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await fetch(`/api/missions/${missionId}`);
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch mission details');
|
||||
}
|
||||
const data = await response.json();
|
||||
console.log("Mission details:", data);
|
||||
setMission(data);
|
||||
} catch (error) {
|
||||
console.error('Error fetching mission details:', error);
|
||||
toast({
|
||||
title: "Erreur",
|
||||
description: "Impossible de charger les détails de la mission",
|
||||
variant: "destructive",
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (missionId) {
|
||||
fetchMissionDetails();
|
||||
}
|
||||
}, [missionId, toast]);
|
||||
|
||||
// Helper function to format date
|
||||
const formatDate = (dateString: string) => {
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString('fr-FR', {
|
||||
day: '2-digit',
|
||||
month: 'long',
|
||||
year: 'numeric'
|
||||
});
|
||||
};
|
||||
|
||||
// Helper functions to get labels
|
||||
const getMissionTypeLabel = (type: string) => {
|
||||
switch(type) {
|
||||
case 'remote': return 'À distance';
|
||||
case 'onsite': return 'Sur site';
|
||||
case 'hybrid': return 'Hybride';
|
||||
default: return type;
|
||||
}
|
||||
};
|
||||
|
||||
const getDurationLabel = (projection: string) => {
|
||||
switch(projection) {
|
||||
case 'short': return '< 1 mois';
|
||||
case 'medium': return '1-3 mois';
|
||||
case 'long': return '> 3 mois';
|
||||
default: return projection;
|
||||
}
|
||||
};
|
||||
|
||||
const getNiveauLabel = (niveau: string) => {
|
||||
switch(niveau) {
|
||||
case 'a': return 'Apprentissage';
|
||||
case 'b': return 'Basique';
|
||||
case 'c': return 'Complexe';
|
||||
case 's': return 'Spécial';
|
||||
default: return niveau;
|
||||
}
|
||||
};
|
||||
|
||||
// Function to get odd info
|
||||
const getODDInfo = (oddScope: string[]) => {
|
||||
const oddCode = oddScope && oddScope.length > 0
|
||||
? oddScope[0]
|
||||
: null;
|
||||
|
||||
// Extract number from odd code (e.g., "odd-3" -> "3")
|
||||
const oddNumber = oddCode ? oddCode.replace('odd-', '') : null;
|
||||
|
||||
return {
|
||||
number: oddNumber,
|
||||
label: oddNumber ? `ODD ${oddNumber}` : "Non catégorisé",
|
||||
iconPath: oddNumber ? `/F SDG Icons 2019 WEB/F-WEB-Goal-${oddNumber.padStart(2, '0')}.png` : ""
|
||||
};
|
||||
};
|
||||
|
||||
// Loading state
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="flex justify-center items-center min-h-screen bg-gray-50 pt-6">
|
||||
<div className="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-blue-600"></div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Error state if mission not found
|
||||
if (!mission) {
|
||||
return (
|
||||
<div className="flex justify-center items-center min-h-screen bg-gray-50 px-4 pt-6">
|
||||
<div className="text-center bg-white p-8 rounded-lg shadow-sm border border-gray-200 max-w-md">
|
||||
<h2 className="text-xl font-semibold text-gray-800 mb-2">Mission non trouvée</h2>
|
||||
<p className="text-gray-600 mb-6">Cette mission n'existe pas ou a été supprimée.</p>
|
||||
<Button
|
||||
onClick={() => router.push('/mission-tab')}
|
||||
className="bg-blue-600 hover:bg-blue-700 text-white"
|
||||
>
|
||||
Retour au tableau des missions
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const oddInfo = getODDInfo(mission.oddScope);
|
||||
|
||||
return (
|
||||
<div className="bg-gray-50 min-h-screen pt-6">
|
||||
<div className="max-w-screen-2xl mx-auto px-6">
|
||||
{/* Back Button */}
|
||||
<div className="mb-4">
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="flex items-center text-gray-600 hover:text-gray-900"
|
||||
onClick={() => router.push('/mission-tab')}
|
||||
>
|
||||
<ArrowLeft className="mr-2 h-4 w-4" />
|
||||
Retour au tableau des missions
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Page Title */}
|
||||
<div className="mb-6">
|
||||
<h1 className="text-3xl font-bold text-gray-900 mb-2">Détails de la Mission</h1>
|
||||
<div className="h-1 w-24 bg-blue-600 rounded-full"></div>
|
||||
</div>
|
||||
|
||||
{/* Header */}
|
||||
<div className="bg-white rounded-lg shadow-sm border border-gray-100 mb-6 p-6">
|
||||
<div className="flex justify-between items-start">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-gray-900 mb-2">{mission.name}</h1>
|
||||
<div className="flex items-center text-gray-500 text-sm gap-4">
|
||||
<div className="flex items-center">
|
||||
<Calendar className="h-4 w-4 mr-1" />
|
||||
{formatDate(mission.createdAt)}
|
||||
</div>
|
||||
<div className="flex items-center">
|
||||
<Eye className="h-4 w-4 mr-1" />
|
||||
{Math.floor(Math.random() * 100) + 1} Views
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Display logo */}
|
||||
<div className="w-24 h-24 rounded-md overflow-hidden flex-shrink-0">
|
||||
{mission.logoUrl ? (
|
||||
<img
|
||||
src={mission.logoUrl}
|
||||
alt={mission.name}
|
||||
className="w-full h-full object-cover rounded-md"
|
||||
onError={(e) => {
|
||||
console.log("Logo failed to load:", mission.logoUrl);
|
||||
// Show placeholder on error
|
||||
(e.currentTarget as HTMLImageElement).style.display = 'none';
|
||||
const parent = e.currentTarget.parentElement;
|
||||
if (parent) {
|
||||
parent.classList.add('bg-gray-100');
|
||||
parent.classList.add('flex');
|
||||
parent.classList.add('items-center');
|
||||
parent.classList.add('justify-center');
|
||||
parent.innerHTML = `<span class="text-2xl font-medium text-gray-400">${mission.name.slice(0, 2).toUpperCase()}</span>`;
|
||||
}
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<div className="w-full h-full bg-gray-100 flex items-center justify-center">
|
||||
<span className="text-2xl font-medium text-gray-400">{mission.name.slice(0, 2).toUpperCase()}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Info Grid */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mb-6">
|
||||
<div className="bg-white rounded-lg p-4 flex items-center shadow-sm border border-gray-100">
|
||||
<div className="bg-amber-50 p-3 rounded-full mr-3">
|
||||
<MapPin className="h-5 w-5 text-amber-600" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm text-gray-500 font-medium">Type de mission</p>
|
||||
<p className="text-gray-800 font-medium">{getMissionTypeLabel(mission.missionType)}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-lg p-4 flex items-center shadow-sm border border-gray-100">
|
||||
<div className="bg-blue-50 p-3 rounded-full mr-3">
|
||||
<Users className="h-5 w-5 text-blue-600" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm text-gray-500 font-medium">Donneur d'ordre</p>
|
||||
<p className="text-gray-800 font-medium">{mission.donneurDOrdre || "Non spécifié"}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-lg p-4 flex items-center shadow-sm border border-gray-100">
|
||||
<div className="bg-green-50 p-3 rounded-full mr-3">
|
||||
<Clock className="h-5 w-5 text-green-600" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm text-gray-500 font-medium">Durée</p>
|
||||
<p className="text-gray-800 font-medium">{getDurationLabel(mission.projection)}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-lg p-4 flex items-center shadow-sm border border-gray-100">
|
||||
<div className="bg-purple-50 p-3 rounded-full mr-3">
|
||||
<ThumbsUp className="h-5 w-5 text-purple-600" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm text-gray-500 font-medium">Niveau</p>
|
||||
<p className="text-gray-800 font-medium">{getNiveauLabel(mission.niveau)}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-lg p-4 flex items-center shadow-sm border border-gray-100">
|
||||
<div className="bg-indigo-50 p-3 rounded-full mr-3">
|
||||
<Languages className="h-5 w-5 text-indigo-600" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm text-gray-500 font-medium">Participation</p>
|
||||
<p className="text-gray-800 font-medium">{mission.participation || "Non spécifié"}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{oddInfo.number && (
|
||||
<div className="bg-white rounded-lg p-4 flex items-center shadow-sm border border-gray-100">
|
||||
<div className="bg-red-50 p-3 rounded-full mr-3 flex items-center justify-center">
|
||||
<img
|
||||
src={oddInfo.iconPath}
|
||||
alt={oddInfo.label}
|
||||
className="h-8 w-8"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm text-gray-500 font-medium">Objectif</p>
|
||||
<p className="text-gray-800 font-medium">Développement durable</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Project Description */}
|
||||
<div className="bg-white rounded-lg shadow-sm border border-gray-100 mb-6 p-6">
|
||||
<h2 className="text-xl font-semibold text-gray-800 mb-4">Description de la mission</h2>
|
||||
<div className="text-gray-700 whitespace-pre-wrap">
|
||||
{mission.intention || "Aucune description disponible pour cette mission."}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Attachments Section */}
|
||||
{mission.attachments && mission.attachments.length > 0 && (
|
||||
<div className="bg-white rounded-lg shadow-sm border border-gray-100 mb-6 p-6">
|
||||
<h2 className="text-xl font-semibold text-gray-800 mb-4">Documents</h2>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
|
||||
{mission.attachments.map((attachment) => (
|
||||
<a
|
||||
key={attachment.id}
|
||||
href={attachment.publicUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="bg-green-50 p-4 rounded-lg flex flex-col hover:bg-green-100 transition-colors"
|
||||
>
|
||||
<div className="text-green-700 mb-2">
|
||||
<FileIcon className="h-10 w-10" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="font-medium text-gray-800 mb-1 truncate">{attachment.filename}</p>
|
||||
<p className="text-sm text-gray-500">
|
||||
{attachment.fileType.split('/')[1]?.toUpperCase() || 'Fichier'}
|
||||
</p>
|
||||
</div>
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Skills Required Section */}
|
||||
{mission.profils && mission.profils.length > 0 && (
|
||||
<div className="bg-white rounded-lg shadow-sm border border-gray-100 mb-6 p-6">
|
||||
<h2 className="text-xl font-semibold text-gray-800 mb-4">Profils recherchés</h2>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{mission.profils.map((profil, index) => (
|
||||
<span
|
||||
key={index}
|
||||
className="bg-red-50 text-red-800 px-3 py-2 rounded-full text-sm"
|
||||
>
|
||||
{profil}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Services Section */}
|
||||
{mission.services && mission.services.length > 0 && (
|
||||
<div className="bg-white rounded-lg shadow-sm border border-gray-100 mb-6 p-6">
|
||||
<h2 className="text-xl font-semibold text-gray-800 mb-4">Services</h2>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{mission.services.map((service, index) => (
|
||||
<span
|
||||
key={index}
|
||||
className="bg-blue-50 text-blue-800 px-3 py-2 rounded-full text-sm"
|
||||
>
|
||||
{service}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Actions Footer */}
|
||||
<div className="bg-white rounded-lg shadow-sm border border-gray-100 mb-6 p-6 flex justify-between items-center">
|
||||
<Button
|
||||
variant="outline"
|
||||
className="text-gray-700 border-gray-300"
|
||||
onClick={() => router.push('/mission-tab')}
|
||||
>
|
||||
Retour au tableau
|
||||
</Button>
|
||||
|
||||
<Button className="bg-green-500 hover:bg-green-600 text-white px-6">
|
||||
Participer à la mission
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -125,10 +125,17 @@ export default function MissionTabPage() {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="w-full bg-white min-h-screen">
|
||||
<div className="bg-white border-b border-gray-100 py-4 px-6">
|
||||
<div className="w-full bg-white min-h-screen pt-6">
|
||||
{/* Page Title */}
|
||||
<div className="max-w-screen-2xl mx-auto px-6 mb-6">
|
||||
<h1 className="text-3xl font-bold text-gray-900 mb-2">Le Tableau des Missions</h1>
|
||||
<div className="h-1 w-24 bg-blue-600 rounded-full"></div>
|
||||
</div>
|
||||
|
||||
{/* Search Header */}
|
||||
<div className="max-w-screen-2xl mx-auto bg-white border border-gray-100 rounded-lg shadow-sm mb-6 py-4 px-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-gray-800 text-xl font-medium">Toutes les missions disponibles</h1>
|
||||
<h2 className="text-gray-800 text-lg font-medium">Toutes les missions disponibles</h2>
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-500" />
|
||||
<Input
|
||||
@ -141,7 +148,8 @@ export default function MissionTabPage() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="p-6 bg-gray-50">
|
||||
{/* Missions Grid */}
|
||||
<div className="max-w-screen-2xl mx-auto p-6 bg-gray-50 rounded-lg border border-gray-100 mb-6">
|
||||
{loading ? (
|
||||
<div className="flex justify-center items-center h-40">
|
||||
<div className="animate-spin rounded-full h-10 w-10 border-t-2 border-b-2 border-blue-600"></div>
|
||||
@ -237,7 +245,7 @@ export default function MissionTabPage() {
|
||||
Créée le {formatDate(mission.createdAt)}
|
||||
</span>
|
||||
|
||||
<Link href={`/missions/${mission.id}`}>
|
||||
<Link href={`/mission-tab/${mission.id}`}>
|
||||
<Button className="bg-blue-600 hover:bg-blue-700 text-white text-xs px-3 py-1 h-7 rounded-md">
|
||||
Voir détails
|
||||
</Button>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user