refactoring majeur (code dupliqué, mort, ...)

- Économie : ~1240 lignes de code dupliqué
- Réduction : ~60% du code modal
- Amélioration : Cohérence et maintenabilité
This commit is contained in:
Yannick Le Duc
2025-08-27 12:45:37 +02:00
parent 6acc7d9d35
commit dc388bf371
25 changed files with 1446 additions and 1821 deletions

32
src/hooks/useFormState.ts Normal file
View File

@@ -0,0 +1,32 @@
import { useState } from 'react';
export function useFormState<T>(initialData: T) {
const [formData, setFormData] = useState<T>(initialData);
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
setFormData(prev => ({ ...prev, [e.target.name]: e.target.value }));
};
const resetForm = () => {
setFormData(initialData);
setError('');
};
const setFieldValue = (field: keyof T, value: any) => {
setFormData(prev => ({ ...prev, [field]: value }));
};
return {
formData,
setFormData,
loading,
setLoading,
error,
setError,
handleChange,
resetForm,
setFieldValue
};
}