family file switch back multi

pull/210/head
aamir-csol 3 days ago
parent 38471a773c
commit 2a8f67bba1

Binary file not shown.

@ -175,4 +175,47 @@ class AppState {
setRatedVisible(bool value) { setRatedVisible(bool value) {
isRatedVisible = value; isRatedVisible = value;
} }
// Dynamic object to track user switch payloads
Map<String, dynamic> _userSwitchPayloads = {};
int _childSwitchCounter = 0;
Map<String, dynamic> get getUserSwitchPayloads => _userSwitchPayloads;
void addUserSwitchPayload(dynamic payload, {bool isSuperUser = false}) {
if (isSuperUser) {
_userSwitchPayloads['superUser'] = payload;
_childSwitchCounter = 0; // Reset counter when super user is set
} else {
_childSwitchCounter++;
if (_childSwitchCounter == 1) {
_userSwitchPayloads['child'] = payload;
} else {
_userSwitchPayloads['child$_childSwitchCounter'] = payload;
}
}
}
dynamic getUserSwitchPayload({required String userType}) {
return _userSwitchPayloads[userType];
}
dynamic getUserSwitchPayloadByIndex({bool isSuperUser = false, int? childIndex}) {
if (isSuperUser) {
return _userSwitchPayloads['superUser'];
} else if (childIndex != null) {
if (childIndex == 1) {
return _userSwitchPayloads['child'];
} else {
return _userSwitchPayloads['child$childIndex'];
}
}
return null;
}
void clearUserSwitchPayloads() {
_userSwitchPayloads.clear();
_childSwitchCounter = 0;
}
} }

@ -212,56 +212,6 @@ class AuthenticationRepoImp implements AuthenticationRepo {
int? patientID, int? patientID,
int? loginType}) async { int? loginType}) async {
AppState appState = getIt.get<AppState>(); AppState appState = getIt.get<AppState>();
// if (isRegister) {
// newRequest["activationCode"] = activationCode ?? "0000";
// newRequest["isSilentLogin"] = activationCode != null ? false : true;
// } else {
// newRequest.activationCode = activationCode ?? "0000";
// newRequest.isSilentLogin = activationCode != null ? false : true;
// newRequest.projectOutSA = newRequest.zipCode == '966' ? false : true;
// newRequest.isDentalAllowedBackend = false;
// newRequest.forRegisteration = newRequest.isRegister ?? false;
// newRequest.isRegister = false;
// }
// Map<String, dynamic> familyRequest = {};
// if (isFormFamilyFile) {
// AppState appState = getIt.get<AppState>();
// familyRequest = {};
// familyRequest['PatientShareRequestID'] = patientShareRequestID;
// familyRequest['ResponseID'] = responseID;
// familyRequest['Status'] = 3;
// familyRequest["PatientID"] = appState.getAuthenticatedUser()!.patientId ?? 0;
// familyRequest["LogInTokenID"] = appState.getFamilyFileTokenID;
// familyRequest["activationCode"] = activationCode ?? "0000";
// familyRequest["PatientMobileNumber"] = newRequest.patientMobileNumber;
// familyRequest["PatientIdentificationID"] = newRequest.patientIdentificationID;
// }
// Map<String, dynamic> switchRequest = {};
// if (isSwitchUser) {
// switchRequest = newRequest.toJson();
//
// switchRequest['PatientID'] = responseID;
// switchRequest['IsSilentLogin'] = true;
// switchRequest['LogInTokenID'] = null;
// switchRequest['SearchType'] = 2;
// if (loginType != 0) {
// switchRequest['SuperUser'] = patientID;
// switchRequest['DeviceToken'] = null;
// } else {
// switchRequest["LoginType"] = 2;
// }
//
// if (appState.getSuperUserID == responseID) {
// // switchRequest['LoginType'] = 3;
// switchRequest['PatientIdentificationID'] = "";
// // switchRequest['ProjectOutSA'] = newRequest.zipCode == '966' ? false : true;
// switchRequest.remove('NationalID');
// switchRequest.remove('isDentalAllowedBackend');
// switchRequest.remove('ProjectOutSA');
// switchRequest.remove('ForRegisteration');
// appState.setSuperUserID = null;
// }
// }
if (isRegister) { if (isRegister) {
newRequest["activationCode"] = activationCode ?? "0000"; newRequest["activationCode"] = activationCode ?? "0000";
@ -330,19 +280,38 @@ class AuthenticationRepoImp implements AuthenticationRepo {
? ApiConsts.checkActivationCodeOthers ? ApiConsts.checkActivationCodeOthers
: ApiConsts.checkActivationCode; : ApiConsts.checkActivationCode;
// Store the payload in AppState
try { try {
GenericApiModel<dynamic>? apiResponse; GenericApiModel<dynamic>? apiResponse;
Failure? failure; Failure? failure;
await apiClient.post( // Determine the payload to send
endpoint, final requestBody = isFormFamilyFile
body: isFormFamilyFile
? familyRequest ? familyRequest
: isRegister : isRegister
? newRequest ? newRequest
: isSwitchUser : isSwitchUser
? switchRequest ? switchRequest
: newRequest.toJson(), : newRequest.toJson();
if (!isSwitchUser) {
print("Initial Super User Payload");
appState.addUserSwitchPayload(requestBody, isSuperUser: true);
} else if (isSwitchUser) {
print("Switch Into First Family File");
appState.addUserSwitchPayload(requestBody, isSuperUser: false);
} else if (appState.getSuperUserID == responseID) {
print("Switching Back to Super User");
// appState.addUserSwitchPayload(requestBody, isSuperUser: true);
} else if (isSwitchUser && appState.getSuperUserID == responseID) {
print("Switching Into Child User 1");
// appState.addUserSwitchPayload(requestBody);
}
await apiClient.post(
endpoint,
body: requestBody,
onFailure: (error, statusCode, {messageStatus, failureType}) { onFailure: (error, statusCode, {messageStatus, failureType}) {
failure = failureType; failure = failureType;
}, },

Loading…
Cancel
Save