Refactor event type handling and add data management page (options and event types)

This commit is contained in:
ElPoyo
2025-10-15 19:01:09 +02:00
parent f10a608801
commit 5057bf9a77
16 changed files with 1561 additions and 61 deletions

View File

@@ -25,7 +25,7 @@ class EventFormController extends ChangeNotifier {
String? _error;
String? _success;
String? _selectedEventTypeId;
List<EventType> _eventTypes = [];
List<EventTypeModel> _eventTypes = [];
bool _isLoadingEventTypes = true;
List<String> _selectedUserIds = [];
List<UserModel> _allUsers = [];
@@ -42,7 +42,7 @@ class EventFormController extends ChangeNotifier {
String? get error => _error;
String? get success => _success;
String? get selectedEventTypeId => _selectedEventTypeId;
List<EventType> get eventTypes => _eventTypes;
List<EventTypeModel> get eventTypes => _eventTypes;
bool get isLoadingEventTypes => _isLoadingEventTypes;
List<String> get selectedUserIds => _selectedUserIds;
List<UserModel> get allUsers => _allUsers;
@@ -147,26 +147,30 @@ class EventFormController extends ChangeNotifier {
final oldEventTypeIndex = _selectedEventTypeId != null
? _eventTypes.indexWhere((et) => et.id == _selectedEventTypeId)
: -1;
final EventType? oldEventType = oldEventTypeIndex != -1 ? _eventTypes[oldEventTypeIndex] : null;
final EventTypeModel? oldEventType = oldEventTypeIndex != -1 ? _eventTypes[oldEventTypeIndex] : null;
_selectedEventTypeId = newTypeId;
if (newTypeId != null) {
final selectedType = _eventTypes.firstWhere((et) => et.id == newTypeId);
// Utiliser le prix par défaut du type d'événement
final defaultPrice = selectedType.defaultPrice;
final currentPrice = double.tryParse(basePriceController.text.replaceAll(',', '.'));
final oldDefaultPrice = oldEventType?.defaultPrice;
// Mettre à jour le prix si le champ est vide ou si c'était l'ancien prix par défaut
if (basePriceController.text.isEmpty ||
(currentPrice != null && oldDefaultPrice != null && currentPrice == oldDefaultPrice)) {
basePriceController.text = defaultPrice.toStringAsFixed(2);
}
// Filtrer les options qui ne sont plus compatibles avec le nouveau type
final before = _selectedOptions.length;
_selectedOptions.removeWhere((opt) {
final types = opt['compatibleTypes'] as List<dynamic>?;
if (types == null) return true;
return !types.contains(selectedType.name);
// Vérifier si cette option est compatible avec le type d'événement sélectionné
final optionEventTypes = opt['eventTypes'] as List<dynamic>? ?? [];
return !optionEventTypes.contains(selectedType.id);
});
if (_selectedOptions.length < before) {