2026-01-21 17:34:48 +01:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { useState, useEffect, useRef } from 'react';
|
|
|
|
|
import TrajetMap from './TrajetMap';
|
|
|
|
|
import AddressAutocomplete from './AddressAutocomplete';
|
2026-01-21 18:13:35 +01:00
|
|
|
import { useNotification } from './NotificationProvider';
|
2026-01-21 17:34:48 +01:00
|
|
|
|
|
|
|
|
interface Adherent {
|
|
|
|
|
id: string;
|
|
|
|
|
nom: string;
|
|
|
|
|
prenom: string;
|
|
|
|
|
adresse: string;
|
|
|
|
|
telephone: string;
|
|
|
|
|
email: string;
|
2026-01-22 19:25:25 +01:00
|
|
|
commentaire?: string | null;
|
|
|
|
|
telephoneSecondaire?: string | null;
|
|
|
|
|
instructions?: string | null;
|
|
|
|
|
situation?: string | null;
|
|
|
|
|
prescripteur?: string | null;
|
|
|
|
|
facturation?: string | null;
|
|
|
|
|
forfait?: string | null;
|
2026-01-21 17:34:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface Chauffeur {
|
|
|
|
|
id: string;
|
|
|
|
|
nom: string;
|
|
|
|
|
prenom: string;
|
|
|
|
|
telephone: string;
|
|
|
|
|
email: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface TrajetFormProps {
|
|
|
|
|
onClose: () => void;
|
|
|
|
|
onSuccess: () => void;
|
2026-01-21 17:48:14 +01:00
|
|
|
trajetToEdit?: {
|
|
|
|
|
id: string;
|
|
|
|
|
date: string;
|
|
|
|
|
adresseDepart: string;
|
|
|
|
|
adresseArrivee: string;
|
|
|
|
|
commentaire?: string | null;
|
2026-01-22 19:25:25 +01:00
|
|
|
instructions?: string | null;
|
2026-01-21 17:48:14 +01:00
|
|
|
statut: string;
|
|
|
|
|
adherentId: string;
|
|
|
|
|
chauffeurId?: string | null;
|
|
|
|
|
};
|
2026-01-21 17:34:48 +01:00
|
|
|
}
|
|
|
|
|
|
2026-01-21 17:48:14 +01:00
|
|
|
export default function TrajetForm({ onClose, onSuccess, trajetToEdit }: TrajetFormProps) {
|
2026-01-21 18:13:35 +01:00
|
|
|
const { showNotification } = useNotification();
|
2026-01-21 17:34:48 +01:00
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
|
const [adherents, setAdherents] = useState<Adherent[]>([]);
|
|
|
|
|
const [chauffeurs, setChauffeurs] = useState<Chauffeur[]>([]);
|
|
|
|
|
const [searchAdherent, setSearchAdherent] = useState('');
|
|
|
|
|
const [searchChauffeur, setSearchChauffeur] = useState('');
|
|
|
|
|
const [showAdherentDropdown, setShowAdherentDropdown] = useState(false);
|
|
|
|
|
const [showChauffeurDropdown, setShowChauffeurDropdown] = useState(false);
|
|
|
|
|
const adherentDropdownRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
const chauffeurDropdownRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
|
|
|
|
const [formData, setFormData] = useState({
|
2026-01-21 17:48:14 +01:00
|
|
|
adherentId: trajetToEdit?.adherentId || '',
|
2026-01-21 17:34:48 +01:00
|
|
|
adherentNom: '',
|
|
|
|
|
adherentPrenom: '',
|
|
|
|
|
adherentAdresse: '',
|
|
|
|
|
adherentTelephone: '',
|
2026-01-22 19:25:25 +01:00
|
|
|
adherentTelephoneSecondaire: '',
|
|
|
|
|
adherentEmail: '',
|
|
|
|
|
adherentForfait: '',
|
2026-01-21 17:48:14 +01:00
|
|
|
chauffeurId: trajetToEdit?.chauffeurId || '',
|
2026-01-21 17:34:48 +01:00
|
|
|
chauffeurNom: '',
|
|
|
|
|
chauffeurPrenom: '',
|
|
|
|
|
chauffeurTelephone: '',
|
2026-01-21 17:48:14 +01:00
|
|
|
date: trajetToEdit ? new Date(trajetToEdit.date).toISOString().split('T')[0] : '',
|
|
|
|
|
heure: trajetToEdit ? new Date(trajetToEdit.date).toTimeString().slice(0, 5) : '',
|
|
|
|
|
adresseDepart: trajetToEdit?.adresseDepart || '',
|
|
|
|
|
adresseArrivee: trajetToEdit?.adresseArrivee || '',
|
|
|
|
|
commentaire: trajetToEdit?.commentaire || '',
|
2026-01-22 19:25:25 +01:00
|
|
|
instructions: trajetToEdit?.instructions || '',
|
2026-01-21 17:34:48 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
fetchAdherents();
|
|
|
|
|
fetchChauffeurs();
|
|
|
|
|
}, []);
|
|
|
|
|
|
2026-01-21 17:48:14 +01:00
|
|
|
useEffect(() => {
|
|
|
|
|
// Si on modifie un trajet, charger les données de l'adhérent et du chauffeur
|
|
|
|
|
if (trajetToEdit) {
|
|
|
|
|
if (trajetToEdit.adherentId) {
|
|
|
|
|
fetch(`/api/adherents/${trajetToEdit.adherentId}`)
|
|
|
|
|
.then(res => res.json())
|
|
|
|
|
.then(data => {
|
|
|
|
|
if (data) {
|
2026-01-22 19:25:25 +01:00
|
|
|
// Construire le commentaire avec toutes les informations pertinentes
|
|
|
|
|
const commentaireParts: string[] = [];
|
|
|
|
|
|
|
|
|
|
if (data.commentaire) {
|
|
|
|
|
commentaireParts.push(`Commentaire adhérent: ${data.commentaire}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.instructions) {
|
|
|
|
|
commentaireParts.push(`Instructions: ${data.instructions}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.telephoneSecondaire) {
|
|
|
|
|
commentaireParts.push(`Téléphone secondaire: ${data.telephoneSecondaire}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.situation) {
|
|
|
|
|
commentaireParts.push(`Situation: ${data.situation}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.prescripteur) {
|
|
|
|
|
commentaireParts.push(`Prescripteur: ${data.prescripteur}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.facturation) {
|
|
|
|
|
commentaireParts.push(`Facturation: ${data.facturation}`);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-21 17:48:14 +01:00
|
|
|
setFormData(prev => ({
|
|
|
|
|
...prev,
|
|
|
|
|
adherentId: data.id,
|
|
|
|
|
adherentNom: data.nom,
|
|
|
|
|
adherentPrenom: data.prenom,
|
|
|
|
|
adherentAdresse: data.adresse,
|
|
|
|
|
adherentTelephone: data.telephone,
|
2026-01-22 19:25:25 +01:00
|
|
|
adherentTelephoneSecondaire: data.telephoneSecondaire || '',
|
|
|
|
|
adherentEmail: data.email,
|
|
|
|
|
adherentForfait: data.forfait || '',
|
2026-01-21 17:48:14 +01:00
|
|
|
adresseDepart: data.adresse,
|
2026-01-22 19:25:25 +01:00
|
|
|
commentaire: data.commentaire || prev.commentaire || trajetToEdit.commentaire || '',
|
|
|
|
|
instructions: data.instructions || prev.instructions || trajetToEdit.instructions || '',
|
2026-01-21 17:48:14 +01:00
|
|
|
}));
|
|
|
|
|
setSearchAdherent(`${data.prenom} ${data.nom}`);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(console.error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (trajetToEdit.chauffeurId) {
|
|
|
|
|
fetch(`/api/chauffeurs/${trajetToEdit.chauffeurId}`)
|
|
|
|
|
.then(res => res.json())
|
|
|
|
|
.then(data => {
|
|
|
|
|
if (data) {
|
|
|
|
|
setFormData(prev => ({
|
|
|
|
|
...prev,
|
|
|
|
|
chauffeurId: data.id,
|
|
|
|
|
chauffeurNom: data.nom,
|
|
|
|
|
chauffeurPrenom: data.prenom,
|
|
|
|
|
chauffeurTelephone: data.telephone,
|
|
|
|
|
}));
|
|
|
|
|
setSearchChauffeur(`${data.prenom} ${data.nom}`);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(console.error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, [trajetToEdit]);
|
|
|
|
|
|
2026-01-21 17:34:48 +01:00
|
|
|
// Fermer les dropdowns quand on clique en dehors
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const handleClickOutside = (event: MouseEvent) => {
|
|
|
|
|
if (
|
|
|
|
|
adherentDropdownRef.current &&
|
|
|
|
|
!adherentDropdownRef.current.contains(event.target as Node)
|
|
|
|
|
) {
|
|
|
|
|
setShowAdherentDropdown(false);
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
chauffeurDropdownRef.current &&
|
|
|
|
|
!chauffeurDropdownRef.current.contains(event.target as Node)
|
|
|
|
|
) {
|
|
|
|
|
setShowChauffeurDropdown(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
document.addEventListener('mousedown', handleClickOutside);
|
|
|
|
|
return () => {
|
|
|
|
|
document.removeEventListener('mousedown', handleClickOutside);
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const fetchAdherents = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch('/api/adherents');
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
setAdherents(data);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Erreur lors du chargement des adhérents:', error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const fetchChauffeurs = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch('/api/chauffeurs');
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
setChauffeurs(data);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Erreur lors du chargement des chauffeurs:', error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-22 19:25:25 +01:00
|
|
|
const handleSelectAdherent = async (adherent: Adherent) => {
|
|
|
|
|
// Charger toutes les informations complètes de l'adhérent depuis l'API
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`/api/adherents/${adherent.id}`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const fullAdherent = await response.json();
|
|
|
|
|
|
|
|
|
|
setFormData({
|
|
|
|
|
...formData,
|
|
|
|
|
adherentId: fullAdherent.id,
|
|
|
|
|
adherentNom: fullAdherent.nom,
|
|
|
|
|
adherentPrenom: fullAdherent.prenom,
|
|
|
|
|
adherentAdresse: fullAdherent.adresse,
|
|
|
|
|
adherentTelephone: fullAdherent.telephone,
|
|
|
|
|
adherentTelephoneSecondaire: fullAdherent.telephoneSecondaire || '',
|
|
|
|
|
adherentEmail: fullAdherent.email,
|
|
|
|
|
adherentForfait: fullAdherent.forfait || '',
|
|
|
|
|
adresseDepart: fullAdherent.adresse, // Remplir automatiquement l'adresse de départ
|
|
|
|
|
commentaire: fullAdherent.commentaire || formData.commentaire || '', // Prendre uniquement le commentaire de l'adhérent
|
|
|
|
|
instructions: fullAdherent.instructions || formData.instructions || '', // Pré-remplir les instructions
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// Si l'API échoue, utiliser les données de base
|
|
|
|
|
setFormData({
|
|
|
|
|
...formData,
|
|
|
|
|
adherentId: adherent.id,
|
|
|
|
|
adherentNom: adherent.nom,
|
|
|
|
|
adherentPrenom: adherent.prenom,
|
|
|
|
|
adherentAdresse: adherent.adresse,
|
|
|
|
|
adherentTelephone: adherent.telephone,
|
|
|
|
|
adresseDepart: adherent.adresse,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Erreur lors du chargement des détails de l\'adhérent:', error);
|
|
|
|
|
// En cas d'erreur, utiliser les données de base
|
|
|
|
|
setFormData({
|
|
|
|
|
...formData,
|
|
|
|
|
adherentId: adherent.id,
|
|
|
|
|
adherentNom: adherent.nom,
|
|
|
|
|
adherentPrenom: adherent.prenom,
|
|
|
|
|
adherentAdresse: adherent.adresse,
|
|
|
|
|
adherentTelephone: adherent.telephone,
|
|
|
|
|
adresseDepart: adherent.adresse,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-21 17:34:48 +01:00
|
|
|
setSearchAdherent(`${adherent.prenom} ${adherent.nom}`);
|
|
|
|
|
setShowAdherentDropdown(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleSelectChauffeur = (chauffeur: Chauffeur) => {
|
|
|
|
|
setFormData({
|
|
|
|
|
...formData,
|
|
|
|
|
chauffeurId: chauffeur.id,
|
|
|
|
|
chauffeurNom: chauffeur.nom,
|
|
|
|
|
chauffeurPrenom: chauffeur.prenom,
|
|
|
|
|
chauffeurTelephone: chauffeur.telephone,
|
|
|
|
|
});
|
|
|
|
|
setSearchChauffeur(`${chauffeur.prenom} ${chauffeur.nom}`);
|
|
|
|
|
setShowChauffeurDropdown(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const filteredAdherents = adherents.filter(
|
|
|
|
|
(a) =>
|
|
|
|
|
!searchAdherent ||
|
|
|
|
|
`${a.prenom} ${a.nom}`.toLowerCase().includes(searchAdherent.toLowerCase()) ||
|
|
|
|
|
a.email.toLowerCase().includes(searchAdherent.toLowerCase()) ||
|
|
|
|
|
a.telephone.includes(searchAdherent)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const filteredChauffeurs = chauffeurs.filter(
|
|
|
|
|
(c) =>
|
|
|
|
|
!searchChauffeur ||
|
|
|
|
|
`${c.prenom} ${c.nom}`.toLowerCase().includes(searchChauffeur.toLowerCase()) ||
|
|
|
|
|
c.email.toLowerCase().includes(searchChauffeur.toLowerCase()) ||
|
|
|
|
|
c.telephone.includes(searchChauffeur)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const handleSubmit = async (e: React.FormEvent) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
setLoading(true);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// Combiner date et heure
|
|
|
|
|
const dateTime = formData.date && formData.heure
|
|
|
|
|
? new Date(`${formData.date}T${formData.heure}`).toISOString()
|
|
|
|
|
: formData.date
|
|
|
|
|
? new Date(`${formData.date}T09:00`).toISOString()
|
|
|
|
|
: new Date().toISOString();
|
|
|
|
|
|
2026-01-21 17:48:14 +01:00
|
|
|
const url = trajetToEdit ? `/api/trajets/${trajetToEdit.id}` : '/api/trajets';
|
|
|
|
|
const method = trajetToEdit ? 'PUT' : 'POST';
|
|
|
|
|
|
|
|
|
|
const response = await fetch(url, {
|
|
|
|
|
method,
|
2026-01-21 17:34:48 +01:00
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
date: dateTime,
|
|
|
|
|
adresseDepart: formData.adresseDepart,
|
|
|
|
|
adresseArrivee: formData.adresseArrivee,
|
|
|
|
|
commentaire: formData.commentaire || null,
|
2026-01-22 19:25:25 +01:00
|
|
|
instructions: formData.instructions || null,
|
2026-01-21 17:48:14 +01:00
|
|
|
statut: trajetToEdit?.statut || 'Planifié',
|
2026-01-21 17:34:48 +01:00
|
|
|
adherentId: formData.adherentId,
|
|
|
|
|
chauffeurId: formData.chauffeurId || null,
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
2026-01-21 18:13:35 +01:00
|
|
|
showNotification(
|
|
|
|
|
'success',
|
|
|
|
|
trajetToEdit ? 'Trajet modifié avec succès' : 'Trajet créé avec succès'
|
|
|
|
|
);
|
2026-01-21 17:34:48 +01:00
|
|
|
onSuccess();
|
|
|
|
|
onClose();
|
|
|
|
|
} else {
|
|
|
|
|
const error = await response.json();
|
2026-01-21 18:13:35 +01:00
|
|
|
showNotification('error', error.error || `Erreur lors de la ${trajetToEdit ? 'modification' : 'création'} du trajet`);
|
2026-01-21 17:34:48 +01:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
2026-01-21 17:48:14 +01:00
|
|
|
console.error(`Erreur lors de la ${trajetToEdit ? 'modification' : 'création'} du trajet:`, error);
|
2026-01-21 18:13:35 +01:00
|
|
|
showNotification('error', `Erreur lors de la ${trajetToEdit ? 'modification' : 'création'} du trajet`);
|
2026-01-21 17:34:48 +01:00
|
|
|
} finally {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getInitials = (nom: string, prenom: string) => {
|
|
|
|
|
return `${prenom.charAt(0)}${nom.charAt(0)}`.toUpperCase();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4 animate-fadeIn">
|
|
|
|
|
<div className="bg-white rounded-lg shadow-xl max-w-7xl w-full max-h-[95vh] overflow-hidden flex flex-col animate-slideUp border border-gray-200">
|
|
|
|
|
{/* Header */}
|
|
|
|
|
<div className="border-b border-gray-200 px-6 py-5 bg-white">
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<div>
|
2026-01-21 17:48:14 +01:00
|
|
|
<h2 className="text-2xl font-semibold text-gray-900">
|
|
|
|
|
{trajetToEdit ? 'Modifier le trajet' : 'Nouveau trajet'}
|
|
|
|
|
</h2>
|
|
|
|
|
<p className="text-sm text-gray-500 mt-1">
|
|
|
|
|
{trajetToEdit ? 'Modifiez les informations du trajet' : 'Créez un nouveau trajet pour un adhérent'}
|
|
|
|
|
</p>
|
2026-01-21 17:34:48 +01:00
|
|
|
</div>
|
|
|
|
|
<button
|
|
|
|
|
onClick={onClose}
|
|
|
|
|
className="text-gray-400 hover:text-gray-600 transition-colors p-2 hover:bg-gray-100 rounded-lg"
|
|
|
|
|
>
|
|
|
|
|
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
|
|
|
|
</svg>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Content */}
|
|
|
|
|
<form id="trajet-form" onSubmit={handleSubmit} className="flex-1 overflow-hidden flex">
|
|
|
|
|
{/* Colonne gauche - Formulaire */}
|
|
|
|
|
<div className="flex-1 overflow-y-auto px-8 py-8 border-r border-gray-200">
|
|
|
|
|
<div className="space-y-6">
|
|
|
|
|
{/* Sélection adhérent */}
|
|
|
|
|
<div>
|
|
|
|
|
<label className="block text-sm font-semibold text-gray-900 mb-2">
|
|
|
|
|
Adhérent <span className="text-red-500">*</span>
|
|
|
|
|
</label>
|
|
|
|
|
<div className="relative" ref={adherentDropdownRef}>
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
placeholder="Rechercher un adhérent..."
|
|
|
|
|
value={searchAdherent}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
setSearchAdherent(e.target.value);
|
|
|
|
|
setShowAdherentDropdown(true);
|
|
|
|
|
}}
|
|
|
|
|
onFocus={() => setShowAdherentDropdown(true)}
|
|
|
|
|
className="w-full px-4 py-2.5 border border-gray-300 rounded-lg text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-lblue focus:border-transparent"
|
|
|
|
|
/>
|
|
|
|
|
{showAdherentDropdown && filteredAdherents.length > 0 && (
|
|
|
|
|
<div className="absolute z-10 w-full mt-1 bg-white border border-gray-200 rounded-lg shadow-lg max-h-60 overflow-y-auto">
|
|
|
|
|
{filteredAdherents.map((adherent) => (
|
|
|
|
|
<button
|
|
|
|
|
key={adherent.id}
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => handleSelectAdherent(adherent)}
|
|
|
|
|
className="w-full px-4 py-3 text-left hover:bg-gray-50 flex items-center gap-3 border-b border-gray-100 last:border-b-0"
|
|
|
|
|
>
|
|
|
|
|
<div className="w-10 h-10 rounded-full bg-lgreen flex items-center justify-center text-white font-semibold text-sm">
|
|
|
|
|
{getInitials(adherent.nom, adherent.prenom)}
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<div className="text-sm font-medium text-gray-900">
|
|
|
|
|
{adherent.prenom} {adherent.nom}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-xs text-gray-500">{adherent.email}</div>
|
|
|
|
|
</div>
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
{formData.adherentId && (
|
2026-01-22 19:25:25 +01:00
|
|
|
<div className="mt-3 p-4 bg-gray-50 rounded-lg border border-gray-200 space-y-3">
|
2026-01-21 17:34:48 +01:00
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<div className="w-10 h-10 rounded-full bg-lgreen flex items-center justify-center text-white font-semibold text-sm">
|
|
|
|
|
{getInitials(formData.adherentNom, formData.adherentPrenom)}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex-1">
|
|
|
|
|
<div className="text-sm font-medium text-gray-900">
|
|
|
|
|
{formData.adherentPrenom} {formData.adherentNom}
|
|
|
|
|
</div>
|
2026-01-22 19:25:25 +01:00
|
|
|
<div className="text-xs text-gray-500">{formData.adherentAdresse}</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="grid grid-cols-1 gap-2 pt-2 border-t border-gray-200">
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<svg className="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z" />
|
|
|
|
|
</svg>
|
|
|
|
|
<span className="text-xs text-gray-600">{formData.adherentTelephone}</span>
|
|
|
|
|
</div>
|
|
|
|
|
{formData.adherentTelephoneSecondaire && (
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<svg className="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z" />
|
|
|
|
|
</svg>
|
|
|
|
|
<span className="text-xs text-gray-600">Secondaire: {formData.adherentTelephoneSecondaire}</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<svg className="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
|
|
|
|
|
</svg>
|
|
|
|
|
<span className="text-xs text-gray-600">{formData.adherentEmail}</span>
|
2026-01-21 17:34:48 +01:00
|
|
|
</div>
|
2026-01-22 19:25:25 +01:00
|
|
|
{formData.adherentForfait && (
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<svg className="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
|
|
|
</svg>
|
|
|
|
|
<span className="text-xs font-semibold text-lgreen">Forfait: {formData.adherentForfait} €</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-01-21 17:34:48 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Sélection chauffeur */}
|
|
|
|
|
<div>
|
|
|
|
|
<label className="block text-sm font-semibold text-gray-900 mb-2">
|
|
|
|
|
Chauffeur
|
|
|
|
|
</label>
|
|
|
|
|
<div className="relative" ref={chauffeurDropdownRef}>
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
placeholder="Rechercher un chauffeur..."
|
|
|
|
|
value={searchChauffeur}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
setSearchChauffeur(e.target.value);
|
|
|
|
|
setShowChauffeurDropdown(true);
|
|
|
|
|
}}
|
|
|
|
|
onFocus={() => setShowChauffeurDropdown(true)}
|
|
|
|
|
className="w-full px-4 py-2.5 border border-gray-300 rounded-lg text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-lblue focus:border-transparent"
|
|
|
|
|
/>
|
|
|
|
|
{showChauffeurDropdown && filteredChauffeurs.length > 0 && (
|
|
|
|
|
<div className="absolute z-10 w-full mt-1 bg-white border border-gray-200 rounded-lg shadow-lg max-h-60 overflow-y-auto">
|
|
|
|
|
{filteredChauffeurs.map((chauffeur) => (
|
|
|
|
|
<button
|
|
|
|
|
key={chauffeur.id}
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => handleSelectChauffeur(chauffeur)}
|
|
|
|
|
className="w-full px-4 py-3 text-left hover:bg-gray-50 flex items-center gap-3 border-b border-gray-100 last:border-b-0"
|
|
|
|
|
>
|
|
|
|
|
<div className="w-10 h-10 rounded-full bg-lblue flex items-center justify-center text-white font-semibold text-sm">
|
|
|
|
|
{getInitials(chauffeur.nom, chauffeur.prenom)}
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<div className="text-sm font-medium text-gray-900">
|
|
|
|
|
{chauffeur.prenom} {chauffeur.nom}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-xs text-gray-500">{chauffeur.email}</div>
|
|
|
|
|
</div>
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
{formData.chauffeurId && (
|
|
|
|
|
<div className="mt-3 p-3 bg-gray-50 rounded-lg border border-gray-200">
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<div className="w-10 h-10 rounded-full bg-lblue flex items-center justify-center text-white font-semibold text-sm">
|
|
|
|
|
{getInitials(formData.chauffeurNom, formData.chauffeurPrenom)}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex-1">
|
|
|
|
|
<div className="text-sm font-medium text-gray-900">
|
|
|
|
|
{formData.chauffeurPrenom} {formData.chauffeurNom}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-xs text-gray-500">{formData.chauffeurTelephone}</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Date et heure */}
|
|
|
|
|
<div className="grid grid-cols-2 gap-4">
|
|
|
|
|
<div>
|
|
|
|
|
<label className="block text-sm font-semibold text-gray-900 mb-2">
|
|
|
|
|
Date <span className="text-red-500">*</span>
|
|
|
|
|
</label>
|
|
|
|
|
<input
|
|
|
|
|
type="date"
|
|
|
|
|
required
|
|
|
|
|
value={formData.date}
|
|
|
|
|
onChange={(e) => setFormData({ ...formData, date: e.target.value })}
|
|
|
|
|
className="w-full px-4 py-2.5 border border-gray-300 rounded-lg text-gray-900 focus:outline-none focus:ring-2 focus:ring-lblue focus:border-transparent"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label className="block text-sm font-semibold text-gray-900 mb-2">
|
|
|
|
|
Heure <span className="text-red-500">*</span>
|
|
|
|
|
</label>
|
|
|
|
|
<input
|
|
|
|
|
type="time"
|
|
|
|
|
required
|
|
|
|
|
value={formData.heure}
|
|
|
|
|
onChange={(e) => setFormData({ ...formData, heure: e.target.value })}
|
|
|
|
|
className="w-full px-4 py-2.5 border border-gray-300 rounded-lg text-gray-900 focus:outline-none focus:ring-2 focus:ring-lblue focus:border-transparent"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Adresse de départ */}
|
|
|
|
|
<div>
|
|
|
|
|
<label className="block text-sm font-semibold text-gray-900 mb-2">
|
|
|
|
|
Adresse de départ <span className="text-red-500">*</span>
|
|
|
|
|
</label>
|
|
|
|
|
<AddressAutocomplete
|
|
|
|
|
value={formData.adresseDepart}
|
|
|
|
|
onChange={(address) => setFormData({ ...formData, adresseDepart: address })}
|
|
|
|
|
placeholder="Rechercher une adresse de départ..."
|
|
|
|
|
required
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Adresse d'arrivée */}
|
|
|
|
|
<div>
|
|
|
|
|
<label className="block text-sm font-semibold text-gray-900 mb-2">
|
|
|
|
|
Adresse d'arrivée <span className="text-red-500">*</span>
|
|
|
|
|
</label>
|
|
|
|
|
<AddressAutocomplete
|
|
|
|
|
value={formData.adresseArrivee}
|
|
|
|
|
onChange={(address) => setFormData({ ...formData, adresseArrivee: address })}
|
|
|
|
|
placeholder="Rechercher une adresse d'arrivée..."
|
|
|
|
|
required
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-01-22 19:25:25 +01:00
|
|
|
{/* Instructions */}
|
|
|
|
|
<div>
|
|
|
|
|
<label className="block text-sm font-semibold text-gray-900 mb-2">
|
|
|
|
|
Instructions
|
|
|
|
|
{formData.adherentId && (
|
|
|
|
|
<span className="ml-2 text-xs font-normal text-gray-500">
|
|
|
|
|
(pré-rempli depuis la fiche adhérent)
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</label>
|
|
|
|
|
<textarea
|
|
|
|
|
value={formData.instructions}
|
|
|
|
|
onChange={(e) => setFormData({ ...formData, instructions: e.target.value })}
|
|
|
|
|
placeholder="Instructions pour ce trajet... Les instructions de la fiche adhérent seront automatiquement ajoutées lors de la sélection."
|
|
|
|
|
rows={4}
|
|
|
|
|
className="w-full px-4 py-2.5 border border-gray-300 rounded-lg text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-lblue focus:border-transparent resize-none"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-01-21 17:34:48 +01:00
|
|
|
{/* Commentaire */}
|
|
|
|
|
<div>
|
|
|
|
|
<label className="block text-sm font-semibold text-gray-900 mb-2">
|
|
|
|
|
Commentaire
|
2026-01-22 19:25:25 +01:00
|
|
|
{formData.adherentId && (
|
|
|
|
|
<span className="ml-2 text-xs font-normal text-gray-500">
|
|
|
|
|
(pré-rempli depuis la fiche adhérent)
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2026-01-21 17:34:48 +01:00
|
|
|
</label>
|
|
|
|
|
<textarea
|
|
|
|
|
value={formData.commentaire}
|
|
|
|
|
onChange={(e) => setFormData({ ...formData, commentaire: e.target.value })}
|
2026-01-22 19:25:25 +01:00
|
|
|
placeholder="Commentaire optionnel... Le commentaire de la fiche adhérent sera automatiquement ajouté lors de la sélection."
|
2026-01-21 17:34:48 +01:00
|
|
|
rows={4}
|
|
|
|
|
className="w-full px-4 py-2.5 border border-gray-300 rounded-lg text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-lblue focus:border-transparent resize-none"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Colonne droite - Carte */}
|
|
|
|
|
<div className="w-[700px] bg-gradient-to-br from-gray-50 to-gray-100 border-l border-gray-200 p-6 flex flex-col">
|
|
|
|
|
<h3 className="text-xl font-semibold text-gray-900 mb-6">Aperçu du trajet</h3>
|
|
|
|
|
|
|
|
|
|
<div className="flex-1 min-h-[600px] rounded-xl overflow-hidden shadow-lg">
|
|
|
|
|
<TrajetMap
|
|
|
|
|
adresseDepart={formData.adresseDepart}
|
|
|
|
|
adresseArrivee={formData.adresseArrivee}
|
|
|
|
|
adherentNom={formData.adherentId ? `${formData.adherentPrenom} ${formData.adherentNom}` : undefined}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Informations supplémentaires */}
|
2026-01-22 19:25:25 +01:00
|
|
|
{(formData.date || formData.heure || formData.chauffeurId || formData.instructions || formData.commentaire) && (
|
2026-01-21 17:34:48 +01:00
|
|
|
<div className="mt-4 bg-white rounded-lg p-4 border border-gray-200 space-y-3">
|
|
|
|
|
{formData.date && (
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<svg className="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" />
|
|
|
|
|
</svg>
|
|
|
|
|
<span className="text-sm text-gray-900">
|
|
|
|
|
{new Date(formData.date).toLocaleDateString('fr-FR', {
|
|
|
|
|
weekday: 'long',
|
|
|
|
|
day: 'numeric',
|
|
|
|
|
month: 'long',
|
|
|
|
|
year: 'numeric',
|
|
|
|
|
})}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{formData.heure && (
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<svg className="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
|
|
|
</svg>
|
|
|
|
|
<span className="text-sm text-gray-900">{formData.heure}</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{formData.chauffeurId && (
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<svg className="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 17a2 2 0 11-4 0 2 2 0 014 0zM19 17a2 2 0 11-4 0 2 2 0 014 0z" />
|
|
|
|
|
</svg>
|
|
|
|
|
<span className="text-sm text-gray-900">
|
|
|
|
|
{formData.chauffeurPrenom} {formData.chauffeurNom}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-01-22 19:25:25 +01:00
|
|
|
{formData.instructions && (
|
|
|
|
|
<div className="pt-3 border-t border-gray-200">
|
|
|
|
|
<div className="text-xs font-semibold text-gray-500 uppercase mb-1">Instructions</div>
|
|
|
|
|
<p className="text-sm text-gray-700 whitespace-pre-line">{formData.instructions}</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-01-21 17:34:48 +01:00
|
|
|
{formData.commentaire && (
|
|
|
|
|
<div className="pt-3 border-t border-gray-200">
|
|
|
|
|
<div className="text-xs font-semibold text-gray-500 uppercase mb-1">Commentaire</div>
|
2026-01-22 19:25:25 +01:00
|
|
|
<p className="text-sm text-gray-700 whitespace-pre-line">{formData.commentaire}</p>
|
2026-01-21 17:34:48 +01:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
{/* Footer */}
|
|
|
|
|
<div className="border-t border-gray-200 px-6 py-4 bg-gray-50/50">
|
|
|
|
|
<div className="flex justify-end gap-3">
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={onClose}
|
|
|
|
|
className="px-4 py-2 text-sm font-medium text-gray-700 hover:text-gray-900 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
Annuler
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
type="submit"
|
|
|
|
|
form="trajet-form"
|
|
|
|
|
disabled={loading || !formData.adherentId || !formData.date || !formData.adresseDepart || !formData.adresseArrivee}
|
|
|
|
|
className="px-6 py-2 bg-lgreen text-white text-sm font-medium rounded-lg hover:bg-dgreen transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2"
|
|
|
|
|
>
|
|
|
|
|
{loading ? (
|
|
|
|
|
<>
|
|
|
|
|
<svg className="animate-spin h-4 w-4" fill="none" viewBox="0 0 24 24">
|
|
|
|
|
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
|
|
|
|
|
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
|
|
|
|
</svg>
|
2026-01-21 17:48:14 +01:00
|
|
|
{trajetToEdit ? 'Modification...' : 'Création...'}
|
2026-01-21 17:34:48 +01:00
|
|
|
</>
|
|
|
|
|
) : (
|
2026-01-21 17:48:14 +01:00
|
|
|
trajetToEdit ? 'Modifier le trajet' : 'Créer le trajet'
|
2026-01-21 17:34:48 +01:00
|
|
|
)}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|