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,189 @@
'use client';
import { useState } from 'react';
import { Dialog } from '@headlessui/react';
import { XMarkIcon } from '@heroicons/react/24/outline';
import { campaignService } from '@/lib/services';
import { CampaignStatus } from '@/types';
interface CreateCampaignModalProps {
isOpen: boolean;
onClose: () => void;
onSuccess: () => void;
}
export default function CreateCampaignModal({ isOpen, onClose, onSuccess }: CreateCampaignModalProps) {
const [formData, setFormData] = useState({
title: '',
description: '',
status: 'deposit' as CampaignStatus,
budget_per_user: 100,
spending_tiers: '10,25,50,100'
});
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
setError('');
try {
await campaignService.create(formData);
onSuccess();
// Reset form
setFormData({
title: '',
description: '',
status: 'deposit',
budget_per_user: 100,
spending_tiers: '10,25,50,100'
});
} catch (err) {
setError('Erreur lors de la création de la campagne');
console.error(err);
} finally {
setLoading(false);
}
};
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => {
const { name, value } = e.target;
setFormData(prev => ({
...prev,
[name]: name === 'budget_per_user' ? parseInt(value) || 0 : 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">
Créer une nouvelle campagne
</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 *
</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 campagne"
/>
</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={3}
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="Description de la campagne"
/>
</div>
<div>
<label htmlFor="status" className="block text-sm font-medium text-gray-700 mb-1">
État initial
</label>
<select
id="status"
name="status"
value={formData.status}
onChange={handleChange}
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"
>
<option value="deposit">Dépôt de propositions</option>
<option value="voting">En cours de vote</option>
<option value="closed">Fermé</option>
</select>
</div>
<div>
<label htmlFor="budget_per_user" className="block text-sm font-medium text-gray-700 mb-1">
Budget par utilisateur () *
</label>
<input
type="number"
id="budget_per_user"
name="budget_per_user"
value={formData.budget_per_user}
onChange={handleChange}
required
min="1"
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="100"
/>
</div>
<div>
<label htmlFor="spending_tiers" className="block text-sm font-medium text-gray-700 mb-1">
Paliers de dépenses () *
</label>
<input
type="text"
id="spending_tiers"
name="spending_tiers"
value={formData.spending_tiers}
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="10,25,50,100"
/>
<p className="mt-1 text-sm text-gray-500">
Montants séparés par des virgules (ex: 10,25,50,100)
</p>
</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 ? 'Création...' : 'Créer la campagne'}
</button>
</div>
</form>
</Dialog.Panel>
</div>
</Dialog>
);
}