initial commit

This commit is contained in:
Yannick Le Duc
2025-08-25 14:38:13 +02:00
parent 02197190e9
commit e0f86a8845
25 changed files with 3336 additions and 128 deletions

View File

@@ -0,0 +1,141 @@
'use client';
import { useState, useEffect } from 'react';
import { Dialog } from '@headlessui/react';
import { XMarkIcon } from '@heroicons/react/24/outline';
import { propositionService } from '@/lib/services';
import { Proposition } from '@/types';
interface EditPropositionModalProps {
isOpen: boolean;
onClose: () => void;
onSuccess: () => void;
proposition: Proposition;
}
export default function EditPropositionModal({
isOpen,
onClose,
onSuccess,
proposition
}: EditPropositionModalProps) {
const [formData, setFormData] = useState({
title: '',
description: ''
});
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
// Initialiser le formulaire avec les données de la proposition
useEffect(() => {
if (proposition) {
setFormData({
title: proposition.title,
description: proposition.description
});
}
}, [proposition]);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
setError('');
try {
await propositionService.update(proposition.id, formData);
onSuccess();
} catch (err: any) {
const errorMessage = err?.message || err?.details || 'Erreur lors de la modification de la proposition';
setError(`Erreur lors de la modification de la proposition: ${errorMessage}`);
} finally {
setLoading(false);
}
};
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
const { name, value } = e.target;
setFormData(prev => ({
...prev,
[name]: value
}));
};
return (
<Dialog open={isOpen} onClose={onClose} className="relative z-50">
<div className="fixed inset-0 bg-black/30" aria-hidden="true" />
<div className="fixed inset-0 flex items-center justify-center p-4">
<Dialog.Panel className="mx-auto max-w-md w-full bg-white rounded-lg shadow-xl">
<div className="flex items-center justify-between p-6 border-b border-gray-200">
<Dialog.Title className="text-lg font-medium text-gray-900">
Modifier la proposition
</Dialog.Title>
<button
onClick={onClose}
className="text-gray-400 hover:text-gray-600"
>
<XMarkIcon className="h-6 w-6" />
</button>
</div>
<form onSubmit={handleSubmit} className="p-6 space-y-4">
{error && (
<div className="bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-md">
{error}
</div>
)}
<div>
<label htmlFor="title" className="block text-sm font-medium text-gray-700 mb-1">
Titre de la proposition *
</label>
<input
type="text"
id="title"
name="title"
value={formData.title}
onChange={handleChange}
required
className="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500"
placeholder="Titre de la proposition"
/>
</div>
<div>
<label htmlFor="description" className="block text-sm font-medium text-gray-700 mb-1">
Description *
</label>
<textarea
id="description"
name="description"
value={formData.description}
onChange={handleChange}
required
rows={4}
className="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500"
placeholder="Décrivez votre proposition en détail..."
/>
</div>
<div className="flex items-center 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-white border border-gray-300 rounded-md hover:bg-gray-50"
>
Annuler
</button>
<button
type="submit"
disabled={loading}
className="px-4 py-2 text-sm font-medium text-white bg-indigo-600 border border-transparent rounded-md hover:bg-indigo-700 disabled:opacity-50 disabled:cursor-not-allowed"
>
{loading ? 'Modification...' : 'Modifier la proposition'}
</button>
</div>
</form>
</Dialog.Panel>
</div>
</Dialog>
);
}