diff --git a/lib/pages/access_management/booking_system/presentation/view/widgets/icon_text_button.dart b/lib/pages/access_management/booking_system/presentation/view/widgets/icon_text_button.dart index 32201ed5..9844e3d8 100644 --- a/lib/pages/access_management/booking_system/presentation/view/widgets/icon_text_button.dart +++ b/lib/pages/access_management/booking_system/presentation/view/widgets/icon_text_button.dart @@ -4,8 +4,7 @@ import 'package:syncrow_web/utils/color_manager.dart'; class SvgTextButton extends StatelessWidget { final String svgAsset; - final double? horizontalPadding; - final double? verticalPadding; + final EdgeInsets? padding; final String label; final VoidCallback onPressed; final Color backgroundColor; @@ -27,8 +26,7 @@ class SvgTextButton extends StatelessWidget { this.svgColor = const Color(0xFF496EFF), this.labelColor = Colors.black, this.borderRadius = 10.0, - this.horizontalPadding, - this.verticalPadding, + this.padding, this.boxShadow = const [ BoxShadow( color: ColorsManager.lightGrayColor, @@ -47,9 +45,8 @@ class SvgTextButton extends StatelessWidget { borderRadius: BorderRadius.circular(borderRadius), onTap: onPressed, child: Container( - padding: EdgeInsets.symmetric( - horizontal: horizontalPadding ?? 24, - vertical: verticalPadding ?? 12), + padding: padding ?? + const EdgeInsets.symmetric(horizontal: 24, vertical: 12), decoration: BoxDecoration( color: backgroundColor, borderRadius: BorderRadius.circular(borderRadius), diff --git a/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/bookable_spaces_bloc/bookable_spaces_bloc.dart b/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/bookable_spaces_bloc/bookable_spaces_bloc.dart index 9f7bf2eb..c947cd69 100644 --- a/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/bookable_spaces_bloc/bookable_spaces_bloc.dart +++ b/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/bookable_spaces_bloc/bookable_spaces_bloc.dart @@ -40,22 +40,25 @@ class BookableSpacesBloc if (event.bookableSpace.spaceConfig!.configUuid == event.updatedBookableSpaceConfig.configUuid) { - final editedBookableSpace = event.bookableSpaces.data.firstWhere( - (element) => element.spaceUuid == event.bookableSpace.spaceUuid, - ); - final config = editedBookableSpace.spaceConfig!.copyWith( - availability: event.updatedBookableSpaceConfig.availability, - bookableDays: event.updatedBookableSpaceConfig.bookableDays, - bookingEndTime: event.updatedBookableSpaceConfig.bookingEndTime, - bookingStartTime: event.updatedBookableSpaceConfig.bookingStartTime, - cost: event.updatedBookableSpaceConfig.cost, - ); - editedBookableSpace.copyWith(spaceConfig: config); final index = event.bookableSpaces.data.indexWhere( (element) => element.spaceUuid == event.bookableSpace.spaceUuid, ); - event.bookableSpaces.data.removeAt(index); - event.bookableSpaces.data.insert(index, editedBookableSpace); + + if (index != -1) { + final original = event.bookableSpaces.data[index]; + + final updatedConfig = original.spaceConfig!.copyWith( + availability: event.updatedBookableSpaceConfig.availability, + bookableDays: event.updatedBookableSpaceConfig.bookableDays, + bookingEndTime: event.updatedBookableSpaceConfig.bookingEndTime, + bookingStartTime: event.updatedBookableSpaceConfig.bookingStartTime, + cost: event.updatedBookableSpaceConfig.cost, + ); + + final updatedSpace = original.copyWith(spaceConfig: updatedConfig); + + event.bookableSpaces.data[index] = updatedSpace; + } } emit(BookableSpacesLoaded(bookableSpacesList: event.bookableSpaces)); diff --git a/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/booking_period_widget.dart b/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/booking_period_widget.dart index 75cf34d7..439bda04 100644 --- a/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/booking_period_widget.dart +++ b/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/booking_period_widget.dart @@ -65,10 +65,21 @@ class BookingPeriodWidget extends StatelessWidget { )); throw Exception(); } else { - setupBookableSpacesBloc.selectedBookableSpaces.forEach( - (e) => - e.spaceConfig!.copyWith(bookingStartTime: timePicked), - ); + for (int i = 0; + i < + setupBookableSpacesBloc + .selectedBookableSpaces.length; + i++) { + final space = + setupBookableSpacesBloc.selectedBookableSpaces[i]; + final updatedConfig = space.spaceConfig + ?.copyWith(bookingStartTime: timePicked); + final updatedSpace = + space.copyWith(spaceConfig: updatedConfig); + + setupBookableSpacesBloc.selectedBookableSpaces[i] = + updatedSpace; + } } }, ), @@ -99,10 +110,21 @@ class BookingPeriodWidget extends StatelessWidget { )); throw Exception(); } else { - setupBookableSpacesBloc.selectedBookableSpaces.forEach( - (e) => - e.spaceConfig!.copyWith(bookingEndTime: timePicked), - ); + for (int i = 0; + i < + setupBookableSpacesBloc + .selectedBookableSpaces.length; + i++) { + final space = + setupBookableSpacesBloc.selectedBookableSpaces[i]; + final updatedConfig = space.spaceConfig + ?.copyWith(bookingEndTime: timePicked); + final updatedSpace = + space.copyWith(spaceConfig: updatedConfig); + + setupBookableSpacesBloc.selectedBookableSpaces[i] = + updatedSpace; + } } }, ), diff --git a/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/main_manage_bookable_widgets/top_part_widget.dart b/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/main_manage_bookable_widgets/top_part_widget.dart index 2460cda0..3c6694af 100644 --- a/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/main_manage_bookable_widgets/top_part_widget.dart +++ b/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/main_manage_bookable_widgets/top_part_widget.dart @@ -53,8 +53,7 @@ class RowOfButtonsTitleWidget extends StatelessWidget { ], ), SvgTextButton( - verticalPadding: 10, - horizontalPadding: 10, + padding: const EdgeInsets.all(10), svgSize: 15, fontSize: 10, fontWeight: FontWeight.bold, diff --git a/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/points_part_widget.dart b/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/points_part_widget.dart index 0ca00205..1106f214 100644 --- a/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/points_part_widget.dart +++ b/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/points_part_widget.dart @@ -73,34 +73,31 @@ class _PointsPartWidgetState extends State { }), value: state is ActivatePointsSwitch, onChanged: (value) { + final bloc = context.read(); + final updatedCost = value ? -1 : 0; + + final switchCubit = + context.read(); if (value) { - context - .read() - .activateSwitch(); - context - .read() - .selectedBookableSpaces - .forEach( - (e) => e.spaceConfig!.copyWith(cost: -1), - ); - context - .read() - .add(CheckConfigurValidityEvent()); + switchCubit.activateSwitch(); } else { - context - .read() - .unActivateSwitch(); + switchCubit.unActivateSwitch(); widget.pointsController.clear(); - context - .read() - .selectedBookableSpaces - .forEach( - (e) => e.spaceConfig!.copyWith(cost: 0), - ); - context - .read() - .add(CheckConfigurValidityEvent()); } + + for (int i = 0; + i < bloc.selectedBookableSpaces.length; + i++) { + final space = bloc.selectedBookableSpaces[i]; + final updatedConfig = + space.spaceConfig?.copyWith(cost: updatedCost); + final updatedSpace = + space.copyWith(spaceConfig: updatedConfig); + + bloc.selectedBookableSpaces[i] = updatedSpace; + } + + bloc.add(CheckConfigurValidityEvent()); }, ), ) @@ -114,16 +111,21 @@ class _PointsPartWidgetState extends State { title: 'Ex: 0', height: 40, onChanged: (p0) { - context - .read() - .selectedBookableSpaces - .forEach( - (e) => e.spaceConfig!.copyWith( - cost: int.parse(widget.pointsController.text.isEmpty - ? '0' - : widget.pointsController.text), - ), - ); + final updatedCost = + int.tryParse(widget.pointsController.text) ?? 0; + + final bloc = context.read(); + + for (var i = 0; i < bloc.selectedBookableSpaces.length; i++) { + final space = bloc.selectedBookableSpaces[i]; + final updatedConfig = + space.spaceConfig?.copyWith(cost: updatedCost); + final updatedSpace = + space.copyWith(spaceConfig: updatedConfig); + + bloc.selectedBookableSpaces[i] = updatedSpace; + } + context .read() .add(CheckConfigurValidityEvent()); diff --git a/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/week_checkbox_title_widget.dart b/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/week_checkbox_title_widget.dart index cd6af711..5d689748 100644 --- a/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/week_checkbox_title_widget.dart +++ b/lib/pages/access_management/manage_bookable_spaces/presentation/widgets/week_checkbox_title_widget.dart @@ -52,21 +52,28 @@ class _WeekDaysCheckboxRowState extends State { onChanged: (newValue) { setState(() { _daysChecked[entry.key] = newValue ?? false; - final selectedDays = _daysChecked.entries - .where((e) => e.value) - .map((e) => e.key) - .toList(); - - for (var space in context - .read() - .selectedBookableSpaces) { - space.spaceConfig!.copyWith(bookableDays: selectedDays); - } }); - context - .read() - .add(CheckConfigurValidityEvent()); + final selectedDays = _daysChecked.entries + .where((e) => e.value) + .map((e) => e.key) + .toList(); + + final bloc = context.read(); + + for (int i = 0; + i < bloc.selectedBookableSpaces.length; + i++) { + final space = bloc.selectedBookableSpaces[i]; + final updatedConfig = space.spaceConfig + ?.copyWith(bookableDays: selectedDays); + final updatedSpace = + space.copyWith(spaceConfig: updatedConfig); + + bloc.selectedBookableSpaces[i] = updatedSpace; + } + + bloc.add(CheckConfigurValidityEvent()); }, ), ),