switch user #221

Merged
Haroon6138 merged 4 commits from dev_aamir into master 2 days ago

@ -249,4 +249,18 @@ class AppState {
_userSwitchPayloads.clear(); _userSwitchPayloads.clear();
_childSwitchCounter = 0; _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;
}
}
} }

@ -314,7 +314,7 @@ class AuthenticationRepoImp implements AuthenticationRepo {
requestBody['PatientIdentificationID'] = ""; requestBody['PatientIdentificationID'] = "";
requestBody.removeWhere((key, value) => ['NationalID', 'isDentalAllowedBackend', 'ForRegisteration'].contains(key)); requestBody.removeWhere((key, value) => ['NationalID', 'isDentalAllowedBackend', 'ForRegisteration'].contains(key));
appState.setIsChildLoggedIn = false; appState.setIsChildLoggedIn = false;
appState.clearUserSwitchPayloads(); appState.clearChildUsersKeepSuperUser();
} }
} else { } else {
appState.setIsChildLoggedIn = true; appState.setIsChildLoggedIn = true;

@ -641,8 +641,8 @@ class AuthenticationViewModel extends ChangeNotifier {
_appState.addUserSwitchPayload(activation.list!.first.toJson(), isSuperUser: true); _appState.addUserSwitchPayload(activation.list!.first.toJson(), isSuperUser: true);
} }
} else { } else {
_appState.setSuperUserID = _appState.getAuthenticatedUser()?.patientId; var allUsersPayload = _appState.getUserSwitchPayloads;
// _appState.setIsChildLoggedIn = false; _appState.setSuperUserID = allUsersPayload['superUser']?['PatientID'];
activation.list!.first.isParentUser = true; activation.list!.first.isParentUser = true;
_appState.addUserSwitchPayload(activation.list!.first.toJson(), isSuperUser: true); _appState.addUserSwitchPayload(activation.list!.first.toJson(), isSuperUser: true);
} }

@ -319,7 +319,6 @@ class _FamilyCardsState extends State<FamilyCards> {
final profile = widget.profileViewList![index]; final profile = widget.profileViewList![index];
final isActive = (profile.responseId == appState.getAuthenticatedUser()?.patientId); final isActive = (profile.responseId == appState.getAuthenticatedUser()?.patientId);
final isParentUser = appState.getAuthenticatedUser()?.isParentUser ?? false; final isParentUser = appState.getAuthenticatedUser()?.isParentUser ?? false;
print(jsonEncode(appState.getUserSwitchPayloads));
final isSuperUser = appState.getUserSwitchPayloads; final isSuperUser = appState.getUserSwitchPayloads;
// TODO: canSwitch functionality is currently disabled - set to true to allow all switches // TODO: canSwitch functionality is currently disabled - set to true to allow all switches
// Original logic: final canSwitch = isParentUser || (!isParentUser && profile.responseId == appState.getSuperUserID); // Original logic: final canSwitch = isParentUser || (!isParentUser && profile.responseId == appState.getSuperUserID);

Loading…
Cancel
Save