6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit 69df61c1
Changed files
.../bloc/booking_details_state.freezed.dart | 316 +++++++++++++++++++ .../booking_details/bloc/booking_details_bloc.dart | 338 --------------------- .../bloc/booking_details_cubit.dart | 62 ++-- .../bloc/booking_details_event.dart | 90 ------ .../bloc/booking_details_state.dart | 131 ++------ .../lib/booking_details/booking_details_page.dart | 2 +- .../lib/booking_details/booking_details_route.dart | 1 - .../components/booking_details_bottom_sheet.dart | 5 +- .../components/check_in_button.dart | 2 - .../components/check_in_button_timer.dart | 2 +- .../components/check_out_button.dart | 1 - .../components/get_keys_button.dart | 6 +- .../components/housekeeping_button.dart | 1 - .../components/preregister_button.dart | 1 - .../booking_details/components/share_button.dart | 1 - .../lib/my_booking/my_booking_page.dart | 3 +- .../screens/concierge/bloc/concierge_state.dart | 2 - .../booking_details_bloc_test.dart | 67 ---- 18 files changed, 379 insertions(+), 652 deletions(-)
Diff
diff --git a/comwell_key_app/lib/.generated/booking_details/bloc/booking_details_state.freezed.dart b/comwell_key_app/lib/.generated/booking_details/bloc/booking_details_state.freezed.dart
new file mode 100644
index 00000000..f16f0ff9
--- /dev/null
+++ b/comwell_key_app/lib/.generated/booking_details/bloc/booking_details_state.freezed.dart
@@ -0,0 +1,316 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+// coverage:ignore-file
+// ignore_for_file: type=lint
+// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
+
+part of '../../../booking_details/bloc/booking_details_state.dart';
+
+// **************************************************************************
+// FreezedGenerator
+// **************************************************************************
+
+// dart format off
+T _$identity<T>(T value) => value;
+/// @nodoc
+mixin _$BookingDetailsState {
+
+ bool get isHouseKeepingOrdered; MobileKeysKey? get key; List<MobileKeysKey> get keys; List<Guest> get guests; Duration get remainingTime; AppError get error; bool get isLoading; bool get isLoadingKeys; UpSales? get upSales; List<Upgrade> get selectedUpSales;
+/// Create a copy of BookingDetailsState
+/// with the given fields replaced by the non-null parameter values.
+@JsonKey(includeFromJson: false, includeToJson: false)
+@pragma('vm:prefer-inline')
+$BookingDetailsStateCopyWith<BookingDetailsState> get copyWith => _$BookingDetailsStateCopyWithImpl<BookingDetailsState>(this as BookingDetailsState, _$identity);
+
+
+
+@override
+bool operator ==(Object other) {
+ return identical(this, other) || (other.runtimeType == runtimeType&&other is BookingDetailsState&&(identical(other.isHouseKeepingOrdered, isHouseKeepingOrdered) || other.isHouseKeepingOrdered == isHouseKeepingOrdered)&&(identical(other.key, key) || other.key == key)&&const DeepCollectionEquality().equals(other.keys, keys)&&const DeepCollectionEquality().equals(other.guests, guests)&&(identical(other.remainingTime, remainingTime) || other.remainingTime == remainingTime)&&(identical(other.error, error) || other.error == error)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isLoadingKeys, isLoadingKeys) || other.isLoadingKeys == isLoadingKeys)&&(identical(other.upSales, upSales) || other.upSales == upSales)&&const DeepCollectionEquality().equals(other.selectedUpSales, selectedUpSales));
+}
+
+
+@override
+int get hashCode => Object.hash(runtimeType,isHouseKeepingOrdered,key,const DeepCollectionEquality().hash(keys),const DeepCollectionEquality().hash(guests),remainingTime,error,isLoading,isLoadingKeys,upSales,const DeepCollectionEquality().hash(selectedUpSales));
+
+@override
+String toString() {
+ return 'BookingDetailsState(isHouseKeepingOrdered: $isHouseKeepingOrdered, key: $key, keys: $keys, guests: $guests, remainingTime: $remainingTime, error: $error, isLoading: $isLoading, isLoadingKeys: $isLoadingKeys, upSales: $upSales, selectedUpSales: $selectedUpSales)';
+}
+
+
+}
+
+/// @nodoc
+abstract mixin class $BookingDetailsStateCopyWith<$Res> {
+ factory $BookingDetailsStateCopyWith(BookingDetailsState value, $Res Function(BookingDetailsState) _then) = _$BookingDetailsStateCopyWithImpl;
+@useResult
+$Res call({
+ bool isHouseKeepingOrdered, MobileKeysKey? key, List<MobileKeysKey> keys, List<Guest> guests, Duration remainingTime, AppError error, bool isLoading, bool isLoadingKeys, UpSales? upSales, List<Upgrade> selectedUpSales
+});
+
+
+
+
+}
+/// @nodoc
+class _$BookingDetailsStateCopyWithImpl<$Res>
+ implements $BookingDetailsStateCopyWith<$Res> {
+ _$BookingDetailsStateCopyWithImpl(this._self, this._then);
+
+ final BookingDetailsState _self;
+ final $Res Function(BookingDetailsState) _then;
+
+/// Create a copy of BookingDetailsState
+/// with the given fields replaced by the non-null parameter values.
+@pragma('vm:prefer-inline') @override $Res call({Object? isHouseKeepingOrdered = null,Object? key = freezed,Object? keys = null,Object? guests = null,Object? remainingTime = null,Object? error = null,Object? isLoading = null,Object? isLoadingKeys = null,Object? upSales = freezed,Object? selectedUpSales = null,}) {
+ return _then(_self.copyWith(
+isHouseKeepingOrdered: null == isHouseKeepingOrdered ? _self.isHouseKeepingOrdered : isHouseKeepingOrdered // ignore: cast_nullable_to_non_nullable
+as bool,key: freezed == key ? _self.key : key // ignore: cast_nullable_to_non_nullable
+as MobileKeysKey?,keys: null == keys ? _self.keys : keys // ignore: cast_nullable_to_non_nullable
+as List<MobileKeysKey>,guests: null == guests ? _self.guests : guests // ignore: cast_nullable_to_non_nullable
+as List<Guest>,remainingTime: null == remainingTime ? _self.remainingTime : remainingTime // ignore: cast_nullable_to_non_nullable
+as Duration,error: null == error ? _self.error : error // ignore: cast_nullable_to_non_nullable
+as AppError,isLoading: null == isLoading ? _self.isLoading : isLoading // ignore: cast_nullable_to_non_nullable
+as bool,isLoadingKeys: null == isLoadingKeys ? _self.isLoadingKeys : isLoadingKeys // ignore: cast_nullable_to_non_nullable
+as bool,upSales: freezed == upSales ? _self.upSales : upSales // ignore: cast_nullable_to_non_nullable
+as UpSales?,selectedUpSales: null == selectedUpSales ? _self.selectedUpSales : selectedUpSales // ignore: cast_nullable_to_non_nullable
+as List<Upgrade>,
+ ));
+}
+
+}
+
+
+/// Adds pattern-matching-related methods to [BookingDetailsState].
+extension BookingDetailsStatePatterns on BookingDetailsState {
+/// A variant of `map` that fallback to returning `orElse`.
+///
+/// It is equivalent to doing:
+/// ```dart
+/// switch (sealedClass) {
+/// case final Subclass value:
+/// return ...;
+/// case _:
+/// return orElse();
+/// }
+/// ```
+
+@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _BookingDetailsState value)? $default,{required TResult orElse(),}){
+final _that = this;
+switch (_that) {
+case _BookingDetailsState() when $default != null:
+return $default(_that);case _:
+ return orElse();
+
+}
+}
+/// A `switch`-like method, using callbacks.
+///
+/// Callbacks receives the raw object, upcasted.
+/// It is equivalent to doing:
+/// ```dart
+/// switch (sealedClass) {
+/// case final Subclass value:
+/// return ...;
+/// case final Subclass2 value:
+/// return ...;
+/// }
+/// ```
+
+@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _BookingDetailsState value) $default,){
+final _that = this;
+switch (_that) {
+case _BookingDetailsState():
+return $default(_that);case _:
+ throw StateError('Unexpected subclass');
+
+}
+}
+/// A variant of `map` that fallback to returning `null`.
+///
+/// It is equivalent to doing:
+/// ```dart
+/// switch (sealedClass) {
+/// case final Subclass value:
+/// return ...;
+/// case _:
+/// return null;
+/// }
+/// ```
+
+@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _BookingDetailsState value)? $default,){
+final _that = this;
+switch (_that) {
+case _BookingDetailsState() when $default != null:
+return $default(_that);case _:
+ return null;
+
+}
+}
+/// A variant of `when` that fallback to an `orElse` callback.
+///
+/// It is equivalent to doing:
+/// ```dart
+/// switch (sealedClass) {
+/// case Subclass(:final field):
+/// return ...;
+/// case _:
+/// return orElse();
+/// }
+/// ```
+
+@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( bool isHouseKeepingOrdered, MobileKeysKey? key, List<MobileKeysKey> keys, List<Guest> guests, Duration remainingTime, AppError error, bool isLoading, bool isLoadingKeys, UpSales? upSales, List<Upgrade> selectedUpSales)? $default,{required TResult orElse(),}) {final _that = this;
+switch (_that) {
+case _BookingDetailsState() when $default != null:
+return $default(_that.isHouseKeepingOrdered,_that.key,_that.keys,_that.guests,_that.remainingTime,_that.error,_that.isLoading,_that.isLoadingKeys,_that.upSales,_that.selectedUpSales);case _:
+ return orElse();
+
+}
+}
+/// A `switch`-like method, using callbacks.
+///
+/// As opposed to `map`, this offers destructuring.
+/// It is equivalent to doing:
+/// ```dart
+/// switch (sealedClass) {
+/// case Subclass(:final field):
+/// return ...;
+/// case Subclass2(:final field2):
+/// return ...;
+/// }
+/// ```
+
+@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( bool isHouseKeepingOrdered, MobileKeysKey? key, List<MobileKeysKey> keys, List<Guest> guests, Duration remainingTime, AppError error, bool isLoading, bool isLoadingKeys, UpSales? upSales, List<Upgrade> selectedUpSales) $default,) {final _that = this;
+switch (_that) {
+case _BookingDetailsState():
+return $default(_that.isHouseKeepingOrdered,_that.key,_that.keys,_that.guests,_that.remainingTime,_that.error,_that.isLoading,_that.isLoadingKeys,_that.upSales,_that.selectedUpSales);case _:
+ throw StateError('Unexpected subclass');
+
+}
+}
+/// A variant of `when` that fallback to returning `null`
+///
+/// It is equivalent to doing:
+/// ```dart
+/// switch (sealedClass) {
+/// case Subclass(:final field):
+/// return ...;
+/// case _:
+/// return null;
+/// }
+/// ```
+
+@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( bool isHouseKeepingOrdered, MobileKeysKey? key, List<MobileKeysKey> keys, List<Guest> guests, Duration remainingTime, AppError error, bool isLoading, bool isLoadingKeys, UpSales? upSales, List<Upgrade> selectedUpSales)? $default,) {final _that = this;
+switch (_that) {
+case _BookingDetailsState() when $default != null:
+return $default(_that.isHouseKeepingOrdered,_that.key,_that.keys,_that.guests,_that.remainingTime,_that.error,_that.isLoading,_that.isLoadingKeys,_that.upSales,_that.selectedUpSales);case _:
+ return null;
+
+}
+}
+
+}
+
+/// @nodoc
+
+
+class _BookingDetailsState implements BookingDetailsState {
+ const _BookingDetailsState({this.isHouseKeepingOrdered = false, this.key = null, final List<MobileKeysKey> keys = const [], final List<Guest> guests = const [], this.remainingTime = Duration.zero, this.error = AppError.none, this.isLoading = false, this.isLoadingKeys = false, this.upSales = null, final List<Upgrade> selectedUpSales = const []}): _keys = keys,_guests = guests,_selectedUpSales = selectedUpSales;
+
+
+@override@JsonKey() final bool isHouseKeepingOrdered;
+@override@JsonKey() final MobileKeysKey? key;
+ final List<MobileKeysKey> _keys;
+@override@JsonKey() List<MobileKeysKey> get keys {
+ if (_keys is EqualUnmodifiableListView) return _keys;
+ // ignore: implicit_dynamic_type
+ return EqualUnmodifiableListView(_keys);
+}
+
+ final List<Guest> _guests;
+@override@JsonKey() List<Guest> get guests {
+ if (_guests is EqualUnmodifiableListView) return _guests;
+ // ignore: implicit_dynamic_type
+ return EqualUnmodifiableListView(_guests);
+}
+
+@override@JsonKey() final Duration remainingTime;
+@override@JsonKey() final AppError error;
+@override@JsonKey() final bool isLoading;
+@override@JsonKey() final bool isLoadingKeys;
+@override@JsonKey() final UpSales? upSales;
+ final List<Upgrade> _selectedUpSales;
+@override@JsonKey() List<Upgrade> get selectedUpSales {
+ if (_selectedUpSales is EqualUnmodifiableListView) return _selectedUpSales;
+ // ignore: implicit_dynamic_type
+ return EqualUnmodifiableListView(_selectedUpSales);
+}
+
+
+/// Create a copy of BookingDetailsState
+/// with the given fields replaced by the non-null parameter values.
+@override @JsonKey(includeFromJson: false, includeToJson: false)
+@pragma('vm:prefer-inline')
+_$BookingDetailsStateCopyWith<_BookingDetailsState> get copyWith => __$BookingDetailsStateCopyWithImpl<_BookingDetailsState>(this, _$identity);
+
+
+
+@override
+bool operator ==(Object other) {
+ return identical(this, other) || (other.runtimeType == runtimeType&&other is _BookingDetailsState&&(identical(other.isHouseKeepingOrdered, isHouseKeepingOrdered) || other.isHouseKeepingOrdered == isHouseKeepingOrdered)&&(identical(other.key, key) || other.key == key)&&const DeepCollectionEquality().equals(other._keys, _keys)&&const DeepCollectionEquality().equals(other._guests, _guests)&&(identical(other.remainingTime, remainingTime) || other.remainingTime == remainingTime)&&(identical(other.error, error) || other.error == error)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isLoadingKeys, isLoadingKeys) || other.isLoadingKeys == isLoadingKeys)&&(identical(other.upSales, upSales) || other.upSales == upSales)&&const DeepCollectionEquality().equals(other._selectedUpSales, _selectedUpSales));
+}
+
+
+@override
+int get hashCode => Object.hash(runtimeType,isHouseKeepingOrdered,key,const DeepCollectionEquality().hash(_keys),const DeepCollectionEquality().hash(_guests),remainingTime,error,isLoading,isLoadingKeys,upSales,const DeepCollectionEquality().hash(_selectedUpSales));
+
+@override
+String toString() {
+ return 'BookingDetailsState(isHouseKeepingOrdered: $isHouseKeepingOrdered, key: $key, keys: $keys, guests: $guests, remainingTime: $remainingTime, error: $error, isLoading: $isLoading, isLoadingKeys: $isLoadingKeys, upSales: $upSales, selectedUpSales: $selectedUpSales)';
+}
+
+
+}
+
+/// @nodoc
+abstract mixin class _$BookingDetailsStateCopyWith<$Res> implements $BookingDetailsStateCopyWith<$Res> {
+ factory _$BookingDetailsStateCopyWith(_BookingDetailsState value, $Res Function(_BookingDetailsState) _then) = __$BookingDetailsStateCopyWithImpl;
+@override @useResult
+$Res call({
+ bool isHouseKeepingOrdered, MobileKeysKey? key, List<MobileKeysKey> keys, List<Guest> guests, Duration remainingTime, AppError error, bool isLoading, bool isLoadingKeys, UpSales? upSales, List<Upgrade> selectedUpSales
+});
+
+
+
+
+}
+/// @nodoc
+class __$BookingDetailsStateCopyWithImpl<$Res>
+ implements _$BookingDetailsStateCopyWith<$Res> {
+ __$BookingDetailsStateCopyWithImpl(this._self, this._then);
+
+ final _BookingDetailsState _self;
+ final $Res Function(_BookingDetailsState) _then;
+
+/// Create a copy of BookingDetailsState
+/// with the given fields replaced by the non-null parameter values.
+@override @pragma('vm:prefer-inline') $Res call({Object? isHouseKeepingOrdered = null,Object? key = freezed,Object? keys = null,Object? guests = null,Object? remainingTime = null,Object? error = null,Object? isLoading = null,Object? isLoadingKeys = null,Object? upSales = freezed,Object? selectedUpSales = null,}) {
+ return _then(_BookingDetailsState(
+isHouseKeepingOrdered: null == isHouseKeepingOrdered ? _self.isHouseKeepingOrdered : isHouseKeepingOrdered // ignore: cast_nullable_to_non_nullable
+as bool,key: freezed == key ? _self.key : key // ignore: cast_nullable_to_non_nullable
+as MobileKeysKey?,keys: null == keys ? _self._keys : keys // ignore: cast_nullable_to_non_nullable
+as List<MobileKeysKey>,guests: null == guests ? _self._guests : guests // ignore: cast_nullable_to_non_nullable
+as List<Guest>,remainingTime: null == remainingTime ? _self.remainingTime : remainingTime // ignore: cast_nullable_to_non_nullable
+as Duration,error: null == error ? _self.error : error // ignore: cast_nullable_to_non_nullable
+as AppError,isLoading: null == isLoading ? _self.isLoading : isLoading // ignore: cast_nullable_to_non_nullable
+as bool,isLoadingKeys: null == isLoadingKeys ? _self.isLoadingKeys : isLoadingKeys // ignore: cast_nullable_to_non_nullable
+as bool,upSales: freezed == upSales ? _self.upSales : upSales // ignore: cast_nullable_to_non_nullable
+as UpSales?,selectedUpSales: null == selectedUpSales ? _self._selectedUpSales : selectedUpSales // ignore: cast_nullable_to_non_nullable
+as List<Upgrade>,
+ ));
+}
+
+
+}
+
+// dart format on
diff --git a/comwell_key_app/lib/booking_details/bloc/booking_details_bloc.dart b/comwell_key_app/lib/booking_details/bloc/booking_details_bloc.dart
deleted file mode 100644
index b5b032ba..00000000
--- a/comwell_key_app/lib/booking_details/bloc/booking_details_bloc.dart
+++ /dev/null
@@ -1,338 +0,0 @@
-import 'dart:async';
-import 'package:bloc/bloc.dart';
-
-import 'package:comwell_key_app/housekeeping/components/housekeeping_service.dart';
-import 'package:comwell_key_app/housekeeping/housekeeping_repository.dart';
-import 'package:comwell_key_app/housekeeping/models/housekeeping.dart';
-import 'package:comwell_key_app/overview/models/guest.dart';
-import 'package:comwell_key_app/profile/profile_repository.dart';
-import 'package:comwell_key_app/profile_settings/model/user.dart';
-import 'package:comwell_key_app/share/share_booking_repository.dart';
-import 'package:comwell_key_app/up_sales/models/up_sales.dart';
-import 'package:comwell_key_app/up_sales/models/upgrade.dart';
-import 'package:comwell_key_app/up_sales/up_sales_repository.dart';
-import 'package:comwell_key_app/utils/seos_repository.dart';
-import 'package:equatable/equatable.dart';
-import 'package:flutter/foundation.dart';
-import 'package:seos_mobile_keys_plugin/app_usage_api.dart';
-
-import '../../overview/models/booking.dart';
-import '../booking_details_repository.dart';
-
-part 'booking_details_event.dart';
-
-part 'booking_details_state.dart';
-
-class BookingDetailsBloc extends Bloc<BookingDetailsEvent, BookingDetailsState> {
- late Booking booking;
- User? user;
- Timer? _timer;
- final BookingDetailsRepository _bookingDetailsRepository;
- final ProfileRepository _profileRepository;
- final SeosRepository _seosRepository;
- final UpSalesRepository _upSaleRepository;
- final HouseKeepingRepository _houseKeepingRepository;
- final ShareBookingRepository _shareBookingRepository;
- Duration _remainingTime = Duration.zero;
-
- BookingDetailsBloc(
- this._bookingDetailsRepository,
- this._profileRepository,
- this._seosRepository,
- this._upSaleRepository,
- this._shareBookingRepository,
- this._houseKeepingRepository, {
- required this.booking,
- }) : super(BookingDetailsState.initial(booking)) {
- on<InitialEvent>((event, emit) async {
- try {
- emit(state.loading());
- debugPrint("booking=$booking");
- add(GetUserEvent(event.fetchRemote));
- add(StartTimerEvent());
- add(CheckIfHouseKeepingOrdered());
- add(CheckMobileKeys());
- add(GetBookingDetailsEvent(booking.confirmationNumber, event.fetchRemote));
- add(UpdateRemainingEvent(getCheckInTime().difference(DateTime.now())));
- add(GetUpSalesEvent());
- emit(state.loaded());
- } catch (e, st) {
- if (kDebugMode) print("err=$e, $st");
- emit(state.setupError());
- }
- });
-
- on<GetKeysEvent>((event, emit) async {
- emit(state.loading());
- await checkMobileKeys(emit);
- emit(state.loaded());
- });
-
- on<PreregisterEvent>((event, emit) async {
- emit(state.loading());
- await getBookingDetails(
- emit,
- booking.confirmationNumber,
- fetchRemote: true,
- hotelCode: booking.hotelCode,
- );
- await getUpSales(emit, fetchRemote: true);
- emit(state.main());
- });
-
- on<CheckInEvent>((event, emit) async {
- emit(state.loading());
- await getBookingDetails(
- emit,
- booking.confirmationNumber,
- fetchRemote: true,
- hotelCode: booking.hotelCode,
- );
- await checkMobileKeys(emit);
- await getUpSales(emit, fetchRemote: true);
- emit(state.main());
- });
-
- on<StartTimerEvent>((event, emit) async {
- _startTimer();
- });
-
- on<GetUpSalesEvent>((event, emit) async {
- try {
- await getUpSales(emit, fetchRemote: true);
- emit(state.main());
- } catch (e) {
- if (kDebugMode) print("err=$e");
- emit(state.setupError());
- }
- });
-
- on<OrderHouseKeepingEvent>((event, emit) async {
- await orderHouseKeeping(emit, event.selectedServices);
- });
-
- on<UpdateRemainingEvent>((event, emit) async {
- await updateRemainingTime(emit);
- });
-
- on<CheckMobileKeys>((event, emit) async {
- await checkMobileKeys(emit);
- });
-
- on<CheckIfHouseKeepingOrdered>((event, emit) async {
- await checkIfHouseKeepingOrdered(emit);
- });
-
- on<UpdateBookingEvent>((event, emit) async {
- await updateBooking(emit, booking, event);
- });
-
- on<GetBookingDetailsEvent>((event, emit) async {
- await getBookingDetails(
- emit,
- event.hmsConfirmationNumber,
- hotelCode: booking.hotelCode,
- fetchRemote: event.fetchRemote,
- );
- });
-
- on<GetUserEvent>((event, emit) async {
- await getUser(emit, fetchRemote: event.fetchRemote);
- });
-
- on<BypassTimerEvent>((event, emit) {
- _timer?.cancel();
- emit(state.updateRemainingTime(const Duration(seconds: -1)));
- });
- }
-
- Future<void> getUpSales(Emitter<BookingDetailsState> emit, {bool fetchRemote = false}) async {
- try {
- if (fetchRemote) {
- final response = await _upSaleRepository.getRemoteUpSales(
- booking.confirmationNumber,
- booking.hotelCode,
- );
- emit(state.getUpSales(response));
- } else {
- final response = await _upSaleRepository.getUpSales(
- booking.confirmationNumber,
- booking.hotelCode,
- );
- emit(state.getUpSales(response));
- }
- } catch (e) {
- if (kDebugMode) print("err=$e");
- emit(state.upSalesError());
- }
- }
-
- Future<Booking> getBookingDetails(
- Emitter<BookingDetailsState> emit,
- String hmsConfirmationNumber, {
- bool fetchRemote = false,
- required String hotelCode,
- }) async {
- emit(state.loading());
- try {
- if (fetchRemote) {
- final bookingDetails = await _bookingDetailsRepository.getRemoteBookingDetails(
- hmsConfirmationNumber,
- hotelCode,
- );
- booking = bookingDetails;
- return booking;
- } else {
- user = await _profileRepository.fetchProfileSettings();
- final bookingDetails = await _bookingDetailsRepository.getBookingDetails(
- hmsConfirmationNumber,
- hotelCode,
- );
- booking = bookingDetails;
-
- return booking;
- }
- } catch (e) {
- if (kDebugMode) print("err=$e");
- emit(state.setupError());
- rethrow;
- }
- }
-
- Future<void> checkMobileKeys(Emitter<BookingDetailsState> emit) async {
- try {
- final isEndPointSetup = await _seosRepository.isEndpointSetup();
- if (isEndPointSetup) {
- final keys = await _seosRepository.refreshKeys();
- emit(state.updateKeys(keys));
- }
- } catch (e) {
- emit(state.setupError());
- }
- }
-
- Future<void> checkIfSetup() async {
- final isSetup = await _seosRepository.isEndpointSetup();
- if (!isSetup) await _seosRepository.startMobilePlugin();
- }
-
- Future<void> provisionKey(String hmsConfirmationNumber, String hotelCode) async {
- await _seosRepository.provisionKey(bookingId: hmsConfirmationNumber, hotelCode: hotelCode);
- }
-
- Future<void> getKeys(String hmsConfirmationNumber, String hotelCode) async {
- final keys = await _seosRepository.refreshKeys();
- debugPrint("keys: $keys");
- if (keys.isEmpty) {
- throw Exception("Could not provision key for this booking");
- }
- }
-
- Future<void> checkIfHouseKeepingOrdered(Emitter<BookingDetailsState> emit) async {
- final isHouseKeepingOrdered = await _houseKeepingRepository.isHousesKeepingOrdered(
- booking.roomNumber,
- );
-
- if (isHouseKeepingOrdered) {
- emit(state.houseKeepingOrdered());
- }
- }
-
- Future<void> orderHouseKeeping(
- Emitter<BookingDetailsState> emit,
- List<String> selectedServices,
- ) async {
- final housekeeping = Housekeeping.toJson(
- booking.hotelCode,
- booking.roomNumber,
- selectedServices
- .map((e) => HouseKeepingService.values.firstWhere((element) => element.name == e))
- .toList(),
- );
- await _houseKeepingRepository.saveHouseKeepingOrdered(housekeeping);
- emit(state.houseKeepingOrdered());
- }
-
- Future<void> updateBooking(
- Emitter<BookingDetailsState> emit,
- Booking booking,
- UpdateBookingEvent event,
- ) async {
- try {
- //TODO: add this when we have the backend
- // await bookingDetailsRepository.updateBooking(event.booking);
- emit(state.updateGuests(event.booking.guests));
- } catch (e) {
- emit(state.setupError());
- }
- }
-
- void _startTimer() {
- _timer?.cancel();
- _timer = Timer.periodic(
- const Duration(seconds: 1),
- (_) => add(UpdateRemainingEvent(getCheckInTime().difference(DateTime.now()))),
- );
- }
-
- @override
- Future<void> close() {
- _timer?.cancel();
- return super.close();
- }
-
- Future<void> updateRemainingTime(Emitter<BookingDetailsState> emit) async {
- final now = DateTime.now();
- _remainingTime = getCheckInTime().difference(now);
-
- emit(state.updateRemainingTime(_remainingTime));
-
- if (_remainingTime.isNegative) {
- _timer?.cancel();
- emit(state.updateRemainingTime(_remainingTime));
- }
- }
-
- String get trimmedBalance {
- final balance = booking.balance;
- if (balance == null) return '';
- if (balance == balance.toInt()) {
- return balance.toInt().toString();
- } else {
- return balance.toStringAsFixed(2);
- }
- }
-
- DateTime getCheckInTime() => booking.startDate.add(const Duration(hours: 15));
-
- bool get canCheckOut {
- final now = DateTime.now();
- final today = DateTime(now.year, now.month, now.day);
- final checkInDate = DateTime(
- booking.startDate.year,
- booking.startDate.month,
- booking.startDate.day,
- );
- final checkOutDate = DateTime(booking.endDate.year, booking.endDate.month, booking.endDate.day);
-
- if (checkInDate == checkOutDate) {
- return false;
- }
-
- return checkOutDate.isBefore(today);
- }
-
- DateTime getCheckOutTime() => booking.endDate.add(const Duration(hours: 5));
-
- bool get isHouseKeepingTime {
- final now = DateTime.now();
- final tomorrow = DateTime(now.year, now.month, now.day + 1);
- final checkoutDay = DateTime(booking.endDate.year, booking.endDate.month, booking.endDate.day);
- if (checkoutDay == tomorrow) return false;
- return booking.endDate.difference(booking.startDate).inDays >= 2;
- }
-
- Future<void> getUser(Emitter<BookingDetailsState> emit, {bool fetchRemote = false}) async {
- user = await _profileRepository.fetchProfileSettings(fetchRemote: fetchRemote);
- }
-}
diff --git a/comwell_key_app/lib/booking_details/bloc/booking_details_cubit.dart b/comwell_key_app/lib/booking_details/bloc/booking_details_cubit.dart
index e57d7f2b..042b15f5 100644
--- a/comwell_key_app/lib/booking_details/bloc/booking_details_cubit.dart
+++ b/comwell_key_app/lib/booking_details/bloc/booking_details_cubit.dart
@@ -1,12 +1,12 @@
import 'dart:async';
-
-import 'package:bloc/bloc.dart';
-import 'package:comwell_key_app/booking_details/bloc/booking_details_bloc.dart';
+import 'package:comwell_key_app/booking_details/bloc/booking_details_state.dart';
import 'package:comwell_key_app/booking_details/booking_details_repository.dart';
+import 'package:comwell_key_app/domain/models/app_error.dart';
import 'package:comwell_key_app/housekeeping/components/housekeeping_service.dart';
import 'package:comwell_key_app/housekeeping/housekeeping_repository.dart';
import 'package:comwell_key_app/housekeeping/models/housekeeping.dart';
import 'package:comwell_key_app/overview/models/booking.dart';
+import 'package:comwell_key_app/presentation/base/base_cubit.dart';
import 'package:comwell_key_app/profile/profile_repository.dart';
import 'package:comwell_key_app/profile_settings/model/user.dart';
import 'package:comwell_key_app/share/share_booking_repository.dart';
@@ -14,7 +14,7 @@ import 'package:comwell_key_app/up_sales/up_sales_repository.dart';
import 'package:comwell_key_app/utils/seos_repository.dart';
import 'package:flutter/foundation.dart';
-class BookingDetailsCubit extends Cubit<BookingDetailsState> {
+class BookingDetailsCubit extends BaseCubit<BookingDetailsState> {
late Booking booking;
User? user;
Timer? _timer;
@@ -34,13 +34,13 @@ class BookingDetailsCubit extends Cubit<BookingDetailsState> {
this._shareBookingRepository,
this._houseKeepingRepository, {
required this.booking,
- }) : super(BookingDetailsState.initial(booking)) {
+ }) : super(const BookingDetailsState()) {
init();
}
Future<void> init() async {
try {
- emit(state.loading());
+ safeEmit(state.copyWith(isLoading: true));
await getUser();
_startTimer();
await checkIfHouseKeepingOrdered();
@@ -53,9 +53,9 @@ class BookingDetailsCubit extends Cubit<BookingDetailsState> {
await updateRemainingTime();
} catch (e) {
if (kDebugMode) print("err=$e");
- emit(state.setupError());
+ safeEmit(state.copyWith(error: AppError.unknown(e.toString())));
} finally {
- emit(state.main());
+ safeEmit(state.copyWith(isLoading: false));
}
}
@@ -66,17 +66,17 @@ class BookingDetailsCubit extends Cubit<BookingDetailsState> {
booking.confirmationNumber,
booking.hotelCode,
);
- emit(state.getUpSales(response));
+ safeEmit(state.copyWith(upSales: response));
} else {
final response = await _upSaleRepository.getUpSales(
booking.confirmationNumber,
booking.hotelCode,
);
- emit(state.getUpSales(response));
+ safeEmit(state.copyWith(upSales: response));
}
} catch (e) {
if (kDebugMode) print("err=$e");
- emit(state.upSalesError());
+ safeEmit(state.copyWith(error: AppError.unknown(e.toString())));
}
}
@@ -85,7 +85,7 @@ class BookingDetailsCubit extends Cubit<BookingDetailsState> {
bool fetchRemote = false,
required String hotelCode,
}) async {
- emit(state.loading());
+ safeEmit(state.copyWith(isLoading: true));
try {
if (fetchRemote) {
final bookingDetails = await _bookingDetailsRepository.getRemoteBookingDetails(
@@ -106,7 +106,7 @@ class BookingDetailsCubit extends Cubit<BookingDetailsState> {
}
} catch (e) {
if (kDebugMode) print("err=$e");
- emit(state.setupError());
+ safeEmit(state.copyWith(error: AppError.unknown(e.toString())));
rethrow;
}
}
@@ -114,19 +114,21 @@ class BookingDetailsCubit extends Cubit<BookingDetailsState> {
Future<void> checkMobileKeys() async {
try {
final isKeyLoadedForBooking = state.keys.any((key) => key.label == booking.roomNumber);
- emit(state.loadingKeys());
+ safeEmit(state.copyWith(isLoadingKeys: true));
await checkIfSetup();
final keys = await _seosRepository.refreshKeys();
- emit(state.updateKeys(keys));
+ safeEmit(state.copyWith(keys: keys));
if (keys.isEmpty || !isKeyLoadedForBooking) {
await _seosRepository.provisionKey(bookingId: booking.id, hotelCode: booking.hotelCode);
final keys = await _seosRepository.refreshKeys();
- emit(state.updateKeys(keys));
+ safeEmit(state.copyWith(keys: keys));
}
} catch (e) {
- emit(state.setupError());
+ safeEmit(state.copyWith(error: AppError.unknown(e.toString())));
+ } finally {
+ safeEmit(state.copyWith(isLoadingKeys: false));
}
}
@@ -141,29 +143,29 @@ class BookingDetailsCubit extends Cubit<BookingDetailsState> {
);
if (isHouseKeepingOrdered) {
- emit(state.houseKeepingOrdered());
+ emit(state.copyWith(isHouseKeepingOrdered: true));
}
}
Future<void> preregisterEvent() async {
try {
- emit(state.loading());
+ safeEmit(state.copyWith(isLoading: true));
await getBookingDetails(
booking.confirmationNumber,
fetchRemote: true,
hotelCode: booking.hotelCode,
);
await getUpSales(fetchRemote: true);
- emit(state.main());
+ safeEmit(state.copyWith(isLoading: false));
} catch (e) {
if (kDebugMode) print("err=$e");
- emit(state.setupError());
+ safeEmit(state.copyWith(error: AppError.unknown(e.toString())));
}
}
Future<void> checkInEvent() async {
try {
- emit(state.loading());
+ safeEmit(state.copyWith(isLoading: true));
await getBookingDetails(
booking.confirmationNumber,
fetchRemote: true,
@@ -171,10 +173,10 @@ class BookingDetailsCubit extends Cubit<BookingDetailsState> {
);
await checkMobileKeys();
await getUpSales(fetchRemote: true);
- emit(state.main());
+ safeEmit(state.copyWith(isLoading: false));
} catch (e) {
if (kDebugMode) print("err=$e");
- emit(state.setupError());
+ safeEmit(state.copyWith(error: AppError.unknown(e.toString())));
}
}
@@ -189,16 +191,16 @@ class BookingDetailsCubit extends Cubit<BookingDetailsState> {
.toList(),
);
await _houseKeepingRepository.saveHouseKeepingOrdered(housekeeping);
- emit(state.houseKeepingOrdered());
+ safeEmit(state.copyWith(isHouseKeepingOrdered: true));
}
Future<void> updateBooking(Booking booking) async {
try {
//TODO: add this when we have the backend
// await bookingDetailsRepository.updateBooking(event.booking);
- emit(state.updateGuests(booking.guests));
+ safeEmit(state.copyWith(guests: booking.guests));
} catch (e) {
- emit(state.setupError());
+ safeEmit(state.copyWith(error: AppError.unknown(e.toString())));
}
}
@@ -220,11 +222,11 @@ class BookingDetailsCubit extends Cubit<BookingDetailsState> {
final now = DateTime.now();
_remainingTime = getCheckInTime().difference(now);
- emit(state.updateRemainingTime(_remainingTime));
+ safeEmit(state.copyWith(remainingTime: _remainingTime));
if (_remainingTime.isNegative) {
_timer?.cancel();
- emit(state.updateRemainingTime(_remainingTime));
+ safeEmit(state.copyWith(remainingTime: _remainingTime));
}
}
@@ -240,7 +242,7 @@ class BookingDetailsCubit extends Cubit<BookingDetailsState> {
void bypassTimer() {
_timer?.cancel();
- emit(state.updateRemainingTime(const Duration(seconds: -1)));
+ safeEmit(state.copyWith(remainingTime: const Duration(seconds: -1)));
}
DateTime getCheckInTime() => booking.startDate.add(const Duration(hours: 15));
diff --git a/comwell_key_app/lib/booking_details/bloc/booking_details_event.dart b/comwell_key_app/lib/booking_details/bloc/booking_details_event.dart
deleted file mode 100644
index 29b59ddb..00000000
--- a/comwell_key_app/lib/booking_details/bloc/booking_details_event.dart
+++ /dev/null
@@ -1,90 +0,0 @@
-part of 'booking_details_bloc.dart';
-
-sealed class BookingDetailsEvent extends Equatable {
- const BookingDetailsEvent();
-
- @override
- List<Object> get props => [];
-}
-
-final class InitialEvent extends BookingDetailsEvent {
- final bool fetchRemote;
-
- const InitialEvent({this.fetchRemote = false});
-
- @override
- List<Object> get props => [fetchRemote];
-}
-
-final class GetUpSalesEvent extends BookingDetailsEvent {}
-
-final class PreregisterEvent extends BookingDetailsEvent {}
-
-final class CheckInEvent extends BookingDetailsEvent {}
-
-final class CheckIfHouseKeepingOrdered extends BookingDetailsEvent {}
-
-final class GetBookingDetailsEvent extends BookingDetailsEvent {
- final String hmsConfirmationNumber;
- final bool fetchRemote;
-
- const GetBookingDetailsEvent(this.hmsConfirmationNumber, this.fetchRemote);
-
- @override
- List<Object> get props => [hmsConfirmationNumber, fetchRemote];
-}
-
-final class StartTimerEvent extends BookingDetailsEvent {}
-
-final class GetUserEvent extends BookingDetailsEvent {
- final bool fetchRemote;
-
- const GetUserEvent(this.fetchRemote);
-
- @override
- List<Object> get props => [fetchRemote];
-}
-
-final class GetKeysEvent extends BookingDetailsEvent {}
-
-final class CheckMobileKeys extends BookingDetailsEvent {}
-
-final class UpdateRemainingEvent extends BookingDetailsEvent {
- final Duration remaining;
-
- const UpdateRemainingEvent(this.remaining);
-
- @override
- List<Object> get props => [remaining];
-}
-
-final class ProvisionKeyEvent extends BookingDetailsEvent {
- final String bookingId;
-
- const ProvisionKeyEvent(this.bookingId);
-
- @override
- List<Object> get props => [bookingId];
-}
-
-final class UpdateBookingEvent extends BookingDetailsEvent {
- final Booking booking;
-
- const UpdateBookingEvent(this.booking);
-
- @override
- List<Object> get props => [booking];
-}
-
-final class OrderHouseKeepingEvent extends BookingDetailsEvent {
- final List<String> selectedServices;
-
- const OrderHouseKeepingEvent(this.selectedServices);
-
- @override
- List<Object> get props => [selectedServices];
-}
-
-final class BypassTimerEvent extends BookingDetailsEvent {
- const BypassTimerEvent();
-}
diff --git a/comwell_key_app/lib/booking_details/bloc/booking_details_state.dart b/comwell_key_app/lib/booking_details/bloc/booking_details_state.dart
index f04a247f..9b982121 100644
--- a/comwell_key_app/lib/booking_details/bloc/booking_details_state.dart
+++ b/comwell_key_app/lib/booking_details/bloc/booking_details_state.dart
@@ -1,110 +1,25 @@
-part of 'booking_details_bloc.dart';
-
-class BookingDetailsState extends Equatable {
- final bool isHouseKeepingOrdered;
- final BookingDetailsStatus status;
- final MobileKeysKey? key;
- final List<MobileKeysKey> keys;
- final List<Guest> guests;
- final Duration remainingTime;
- final bool isLoading;
- final UpSales? upSales;
- final List<Upgrade> selectedUpSales;
-
- const BookingDetailsState._({
- required this.status,
- required this.key,
- required this.keys,
- required this.isHouseKeepingOrdered,
- required this.guests,
- required this.remainingTime,
- required this.isLoading,
- this.upSales,
- required this.selectedUpSales,
- });
-
- BookingDetailsState.initial(Booking booking)
- : this._(
- status: BookingDetailsStatus.initial,
- key: null,
- keys: [],
- isHouseKeepingOrdered: false,
- guests: booking.guests,
- remainingTime: Duration.zero,
- isLoading: false,
- upSales: null,
- selectedUpSales: [],
- );
-
- BookingDetailsState setupError() => copyWith(status: BookingDetailsStatus.setupError);
-
- BookingDetailsState updateKeys(List<MobileKeysKey> keys) =>
- copyWith(status: BookingDetailsStatus.keysUpdated, keys: keys);
-
- BookingDetailsState houseKeepingOrdered() =>
- copyWith(status: BookingDetailsStatus.houseKeepingOrdered, isHouseKeepingOrdered: true);
-
- BookingDetailsState updateGuests(List<Guest> guests) =>
- copyWith(status: BookingDetailsStatus.guestsUpdated, guests: guests);
-
- BookingDetailsState loadingKeys() => copyWith(status: BookingDetailsStatus.loadingKeys);
-
- BookingDetailsState loading() => copyWith(status: BookingDetailsStatus.loading, isLoading: true);
-
- BookingDetailsState loaded() => copyWith(status: BookingDetailsStatus.loaded, isLoading: false);
-
- BookingDetailsState updateRemainingTime(Duration remainingTime) =>
- copyWith(remainingTime: remainingTime);
-
- BookingDetailsState main() => copyWith(status: BookingDetailsStatus.main, isLoading: false);
-
- BookingDetailsState getUpSales(UpSales upSales) => copyWith(upSales: upSales);
-
- BookingDetailsState upSalesError() => copyWith(status: BookingDetailsStatus.upSalesError);
-
- @override
- List<Object?> get props => [status, guests, isLoading, remainingTime, upSales, keys, key];
-
- BookingDetailsState copyWith({
- BookingDetailsStatus? status,
- MobileKeysKey? key,
- List<MobileKeysKey>? keys,
- bool? isHouseKeepingOrdered,
- List<Guest>? guests,
- bool? isLoading,
- Duration? remainingTime,
- UpSales? upSales,
- List<Upgrade>? selectedUpSales,
- }) {
- return BookingDetailsState._(
- status: status ?? this.status,
- key: key ?? this.key,
- keys: keys ?? this.keys,
- isHouseKeepingOrdered: isHouseKeepingOrdered ?? this.isHouseKeepingOrdered,
- guests: guests ?? this.guests,
- isLoading: isLoading ?? this.isLoading,
- remainingTime: remainingTime ?? this.remainingTime,
- upSales: upSales ?? this.upSales,
- selectedUpSales: selectedUpSales ?? this.selectedUpSales,
- );
- }
-
- @override
- String toString() {
- return "BookingDetailsState(status=$status, key=$key, keys=$keys, isHouseKeepingOrdered=$isHouseKeepingOrdered, isLoading=$isLoading, upSales=$upSales)";
- }
+import 'package:comwell_key_app/domain/models/app_error.dart';
+import 'package:comwell_key_app/overview/models/guest.dart';
+import 'package:comwell_key_app/up_sales/models/up_sales.dart';
+import 'package:comwell_key_app/up_sales/models/upgrade.dart';
+import 'package:freezed_annotation/freezed_annotation.dart';
+import 'package:seos_mobile_keys_plugin/app_usage_api.dart';
+
+part '../../.generated/booking_details/bloc/booking_details_state.freezed.dart';
+
+@freezed
+abstract class BookingDetailsState with _$BookingDetailsState {
+ const factory BookingDetailsState({
+ @Default(false) bool isHouseKeepingOrdered,
+ @Default(null) MobileKeysKey? key,
+ @Default([]) List<MobileKeysKey> keys,
+ @Default([]) List<Guest> guests,
+ @Default(Duration.zero) Duration remainingTime,
+ @Default(AppError.none) AppError error,
+ @Default(false) bool isLoading,
+ @Default(false) bool isLoadingKeys,
+ @Default(null) UpSales? upSales,
+ @Default([]) List<Upgrade> selectedUpSales,
+ }) = _BookingDetailsState;
}
-enum BookingDetailsStatus {
- initial,
- loaded,
- setupError,
- keysUpdated,
- guestsUpdated,
- loadingKeys,
- main,
- houseKeepingOrdered,
- loading,
- loadingUpSales,
- upSalesError,
-}
diff --git a/comwell_key_app/lib/booking_details/booking_details_page.dart b/comwell_key_app/lib/booking_details/booking_details_page.dart
index 64431f4f..f2b21896 100644
--- a/comwell_key_app/lib/booking_details/booking_details_page.dart
+++ b/comwell_key_app/lib/booking_details/booking_details_page.dart
@@ -1,4 +1,5 @@
import 'package:comwell_key_app/booking_details/bloc/booking_details_cubit.dart';
+import 'package:comwell_key_app/booking_details/bloc/booking_details_state.dart';
import 'package:comwell_key_app/booking_details/components/booking_details_bottom_sheet.dart';
import 'package:comwell_key_app/booking_details/components/check_in_button_timer.dart';
import 'package:comwell_key_app/booking_details/components/get_keys_button.dart';
@@ -17,7 +18,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import '../.generated/assets/assets.gen.dart';
-import 'bloc/booking_details_bloc.dart';
import 'components/unlock_room_button.dart';
class BookingDetailsPage extends StatelessWidget {
diff --git a/comwell_key_app/lib/booking_details/booking_details_route.dart b/comwell_key_app/lib/booking_details/booking_details_route.dart
index 9dfe7f3d..a7e5e441 100644
--- a/comwell_key_app/lib/booking_details/booking_details_route.dart
+++ b/comwell_key_app/lib/booking_details/booking_details_route.dart
@@ -1,4 +1,3 @@
-import 'package:comwell_key_app/booking_details/bloc/booking_details_bloc.dart';
import 'package:comwell_key_app/booking_details/bloc/booking_details_cubit.dart';
import 'package:comwell_key_app/booking_details/booking_details_page.dart';
import 'package:comwell_key_app/find_booking/loading_page.dart';
diff --git a/comwell_key_app/lib/booking_details/components/booking_details_bottom_sheet.dart b/comwell_key_app/lib/booking_details/components/booking_details_bottom_sheet.dart
index e3be0476..cefa1d8e 100644
--- a/comwell_key_app/lib/booking_details/components/booking_details_bottom_sheet.dart
+++ b/comwell_key_app/lib/booking_details/components/booking_details_bottom_sheet.dart
@@ -1,11 +1,12 @@
-import 'package:comwell_key_app/booking_details/bloc/booking_details_bloc.dart';
import 'package:comwell_key_app/booking_details/bloc/booking_details_cubit.dart';
+import 'package:comwell_key_app/booking_details/bloc/booking_details_state.dart';
import 'package:comwell_key_app/booking_details/components/check_out_button.dart';
import 'package:comwell_key_app/booking_details/components/concierge_button.dart';
import 'package:comwell_key_app/booking_details/components/housekeeping_button.dart';
import 'package:comwell_key_app/booking_details/components/practical_information_button.dart';
import 'package:comwell_key_app/common/components/comwell_error_widget.dart';
import 'package:comwell_key_app/common/components/outlined_pill_button.dart';
+import 'package:comwell_key_app/domain/models/app_error.dart';
import 'package:comwell_key_app/overview/models/booking.dart';
import 'package:comwell_key_app/profile/components/comwell_club_container.dart';
import 'package:comwell_key_app/routing/app_routes.dart';
@@ -156,7 +157,7 @@ class BookingDetailsBottomSheet extends StatelessWidget {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
- state.status == BookingDetailsStatus.upSalesError
+ state.error != AppError.none
? Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
diff --git a/comwell_key_app/lib/booking_details/components/check_in_button.dart b/comwell_key_app/lib/booking_details/components/check_in_button.dart
index 41f372b4..24c11ae9 100644
--- a/comwell_key_app/lib/booking_details/components/check_in_button.dart
+++ b/comwell_key_app/lib/booking_details/components/check_in_button.dart
@@ -4,10 +4,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/svg.dart';
import 'package:go_router/go_router.dart';
-
import '../../routing/app_routes.dart';
import '../../themes/dark_theme.dart';
-import '../bloc/booking_details_bloc.dart';
class CheckInButton extends StatelessWidget {
const CheckInButton({super.key});
diff --git a/comwell_key_app/lib/booking_details/components/check_in_button_timer.dart b/comwell_key_app/lib/booking_details/components/check_in_button_timer.dart
index d6f6ae2e..3bfcb9d7 100644
--- a/comwell_key_app/lib/booking_details/components/check_in_button_timer.dart
+++ b/comwell_key_app/lib/booking_details/components/check_in_button_timer.dart
@@ -1,6 +1,6 @@
import 'package:comwell_key_app/.generated/assets/assets.gen.dart';
-import 'package:comwell_key_app/booking_details/bloc/booking_details_bloc.dart';
import 'package:comwell_key_app/booking_details/bloc/booking_details_cubit.dart';
+import 'package:comwell_key_app/booking_details/bloc/booking_details_state.dart';
import 'package:comwell_key_app/booking_details/components/check_in_button.dart';
import 'package:comwell_key_app/themes/light_theme.dart';
import 'package:comwell_key_app/utils/l10n_utils.dart';
diff --git a/comwell_key_app/lib/booking_details/components/check_out_button.dart b/comwell_key_app/lib/booking_details/components/check_out_button.dart
index 62c0a92d..2b154ada 100644
--- a/comwell_key_app/lib/booking_details/components/check_out_button.dart
+++ b/comwell_key_app/lib/booking_details/components/check_out_button.dart
@@ -1,4 +1,3 @@
-import 'package:comwell_key_app/booking_details/bloc/booking_details_bloc.dart';
import 'package:comwell_key_app/booking_details/bloc/booking_details_cubit.dart';
import 'package:comwell_key_app/routing/app_routes.dart';
import 'package:comwell_key_app/themes/light_theme.dart';
diff --git a/comwell_key_app/lib/booking_details/components/get_keys_button.dart b/comwell_key_app/lib/booking_details/components/get_keys_button.dart
index 023291c6..02906c4a 100644
--- a/comwell_key_app/lib/booking_details/components/get_keys_button.dart
+++ b/comwell_key_app/lib/booking_details/components/get_keys_button.dart
@@ -1,12 +1,10 @@
-import 'package:comwell_key_app/booking_details/bloc/booking_details_bloc.dart';
import 'package:comwell_key_app/booking_details/bloc/booking_details_cubit.dart';
-import 'package:comwell_key_app/routing/app_routes.dart';
+import 'package:comwell_key_app/booking_details/bloc/booking_details_state.dart';
import 'package:comwell_key_app/themes/dark_theme.dart';
import 'package:comwell_key_app/utils/l10n_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/svg.dart';
-import 'package:go_router/go_router.dart';
class GetKeysButton extends StatelessWidget {
const GetKeysButton({super.key});
@@ -17,7 +15,7 @@ class GetKeysButton extends StatelessWidget {
builder: (context, state) {
final cubit = context.read<BookingDetailsCubit>();
final theme = Theme.of(context);
- if (state.status == BookingDetailsStatus.loadingKeys) {
+ if (state.isLoadingKeys) {
return const Center(
child: CircularProgressIndicator(
color: sandColor,
diff --git a/comwell_key_app/lib/booking_details/components/housekeeping_button.dart b/comwell_key_app/lib/booking_details/components/housekeeping_button.dart
index 1cf07b03..6bc2a08f 100644
--- a/comwell_key_app/lib/booking_details/components/housekeeping_button.dart
+++ b/comwell_key_app/lib/booking_details/components/housekeeping_button.dart
@@ -9,7 +9,6 @@ import 'package:flutter_svg/svg.dart';
import 'package:go_router/go_router.dart';
import '../../routing/app_routes.dart';
-import '../bloc/booking_details_bloc.dart';
class HousekeepingButton extends StatelessWidget {
final Booking booking;
diff --git a/comwell_key_app/lib/booking_details/components/preregister_button.dart b/comwell_key_app/lib/booking_details/components/preregister_button.dart
index 71456a42..c8fb6f9a 100644
--- a/comwell_key_app/lib/booking_details/components/preregister_button.dart
+++ b/comwell_key_app/lib/booking_details/components/preregister_button.dart
@@ -7,7 +7,6 @@ import 'package:go_router/go_router.dart';
import '../../routing/app_routes.dart';
import '../../themes/dark_theme.dart';
-import '../bloc/booking_details_bloc.dart';
class PreregisterButton extends StatelessWidget {
const PreregisterButton({super.key});
diff --git a/comwell_key_app/lib/booking_details/components/share_button.dart b/comwell_key_app/lib/booking_details/components/share_button.dart
index 8d41cfff..3ce87a91 100644
--- a/comwell_key_app/lib/booking_details/components/share_button.dart
+++ b/comwell_key_app/lib/booking_details/components/share_button.dart
@@ -1,4 +1,3 @@
-import 'package:comwell_key_app/booking_details/bloc/booking_details_bloc.dart';
import 'package:comwell_key_app/booking_details/bloc/booking_details_cubit.dart';
import 'package:comwell_key_app/common/components/comwell_error_widget.dart';
import 'package:comwell_key_app/overview/models/booking.dart';
diff --git a/comwell_key_app/lib/my_booking/my_booking_page.dart b/comwell_key_app/lib/my_booking/my_booking_page.dart
index 3c290925..17535085 100644
--- a/comwell_key_app/lib/my_booking/my_booking_page.dart
+++ b/comwell_key_app/lib/my_booking/my_booking_page.dart
@@ -1,11 +1,10 @@
-import 'package:comwell_key_app/booking_details/bloc/booking_details_bloc.dart';
+
import 'package:comwell_key_app/booking_details/bloc/booking_details_cubit.dart';
import 'package:comwell_key_app/booking_details/components/share_button.dart';
import 'package:comwell_key_app/common/components/comwell_app_bar.dart';
import 'package:comwell_key_app/my_booking/cubit/my_booking_cubit.dart';
import 'package:comwell_key_app/my_booking/cubit/my_booking_state.dart';
import 'package:comwell_key_app/overview/models/booking.dart';
-import 'package:comwell_key_app/profile/profile_repository.dart';
import 'package:comwell_key_app/routing/app_routes.dart';
import 'package:comwell_key_app/services/mappers/booking_mapper.dart';
import 'package:comwell_key_app/themes/light_theme.dart';
diff --git a/comwell_key_app/lib/presentation/screens/concierge/bloc/concierge_state.dart b/comwell_key_app/lib/presentation/screens/concierge/bloc/concierge_state.dart
index 8ec2ab87..b721ac41 100644
--- a/comwell_key_app/lib/presentation/screens/concierge/bloc/concierge_state.dart
+++ b/comwell_key_app/lib/presentation/screens/concierge/bloc/concierge_state.dart
@@ -10,6 +10,4 @@ abstract class ConciergeState with _$ConciergeState {
@Default(AppError.none) AppError error,
@Default("") String userToken,
}) = _ConciergeState;
-
-
}
\ No newline at end of file
diff --git a/comwell_key_app/test/booking_details_test/booking_details_bloc_test.dart b/comwell_key_app/test/booking_details_test/booking_details_bloc_test.dart
deleted file mode 100644
index 287c77f5..00000000
--- a/comwell_key_app/test/booking_details_test/booking_details_bloc_test.dart
+++ /dev/null
@@ -1,67 +0,0 @@
-// Import necessary testing packages, bloc, and mocktail
-import 'package:comwell_key_app/booking_details/bloc/booking_details_bloc.dart';
-import 'package:comwell_key_app/booking_details/booking_details_repository.dart';
-import 'package:comwell_key_app/check_in/check_in_repository.dart';
-import 'package:comwell_key_app/housekeeping/housekeeping_repository.dart';
-import 'package:comwell_key_app/profile/profile_repository.dart';
-import 'package:comwell_key_app/share/share_booking_repository.dart';
-import 'package:comwell_key_app/up_sales/up_sales_repository.dart';
-import 'package:comwell_key_app/utils/locator.dart';
-import 'package:comwell_key_app/utils/seos_repository.dart';
-import 'package:flutter_test/flutter_test.dart';
-import 'package:bloc_test/bloc_test.dart';
-import 'package:mocktail/mocktail.dart';
-
-import '../overview_test/overview_cubic_test.dart';
-
-class MockBookingDetailsRepository extends Mock implements BookingDetailsRepository {}
-
-class MockProfileRepository extends Mock implements ProfileRepository {}
-
-class MockSeosRepository extends Mock implements SeosRepository {}
-
-class MockUpSalesRepository extends Mock implements UpSalesRepository {}
-
-class MockHouseKeepingRepository extends Mock implements HouseKeepingRepository {}
-
-void main() {
- // Declare the mock HomeRepository
- late BookingDetailsRepository mockBookingDetailsRepository;
- late ProfileRepository mockProfileRepository;
- late UpSalesRepository mockUpSalesRepository;
- late HouseKeepingRepository mockHouseKeepingRepository;
- late SeosRepository mockSeosRepository;
- late ShareBookingRepository mockShareBookingRepository;
- // Setup function runs before every test
- setUp(() {
- // Initialize the mock HomeRepository
- mockBookingDetailsRepository = MockBookingDetailsRepository();
- mockProfileRepository = MockProfileRepository();
- mockUpSalesRepository = MockUpSalesRepository();
- mockHouseKeepingRepository = MockHouseKeepingRepository();
- mockSeosRepository = MockSeosRepository();
- mockShareBookingRepository = MockShareBookingRepository();
- setupLocator();
- });
-
- // Example test for HomeInitialEvent
- blocTest<BookingDetailsBloc, BookingDetailsState>(
- 'emits [ValidKey] when HomeInitialEvent is added and one key is returned',
- build: () {
- // Return bloc with mocked repository
- return BookingDetailsBloc(
- booking: CheckInRepository.mockBooking,
- mockBookingDetailsRepository,
- mockProfileRepository,
- mockSeosRepository,
- mockUpSalesRepository,
- mockShareBookingRepository,
- mockHouseKeepingRepository,
- );
- },
- act: (bloc) => bloc.add(const InitialEvent()),
- // expect: () => [isA<ValidKey>()], // Expecting ValidKey state to be emitted
- );
-
- // Add more tests for other scenarios and events...
-}