diff --git a/lib/core/app_state.dart b/lib/core/app_state.dart index a5a8d72a..d02aa946 100644 --- a/lib/core/app_state.dart +++ b/lib/core/app_state.dart @@ -249,4 +249,18 @@ class AppState { _userSwitchPayloads.clear(); _childSwitchCounter = 0; } + + void clearChildUsersKeepSuperUser() { + // Keep the super user payload + final superUserPayload = _userSwitchPayloads['superUser']; + + // Clear all payloads + _userSwitchPayloads.clear(); + _childSwitchCounter = 0; + + // Restore super user if it existed + if (superUserPayload != null) { + _userSwitchPayloads['superUser'] = superUserPayload; + } + } } diff --git a/lib/features/authentication/authentication_repo.dart b/lib/features/authentication/authentication_repo.dart index 39d8e3ee..c355819e 100644 --- a/lib/features/authentication/authentication_repo.dart +++ b/lib/features/authentication/authentication_repo.dart @@ -314,7 +314,7 @@ class AuthenticationRepoImp implements AuthenticationRepo { requestBody['PatientIdentificationID'] = ""; requestBody.removeWhere((key, value) => ['NationalID', 'isDentalAllowedBackend', 'ForRegisteration'].contains(key)); appState.setIsChildLoggedIn = false; - appState.clearUserSwitchPayloads(); + appState.clearChildUsersKeepSuperUser(); } } else { appState.setIsChildLoggedIn = true; diff --git a/lib/features/authentication/authentication_view_model.dart b/lib/features/authentication/authentication_view_model.dart index 7e753722..733118ca 100644 --- a/lib/features/authentication/authentication_view_model.dart +++ b/lib/features/authentication/authentication_view_model.dart @@ -641,8 +641,8 @@ class AuthenticationViewModel extends ChangeNotifier { _appState.addUserSwitchPayload(activation.list!.first.toJson(), isSuperUser: true); } } else { - _appState.setSuperUserID = _appState.getAuthenticatedUser()?.patientId; - // _appState.setIsChildLoggedIn = false; + var allUsersPayload = _appState.getUserSwitchPayloads; + _appState.setSuperUserID = allUsersPayload['superUser']?['PatientID']; activation.list!.first.isParentUser = true; _appState.addUserSwitchPayload(activation.list!.first.toJson(), isSuperUser: true); } diff --git a/lib/presentation/my_family/widget/family_cards.dart b/lib/presentation/my_family/widget/family_cards.dart index 39344f30..3a647674 100644 --- a/lib/presentation/my_family/widget/family_cards.dart +++ b/lib/presentation/my_family/widget/family_cards.dart @@ -319,7 +319,6 @@ class _FamilyCardsState extends State { final profile = widget.profileViewList![index]; final isActive = (profile.responseId == appState.getAuthenticatedUser()?.patientId); final isParentUser = appState.getAuthenticatedUser()?.isParentUser ?? false; - print(jsonEncode(appState.getUserSwitchPayloads)); final isSuperUser = appState.getUserSwitchPayloads; // TODO: canSwitch functionality is currently disabled - set to true to allow all switches // Original logic: final canSwitch = isParentUser || (!isParentUser && profile.responseId == appState.getSuperUserID);