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 new file mode 100644 index 00000000..14288a25 --- /dev/null +++ b/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/bookable_spaces_bloc/bookable_spaces_bloc.dart @@ -0,0 +1,34 @@ +import 'package:bloc/bloc.dart'; +import 'package:equatable/equatable.dart'; +import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/models/bookable_space_model.dart'; +import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/params/bookable_spaces_params.dart'; +import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/service/bookable_spaces_service.dart'; +import 'package:syncrow_web/pages/space_management_v2/main_module/shared/models/paginated_data_model.dart'; +import 'package:syncrow_web/services/api/api_exception.dart'; + +part 'bookable_spaces_event.dart'; +part 'bookable_spaces_state.dart'; + +class BookableSpacesBloc + extends Bloc { + final BookableSpacesService bookableSpacesService; + BookableSpacesBloc(this.bookableSpacesService) + : super(BookableSpacesInitial()) { + on(_onLoadBookableSpaces); + } + + Future _onLoadBookableSpaces( + LoadBookableSpacesEvent event, Emitter emit) async { + emit(BookableSpacesLoading()); + try { + final bookableSpaces = await bookableSpacesService.load(event.params); + emit(BookableSpacesLoaded(bookableSpacesList: bookableSpaces)); + } on APIException catch (e) { + emit(BookableSpacesError(error: e.message)); + } catch (e) { + emit( + BookableSpacesError(error: e.toString()), + ); + } + } +} diff --git a/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/bookable_spaces_bloc/bookable_spaces_event.dart b/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/bookable_spaces_bloc/bookable_spaces_event.dart new file mode 100644 index 00000000..47a1b396 --- /dev/null +++ b/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/bookable_spaces_bloc/bookable_spaces_event.dart @@ -0,0 +1,13 @@ +part of 'bookable_spaces_bloc.dart'; + +sealed class BookableSpacesEvent extends Equatable { + const BookableSpacesEvent(); + + @override + List get props => []; +} + +class LoadBookableSpacesEvent extends BookableSpacesEvent { + final BookableSpacesParams params; + const LoadBookableSpacesEvent(this.params); +} diff --git a/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/bookable_spaces_bloc/bookable_spaces_state.dart b/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/bookable_spaces_bloc/bookable_spaces_state.dart new file mode 100644 index 00000000..d722ddef --- /dev/null +++ b/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/bookable_spaces_bloc/bookable_spaces_state.dart @@ -0,0 +1,26 @@ +part of 'bookable_spaces_bloc.dart'; + +sealed class BookableSpacesState extends Equatable { + const BookableSpacesState(); + + @override + List get props => []; +} + +final class BookableSpacesInitial extends BookableSpacesState {} + +final class BookableSpacesLoading extends BookableSpacesState {} + +final class BookableSpacesLoaded extends BookableSpacesState { + final PaginatedDataModel bookableSpacesList; + const BookableSpacesLoaded({ + required this.bookableSpacesList, + }); +} + +final class BookableSpacesError extends BookableSpacesState { + final String error; + const BookableSpacesError({ + required this.error, + }); +} diff --git a/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/non_bookable_spaces_bloc/non_bookaable_spaces_bloc.dart b/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/non_bookable_spaces_bloc/non_bookaable_spaces_bloc.dart new file mode 100644 index 00000000..24ac31d7 --- /dev/null +++ b/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/non_bookable_spaces_bloc/non_bookaable_spaces_bloc.dart @@ -0,0 +1,91 @@ +import 'package:bloc/bloc.dart'; +import 'package:equatable/equatable.dart'; +import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/models/bookable_space_model.dart'; +import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/params/non_bookable_spaces_params.dart'; +import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/service/non_bookable_spaces_service.dart'; +import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/service/send_bookable_spaces_to_api_params.dart'; +import 'package:syncrow_web/pages/space_management_v2/main_module/shared/models/paginated_data_model.dart'; + +part 'non_bookaable_spaces_event.dart'; +part 'non_bookaable_spaces_state.dart'; + +class NonBookableSpacesBloc + extends Bloc { + NonBookableSpacesService nonBookableSpacesService; + List selectedBookableSpaces = []; + NonBookableSpacesBloc(this.nonBookableSpacesService) + : super(NonBookableSpacesInitial()) { + on(_onLoadUnBookableSpacesEvent); + on(_onAddToBookableSpaceEvent); + on(_onRemoveFromBookableSpaceEvent); + on(_onSendBookableSpacesToApi); + } + Future _onLoadUnBookableSpacesEvent(LoadUnBookableSpacesEvent event, + Emitter emit) async { + emit(NonBookableSpacesLoading()); + try { + final nonBookableSpacesList = await nonBookableSpacesService.load( + event.nonBookableSpacesParams, + ); + emit( + NonBookableSpacesLoaded(nonBookableSpaces: nonBookableSpacesList), + ); + } catch (e) { + emit( + NonBookableSpacesError(e.toString()), + ); + } + } + + void _onAddToBookableSpaceEvent( + AddToBookableSpaceEvent event, + Emitter emit, + ) { + if (state is NonBookableSpacesLoaded) { + final currentState = state as NonBookableSpacesLoaded; + + final updatedSelectedSpaces = + List.from(currentState.selectedBookableSpaces) + ..add(event.nonBookableSpace); + + selectedBookableSpaces.add(event.nonBookableSpace); + + emit( + NonBookableSpacesLoaded( + nonBookableSpaces: currentState.nonBookableSpaces, + selectedBookableSpaces: updatedSelectedSpaces, + ), + ); + } + } + + void _onRemoveFromBookableSpaceEvent(RemoveFromBookableSpaceEvent event, + Emitter emit) { + if (state is NonBookableSpacesLoaded) { + final currentState = state as NonBookableSpacesLoaded; + currentState.selectedBookableSpaces.remove(event.bookableSpace); + selectedBookableSpaces.remove(event.bookableSpace); + emit( + NonBookableSpacesLoaded( + nonBookableSpaces: currentState.nonBookableSpaces, + selectedBookableSpaces: currentState.selectedBookableSpaces, + ), + ); + } + } + + Future _onSendBookableSpacesToApi(SendBookableSpacesToApi event, + Emitter emit) async { + emit(NonBookableSpacesLoading()); + try { + await nonBookableSpacesService.sendBookableSpacesToApi( + SendBookableSpacesToApiParams.fromBookableSpacesModel( + selectedBookableSpaces), + ); + } catch (e) { + emit( + NonBookableSpacesError(e.toString()), + ); + } + } +} diff --git a/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/non_bookable_spaces_bloc/non_bookaable_spaces_event.dart b/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/non_bookable_spaces_bloc/non_bookaable_spaces_event.dart new file mode 100644 index 00000000..392cf4d4 --- /dev/null +++ b/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/non_bookable_spaces_bloc/non_bookaable_spaces_event.dart @@ -0,0 +1,31 @@ +part of 'non_bookaable_spaces_bloc.dart'; + +sealed class NonBookableSpacesEvent extends Equatable { + const NonBookableSpacesEvent(); + + @override + List get props => []; +} + +class LoadUnBookableSpacesEvent extends NonBookableSpacesEvent { + final NonBookableSpacesParams nonBookableSpacesParams; + const LoadUnBookableSpacesEvent({ + required this.nonBookableSpacesParams, + }); +} + +class AddToBookableSpaceEvent extends NonBookableSpacesEvent { + final BookableSpacemodel nonBookableSpace; + const AddToBookableSpaceEvent({ + required this.nonBookableSpace, + }); +} + +class RemoveFromBookableSpaceEvent extends NonBookableSpacesEvent { + final BookableSpacemodel bookableSpace; + const RemoveFromBookableSpaceEvent({ + required this.bookableSpace, + }); +} + +class SendBookableSpacesToApi extends NonBookableSpacesEvent {} diff --git a/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/non_bookable_spaces_bloc/non_bookaable_spaces_state.dart b/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/non_bookable_spaces_bloc/non_bookaable_spaces_state.dart new file mode 100644 index 00000000..850b114d --- /dev/null +++ b/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/non_bookable_spaces_bloc/non_bookaable_spaces_state.dart @@ -0,0 +1,26 @@ +part of 'non_bookaable_spaces_bloc.dart'; + +sealed class NonBookableSpacesState extends Equatable { + const NonBookableSpacesState(); + + @override + List get props => []; +} + +final class NonBookableSpacesInitial extends NonBookableSpacesState {} + +class NonBookableSpacesLoading extends NonBookableSpacesState {} + +class NonBookableSpacesLoaded extends NonBookableSpacesState { + final PaginatedDataModel nonBookableSpaces; + final List selectedBookableSpaces; + const NonBookableSpacesLoaded({ + required this.nonBookableSpaces, + this.selectedBookableSpaces = const [], + }); +} + +class NonBookableSpacesError extends NonBookableSpacesState { + final String error; + const NonBookableSpacesError(this.error); +} diff --git a/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/steps_cubit/cubit/steps_cubit.dart b/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/steps_cubit/cubit/steps_cubit.dart new file mode 100644 index 00000000..07dba931 --- /dev/null +++ b/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/steps_cubit/cubit/steps_cubit.dart @@ -0,0 +1,18 @@ +import 'package:bloc/bloc.dart'; +import 'package:equatable/equatable.dart'; + +part 'steps_state.dart'; + +class StepsCubit extends Cubit { + StepsCubit() : super(StepsInitial()); + + void initDialogValue() { + emit(StepOneState()); + } + + void goToNextStep() { + if (state is StepOneState) { + emit(StepTwoState()); + } + } +} diff --git a/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/steps_cubit/cubit/steps_state.dart b/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/steps_cubit/cubit/steps_state.dart new file mode 100644 index 00000000..d6b8dd37 --- /dev/null +++ b/lib/pages/access_management/manage_bookable_spaces/presentation/blocs/steps_cubit/cubit/steps_state.dart @@ -0,0 +1,16 @@ +part of 'steps_cubit.dart'; + +sealed class StepsState extends Equatable { + const StepsState(); + + @override + List get props => []; +} + +final class StepsInitial extends StepsState {} + +final class StepOneState extends StepsState {} + +final class StepTwoState extends StepsState {} + +final class StepEditMode extends StepsState {}