diff --git a/ios/Runner/ring_30Sec.mp3 b/ios/Runner/ring_30Sec.mp3 new file mode 100644 index 00000000..b5bb4b88 Binary files /dev/null and b/ios/Runner/ring_30Sec.mp3 differ diff --git a/lib/core/app_state.dart b/lib/core/app_state.dart index b95b883f..274d37f4 100644 --- a/lib/core/app_state.dart +++ b/lib/core/app_state.dart @@ -175,4 +175,47 @@ class AppState { setRatedVisible(bool value) { isRatedVisible = value; } + + // Dynamic object to track user switch payloads + Map _userSwitchPayloads = {}; + int _childSwitchCounter = 0; + + Map 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; + } } diff --git a/lib/features/authentication/authentication_repo.dart b/lib/features/authentication/authentication_repo.dart index 1271f467..74717b8d 100644 --- a/lib/features/authentication/authentication_repo.dart +++ b/lib/features/authentication/authentication_repo.dart @@ -212,56 +212,6 @@ class AuthenticationRepoImp implements AuthenticationRepo { int? patientID, int? loginType}) async { AppState appState = getIt.get(); - // 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 familyRequest = {}; - // if (isFormFamilyFile) { - // AppState appState = getIt.get(); - // 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 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) { newRequest["activationCode"] = activationCode ?? "0000"; @@ -330,19 +280,38 @@ class AuthenticationRepoImp implements AuthenticationRepo { ? ApiConsts.checkActivationCodeOthers : ApiConsts.checkActivationCode; + // Store the payload in AppState + try { GenericApiModel? apiResponse; Failure? failure; + // Determine the payload to send + final requestBody = isFormFamilyFile + ? familyRequest + : isRegister + ? newRequest + : isSwitchUser + ? switchRequest + : 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: isFormFamilyFile - ? familyRequest - : isRegister - ? newRequest - : isSwitchUser - ? switchRequest - : newRequest.toJson(), + body: requestBody, onFailure: (error, statusCode, {messageStatus, failureType}) { failure = failureType; },