Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | 2x 2x 65x 65x 65x 65x 65x 65x 29x 5x 24x 65x 6x 6x 5x 65x 63x 7x | import { useState, useEffect } from 'react';
import { CreateLieuRequest } from '@/lib/api/services/evenementSports/lieuService';
import { Lieu } from '@/types/sportEvenement/lieu';
interface Props {
isOpen: boolean;
onClose: () => void;
onSave: (lieuData: CreateLieuRequest) => void;
loading: boolean;
error: string | null;
lieu?: Lieu;
}
export default function LieuModal({
isOpen,
onClose,
onSave,
loading,
error,
lieu
}: Props) {
const [formData, setFormData] = useState<CreateLieuRequest>({
nom: ''
});
// Déterminer si c'est une création ou une modification
const isEditing = Boolean(lieu);
const title = isEditing ? 'Modifier le lieu' : 'Créer un nouveau lieu';
const submitLabel = isEditing ? 'Modifier' : 'Créer';
const loadingLabel = isEditing ? 'Modification...' : 'Création...';
// Initialiser le formulaire avec les données du lieu en mode édition
useEffect(() => {
if (lieu) {
setFormData({
nom: lieu.nom
});
} else {
setFormData({
nom: ''
});
}
}, [lieu]);
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (formData.nom.trim()) {
onSave(formData);
}
};
if (!isOpen) return null;
return (
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
<div className="bg-white rounded-lg p-6 w-full max-w-md mx-4">
<div className="flex items-center justify-center mb-4" style={{ minHeight: '3rem' }}>
<h3 className="text-lg text-black font-semibold">{title}</h3>
</div>
{error && (
<div className="mb-4 text-sm text-red-600 bg-red-50 p-2 rounded">
{error}
</div>
)}
<form onSubmit={handleSubmit} className="space-y-4">
<div>
<input
type="text"
value={formData.nom}
onChange={(e) => setFormData({ ...formData, nom: e.target.value })}
className="w-full px-3 py-2 border border-gray-300 text-black rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
placeholder="Ex: Stade de France"
required
/>
</div>
<div className="flex justify-end space-x-3 pt-4">
<button
type="button"
onClick={onClose}
className="px-4 py-2 text-sm font-medium text-gray-700 bg-gray-200 rounded-md hover:bg-gray-300"
disabled={loading}
>
Annuler
</button>
<button
type="submit"
className="px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-md hover:bg-blue-700 disabled:bg-blue-300"
disabled={loading}
>
{loading ? loadingLabel : submitLabel}
</button>
</div>
</form>
</div>
</div>
);
}
|