6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit 3a750e01
Changed files
comwell_key_app/lib/data/remote/msal_service.dart | 27 +++++++++++++++++++++- comwell_key_app/lib/overview/models/booking.dart | 1 + .../bloc/booking_details_cubit.dart | 3 ++- .../booking_details/booking_details_page.dart | 10 +++++--- .../components/booking_details_bottom_sheet.dart | 1 + .../pregistration/cubit/preregistration_cubit.dart | 6 ++--- .../pregistration/pages/prereg_profile_page.dart | 2 +- 7 files changed, 41 insertions(+), 9 deletions(-)
Diff
diff --git a/comwell_key_app/lib/data/remote/msal_service.dart b/comwell_key_app/lib/data/remote/msal_service.dart
index 0942332d..cf2d1e3d 100644
--- a/comwell_key_app/lib/data/remote/msal_service.dart
+++ b/comwell_key_app/lib/data/remote/msal_service.dart
@@ -5,6 +5,8 @@ import 'package:flutter/services.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:msal_auth/msal_auth.dart';
+const _msalChannel = MethodChannel('msal_auth');
+
class MSALService {
final scopes = dotenv.ENTRA_SCOPES.split(',');
final authorityUrl = dotenv.ENTRA_ID_AUTHORITY_URL;
@@ -36,11 +38,33 @@ class MSALService {
authority: authorityUrl,
),
);
+ await _clearStaleAccounts();
} catch (e) {
print("qqq msauth init=$e");
}
}
+ /// Removes all cached accounts from the MSAL keychain cache.
+ /// This prevents the "Multiple accounts found in cache" error
+ /// that breaks SingleAccountPca on iOS.
+ Future<void> _clearStaleAccounts() async {
+ try {
+ final result = await _msalChannel.invokeMethod('getAccounts');
+ if (result is List && result.length > 1) {
+ for (final account in result) {
+ final id = (account as Map)['id'] as String?;
+ if (id != null) {
+ try {
+ await _msalChannel.invokeMethod('removeAccount', id);
+ } catch (_) {}
+ }
+ }
+ }
+ } catch (e) {
+ print('qqq _clearStaleAccounts: $e');
+ }
+ }
+
Future<void> openAuth(Prompt prompt) async {
try {
await msAuth.acquireToken(
@@ -73,9 +97,10 @@ class MSALService {
Future<void> logout() async {
await _comwellPreferences.setIsLoggedIn(false);
try {
+ await _clearStaleAccounts();
await msAuth.signOut();
} catch (e) {
- // Ignore sign-out errors when there is no active account or sign-out fails
+ // Ignore sign-out errors
}
}
}
diff --git a/comwell_key_app/lib/overview/models/booking.dart b/comwell_key_app/lib/overview/models/booking.dart
index 48c07503..02b9aff4 100644
--- a/comwell_key_app/lib/overview/models/booking.dart
+++ b/comwell_key_app/lib/overview/models/booking.dart
@@ -154,6 +154,7 @@ enum ReservationStatus {
noshow,
newreservation,
preregistered,
+ preregistrationfinalized,
unknown;
static ReservationStatus fromString(String value) {
diff --git a/comwell_key_app/lib/presentation/screens/booking_details/bloc/booking_details_cubit.dart b/comwell_key_app/lib/presentation/screens/booking_details/bloc/booking_details_cubit.dart
index 5503364b..bf0a9fad 100644
--- a/comwell_key_app/lib/presentation/screens/booking_details/bloc/booking_details_cubit.dart
+++ b/comwell_key_app/lib/presentation/screens/booking_details/bloc/booking_details_cubit.dart
@@ -51,7 +51,8 @@ class BookingDetailsCubit extends BaseCubit<BookingDetailsState> {
fetchRemote: true,
);
if (booking.reservationStatus == ReservationStatus.newreservation ||
- booking.reservationStatus == ReservationStatus.preregistered) {
+ booking.reservationStatus == ReservationStatus.preregistered ||
+ booking.reservationStatus == ReservationStatus.preregistrationfinalized) {
await getUpSales(fetchRemote: true);
}
await updateRemainingTime();
diff --git a/comwell_key_app/lib/presentation/screens/booking_details/booking_details_page.dart b/comwell_key_app/lib/presentation/screens/booking_details/booking_details_page.dart
index f71162a9..58c77154 100644
--- a/comwell_key_app/lib/presentation/screens/booking_details/booking_details_page.dart
+++ b/comwell_key_app/lib/presentation/screens/booking_details/booking_details_page.dart
@@ -58,7 +58,9 @@ class BookingDetailsPage extends StatelessWidget {
) {
final theme = Theme.of(context);
final screenHeight = MediaQuery.of(context).size.height;
- final isPreregistered = cubit.booking.reservationStatus == ReservationStatus.preregistered;
+ final isPreregistered =
+ cubit.booking.reservationStatus == ReservationStatus.preregistered ||
+ cubit.booking.reservationStatus == ReservationStatus.preregistrationfinalized;
final isCheckedIn = cubit.booking.reservationStatus == ReservationStatus.checkedin;
final isPrimaryGuest = cubit.booking.isPrimaryGuest;
final shouldShowShareButton = isPrimaryGuest && isCheckedIn || isPreregistered;
@@ -205,6 +207,9 @@ class _ScrollableBookingContentState extends State<_ScrollableBookingContent> {
final isKeyLoadedForBooking = keys.any((key) => key.label == widget.cubit.booking.roomNumber);
final isKeysEmpty = keys.isEmpty;
final hasRoomNumber = widget.cubit.booking.roomNumber != '';
+ final isPreregistered =
+ widget.cubit.booking.reservationStatus == ReservationStatus.preregistered ||
+ widget.cubit.booking.reservationStatus == ReservationStatus.preregistrationfinalized;
return NotificationListener<ScrollNotification>(
onNotification: (notification) {
@@ -235,8 +240,7 @@ class _ScrollableBookingContentState extends State<_ScrollableBookingContent> {
UnlockRoomButton(roomNumber: widget.cubit.booking.roomNumber)
else if (widget.cubit.booking.reservationStatus == ReservationStatus.checkedin)
const GetKeysButton()
- else if (widget.cubit.booking.reservationStatus ==
- ReservationStatus.preregistered)
+ else if (isPreregistered)
CheckInButtonTimer(
buyEarlyCheckin: () async {
final earlyCheckin = widget.cubit.state.upSales?.addOnUpgrades
diff --git a/comwell_key_app/lib/presentation/screens/booking_details/components/booking_details_bottom_sheet.dart b/comwell_key_app/lib/presentation/screens/booking_details/components/booking_details_bottom_sheet.dart
index 9830155a..92082a38 100644
--- a/comwell_key_app/lib/presentation/screens/booking_details/components/booking_details_bottom_sheet.dart
+++ b/comwell_key_app/lib/presentation/screens/booking_details/components/booking_details_bottom_sheet.dart
@@ -141,6 +141,7 @@ class BookingDetailsBottomSheet extends StatelessWidget {
case ReservationStatus.newreservation:
return _buildServices(context);
case ReservationStatus.preregistered:
+ case ReservationStatus.preregistrationfinalized:
return _buildServices(context);
case ReservationStatus.cancelled:
return const SizedBox();
diff --git a/comwell_key_app/lib/presentation/screens/pregistration/cubit/preregistration_cubit.dart b/comwell_key_app/lib/presentation/screens/pregistration/cubit/preregistration_cubit.dart
index 86784b7e..950e8dcf 100644
--- a/comwell_key_app/lib/presentation/screens/pregistration/cubit/preregistration_cubit.dart
+++ b/comwell_key_app/lib/presentation/screens/pregistration/cubit/preregistration_cubit.dart
@@ -291,8 +291,8 @@ class PreregistrationCubit extends BaseCubit<PreregistrationState> {
emit(state.copyWith(countryCode: country, selectedCountry: country.code ?? ''));
}
- void onNationalitySelected(CountryCode nationality) {
- selectedNationality = nationality.name ?? '';
+ void onNationalitySelected(String nationality) {
+ selectedNationality = nationality;
emit(state.copyWith(selectedNationality: selectedNationality));
}
@@ -408,7 +408,7 @@ class PreregistrationCubit extends BaseCubit<PreregistrationState> {
DateTime get validBirthDate => DateTime.now().subtract(const Duration(days: 365 * 18));
- bool get isFavoriteCountry => favoriteCountries.contains(selectedCountry);
+ bool get isFavoriteCountry => favoriteCountries.contains(selectedNationality);
bool get canContinue {
int page = pageController.page?.ceil() ?? 0;
diff --git a/comwell_key_app/lib/presentation/screens/pregistration/pages/prereg_profile_page.dart b/comwell_key_app/lib/presentation/screens/pregistration/pages/prereg_profile_page.dart
index b9fa5ca4..ed26ea44 100644
--- a/comwell_key_app/lib/presentation/screens/pregistration/pages/prereg_profile_page.dart
+++ b/comwell_key_app/lib/presentation/screens/pregistration/pages/prereg_profile_page.dart
@@ -158,7 +158,7 @@ class PreregProfilePage extends StatelessWidget {
showCountryOnly: true,
showOnlyCountryWhenClosed: true,
onChanged: (CountryCode countryCode) {
- cubit.onNationalitySelected(countryCode);
+ cubit.onNationalitySelected(countryCode.code ?? '');
},
),
),