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 7d3ab1a4..a5a8d72a 100644 --- a/lib/core/app_state.dart +++ b/lib/core/app_state.dart @@ -175,4 +175,78 @@ class AppState { setRatedVisible(bool value) { isRatedVisible = value; } + + Map _userSwitchPayloads = {}; + int _childSwitchCounter = 0; + + Map get getUserSwitchPayloads => _userSwitchPayloads; + + void addUserSwitchPayload(dynamic payload, {bool isSuperUser = false}) { + var patientID = payload is Map ? payload['patientid'] : null; + + if (patientID == null) { + if (isSuperUser) { + _userSwitchPayloads['superUser'] = payload; + _childSwitchCounter = 0; + } else { + _childSwitchCounter++; + if (_childSwitchCounter == 1) { + _userSwitchPayloads['child'] = payload; + } else { + _userSwitchPayloads['child$_childSwitchCounter'] = payload; + } + } + return; + } + + String? existingKey; + for (var entry in _userSwitchPayloads.entries) { + if (entry.value is Map && entry.value['PatientID'] == patientID) { + existingKey = entry.key; + break; + } + } + + if (isSuperUser) { + if (existingKey != null && existingKey != 'superUser') { + _userSwitchPayloads.remove(existingKey); + } + _userSwitchPayloads['superUser'] = payload; + _childSwitchCounter = 0; + } else { + if (existingKey != null) { + _userSwitchPayloads[existingKey] = payload; + } 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 cd8ad70d..de4bec62 100644 --- a/lib/features/authentication/authentication_repo.dart +++ b/lib/features/authentication/authentication_repo.dart @@ -6,6 +6,7 @@ import 'package:hmg_patient_app_new/core/api_consts.dart'; import 'package:hmg_patient_app_new/core/app_state.dart'; import 'package:hmg_patient_app_new/core/common_models/generic_api_model.dart'; import 'package:hmg_patient_app_new/core/dependencies.dart'; +import 'package:hmg_patient_app_new/core/enums.dart'; import 'package:hmg_patient_app_new/core/exceptions/api_failure.dart'; import 'package:hmg_patient_app_new/features/authentication/models/resp_models/select_device_by_imei.dart'; import 'package:hmg_patient_app_new/services/logger_service.dart'; @@ -214,56 +215,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"; @@ -321,7 +272,6 @@ class AuthenticationRepoImp implements AuthenticationRepo { } } - // Determine which API to use based on zipCode final zipCode = _getZipCodeFromRequest(newRequest); final isOthersCountry = zipCode == '0'; final endpoint = isFormFamilyFile @@ -336,15 +286,40 @@ class AuthenticationRepoImp implements AuthenticationRepo { GenericApiModel? apiResponse; Failure? failure; + // Determine the payload to send + var requestBody = isFormFamilyFile + ? familyRequest + : isRegister + ? newRequest + : isSwitchUser + ? switchRequest + : newRequest.toJson(); + + if (isSwitchUser) { + Map allUsersPayload; + var switchingPatientID; + var superUserPatientID; + bool isSwitchingToSuperUser = false; + + allUsersPayload = appState.getUserSwitchPayloads; + switchingPatientID = switchRequest["PatientID"]; + superUserPatientID = allUsersPayload['superUser']['PatientID']; + isSwitchingToSuperUser = (appState.getSuperUserID == responseID) || (allUsersPayload.containsKey('superUser') && superUserPatientID == switchingPatientID); + + if (isSwitchingToSuperUser) { + var superUserPayload = appState.getUserSwitchPayloadByIndex(isSuperUser: true); + if (superUserPayload != null) { + requestBody['DeviceToken'] = newRequest.deviceToken; + requestBody['ProjectOutSA'] = 0; + requestBody['PatientIdentificationID'] = ""; + requestBody.removeWhere((key, value) => ['NationalID', 'isDentalAllowedBackend', 'ForRegisteration'].contains(key)); + } + } + } + await apiClient.post( endpoint, - body: isFormFamilyFile - ? familyRequest - : isRegister - ? newRequest - : isSwitchUser - ? switchRequest - : newRequest.toJson(), + body: requestBody, onFailure: (error, statusCode, {messageStatus, failureType}) { failure = failureType; }, @@ -611,7 +586,7 @@ class AuthenticationRepoImp implements AuthenticationRepo { } @override - Future>> getServicePrivilege() { + Future> getServicePrivilege() { Map mapDevice = {}; try { GenericApiModel? apiResponse; diff --git a/lib/features/authentication/authentication_view_model.dart b/lib/features/authentication/authentication_view_model.dart index 8d313774..c9917d8d 100644 --- a/lib/features/authentication/authentication_view_model.dart +++ b/lib/features/authentication/authentication_view_model.dart @@ -385,7 +385,7 @@ class AuthenticationViewModel extends ChangeNotifier { mobileNumber: phoneNumber, selectedLoginType: otpTypeEnum.toInt(), zipCode: selectedCountrySignup.countryCode, - nationalId:nationalIdOrFileNumber, + nationalId: nationalIdOrFileNumber, isFileNo: isForRegister ? isPatientHasFile(request: payload) : false, patientId: isFormFamilyFile ? _appState.getAuthenticatedUser()!.patientId : 0, isForRegister: isForRegister, @@ -615,13 +615,21 @@ class AuthenticationViewModel extends ChangeNotifier { _appState.setSuperUserID = null; _appState.setIsChildLoggedIn = false; activation.list!.first.isParentUser = true; + var allUsersPayload = _appState.getUserSwitchPayloads; + if ((allUsersPayload.containsKey('superUser') && allUsersPayload['superUser'] != null)) { + _appState.addUserSwitchPayload(activation.list!.first.toJson(), isSuperUser: false); + } else { + _appState.addUserSwitchPayload(activation.list!.first.toJson(), isSuperUser: true); + } } else { _appState.setSuperUserID = _appState.getAuthenticatedUser()?.patientId; _appState.setIsChildLoggedIn = true; activation.list!.first.isParentUser = false; + _appState.addUserSwitchPayload(activation.list!.first.toJson(), isSuperUser: false); } } else { activation.list!.first.isParentUser = true; + _appState.addUserSwitchPayload(activation.list!.first.toJson(), isSuperUser: true); } activation.list!.first.bloodGroup = activation.patientBloodType; activation.list!.first.zipCode = selectedCountrySignup == CountryEnum.others ? '0' : selectedCountrySignup.countryCode; @@ -1152,6 +1160,7 @@ class AuthenticationViewModel extends ChangeNotifier { _appState.setVidaPlusProjectList([]); _appState.setHMCProjectList([]); _appState.setProjectsDetailList([]); + _appState.clearUserSwitchPayloads(); await clearDefaultInputValues(); _navigationService.pushAndReplace(AppRoutes.landingScreen); } catch (e) { diff --git a/lib/presentation/my_family/widget/family_cards.dart b/lib/presentation/my_family/widget/family_cards.dart index a621168f..3f0d4a70 100644 --- a/lib/presentation/my_family/widget/family_cards.dart +++ b/lib/presentation/my_family/widget/family_cards.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:convert'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; @@ -79,8 +80,7 @@ class _FamilyCardsState extends State { children: [ Utils.buildSvgWithAssets(icon: AppAssets.alertSquare), SizedBox(width: 8.h), - LocaleKeys.whoCanViewMyMedicalFile.tr(context: context).toText14(color: AppColors.textColor, isUnderLine: true, weight: FontWeight.w500) - .onPress(() { + LocaleKeys.whoCanViewMyMedicalFile.tr(context: context).toText14(color: AppColors.textColor, isUnderLine: true, weight: FontWeight.w500).onPress(() { dialogService.showFamilyBottomSheetWithoutHWithChild( label: LocaleKeys.manageFiles.tr(context: context), message: "", @@ -136,18 +136,11 @@ class _FamilyCardsState extends State { ? AppColors.textGreenColor : AppColors.alertColor), SizedBox(height: 8.h), - Wrap( - alignment: WrapAlignment.start, - crossAxisAlignment: WrapCrossAlignment.start, - runAlignment: WrapAlignment.start, - spacing: 0.h, - children: [ - (profile.patientName ?? "").toText14(isBold: false, isCenter: false, maxlines: 1, weight: FontWeight.w600), - (getStatusTextByRequest( - FamilyFileEnum.values.firstWhere((e) => e.toInt == profile.status), profile.isRequestFromMySide ?? false)) - .toText12( - isBold: false, isCenter: false, maxLine: 1, fontWeight: FontWeight.w500, color: AppColors.greyTextColor), - ]), + Wrap(alignment: WrapAlignment.start, crossAxisAlignment: WrapCrossAlignment.start, runAlignment: WrapAlignment.start, spacing: 0.h, children: [ + (profile.patientName ?? "").toText14(isBold: false, isCenter: false, maxlines: 1, weight: FontWeight.w600), + (getStatusTextByRequest(FamilyFileEnum.values.firstWhere((e) => e.toInt == profile.status), profile.isRequestFromMySide ?? false)) + .toText12(isBold: false, isCenter: false, maxLine: 1, fontWeight: FontWeight.w500, color: AppColors.greyTextColor), + ]), SizedBox(height: 8.h), CustomChipWidget( height: 30.h, @@ -318,7 +311,11 @@ class _FamilyCardsState extends State { final profile = widget.profileViewList![index]; final isActive = (profile.responseId == appState.getAuthenticatedUser()?.patientId); final isParentUser = appState.getAuthenticatedUser()?.isParentUser ?? false; - final canSwitch = isParentUser || (!isParentUser && profile.responseId == appState.getSuperUserID); + 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); + final canSwitch = true; // Disabled - allows all users to switch return Container( padding: EdgeInsets.symmetric(vertical: 15.h, horizontal: 15.h), decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24.r), @@ -469,10 +466,10 @@ class _FamilyCardsState extends State { alignment: WrapAlignment.start, children: [ (profile.patientName ?? "").toText14(isBold: false, isCenter: true, maxlines: 1, weight: FontWeight.w600), - SizedBox(width: 2.w,), - (getStatusTextByRequest( - FamilyFileEnum.values.firstWhere((e) => e.toInt == profile.status), profile.isRequestFromMySide ?? false)) - .toText14( + SizedBox( + width: 2.w, + ), + (getStatusTextByRequest(FamilyFileEnum.values.firstWhere((e) => e.toInt == profile.status), profile.isRequestFromMySide ?? false)).toText14( isBold: false, isCenter: true, maxlines: 1,