Updates
parent
d703c382e5
commit
d053f58b7d
@ -0,0 +1,100 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:hmg_patient_app_new/core/api/api_client.dart';
|
||||
import 'package:hmg_patient_app_new/core/api_consts.dart';
|
||||
import 'package:hmg_patient_app_new/core/common_models/generic_api_model.dart';
|
||||
import 'package:hmg_patient_app_new/core/exceptions/api_failure.dart';
|
||||
import 'package:hmg_patient_app_new/services/logger_service.dart';
|
||||
|
||||
abstract class ProfileSettingsRepo {
|
||||
/// Updates general patient info (name, phone, etc.).
|
||||
Future<Either<Failure, GenericApiModel<dynamic>>> updatePatientInfo({
|
||||
required Map<String, dynamic> patientInfo,
|
||||
});
|
||||
|
||||
/// Deactivates (deletes) the patient's account.
|
||||
Future<Either<Failure, GenericApiModel<dynamic>>> deactivateAccount();
|
||||
}
|
||||
|
||||
class ProfileSettingsRepoImp implements ProfileSettingsRepo {
|
||||
final ApiClient apiClient;
|
||||
final LoggerService loggerService;
|
||||
|
||||
ProfileSettingsRepoImp({
|
||||
required this.loggerService,
|
||||
required this.apiClient,
|
||||
});
|
||||
|
||||
@override
|
||||
Future<Either<Failure, GenericApiModel<dynamic>>> updatePatientInfo({
|
||||
required Map<String, dynamic> patientInfo,
|
||||
}) async {
|
||||
try {
|
||||
GenericApiModel<dynamic>? apiResponse;
|
||||
Failure? failure;
|
||||
|
||||
await apiClient.post(
|
||||
SAVE_SETTING,
|
||||
body: patientInfo,
|
||||
onFailure: (error, statusCode, {messageStatus, failureType}) {
|
||||
failure = failureType;
|
||||
},
|
||||
onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
|
||||
try {
|
||||
apiResponse = GenericApiModel<dynamic>(
|
||||
messageStatus: messageStatus,
|
||||
statusCode: statusCode,
|
||||
errorMessage: errorMessage,
|
||||
data: response,
|
||||
);
|
||||
} catch (e) {
|
||||
failure = DataParsingFailure(e.toString());
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
if (failure != null) return Left(failure!);
|
||||
if (apiResponse == null) return Left(ServerFailure("Unknown error"));
|
||||
return Right(apiResponse!);
|
||||
} catch (e) {
|
||||
return Left(UnknownFailure(e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, GenericApiModel<dynamic>>> deactivateAccount() async {
|
||||
final Map<String, dynamic> body = {};
|
||||
|
||||
try {
|
||||
GenericApiModel<dynamic>? apiResponse;
|
||||
Failure? failure;
|
||||
|
||||
await apiClient.post(
|
||||
// TODO: Replace with actual deactivate-account endpoint once available
|
||||
'Services/Patients.svc/REST/Patient_DeactivateAccount',
|
||||
body: body,
|
||||
onFailure: (error, statusCode, {messageStatus, failureType}) {
|
||||
failure = failureType;
|
||||
},
|
||||
onSuccess: (response, statusCode, {messageStatus, errorMessage}) {
|
||||
try {
|
||||
apiResponse = GenericApiModel<dynamic>(
|
||||
messageStatus: messageStatus,
|
||||
statusCode: statusCode,
|
||||
errorMessage: errorMessage,
|
||||
data: response,
|
||||
);
|
||||
} catch (e) {
|
||||
failure = DataParsingFailure(e.toString());
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
if (failure != null) return Left(failure!);
|
||||
if (apiResponse == null) return Left(ServerFailure("Unknown error"));
|
||||
return Right(apiResponse!);
|
||||
} catch (e) {
|
||||
return Left(UnknownFailure(e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,106 @@
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hmg_patient_app_new/core/app_assets.dart';
|
||||
import 'package:hmg_patient_app_new/core/app_state.dart';
|
||||
import 'package:hmg_patient_app_new/core/dependencies.dart';
|
||||
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
|
||||
import 'package:hmg_patient_app_new/core/utils/utils.dart';
|
||||
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
|
||||
import 'package:hmg_patient_app_new/features/profile_settings/profile_settings_view_model.dart';
|
||||
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
|
||||
import 'package:hmg_patient_app_new/theme/colors.dart';
|
||||
import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart';
|
||||
import 'package:hmg_patient_app_new/widgets/common_bottom_sheet.dart';
|
||||
import 'package:hmg_patient_app_new/widgets/input_widget.dart';
|
||||
import 'package:hmg_patient_app_new/widgets/loader/bottomsheet_loader.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class UpdateEmailDialog extends StatefulWidget {
|
||||
UpdateEmailDialog({super.key});
|
||||
|
||||
@override
|
||||
State<UpdateEmailDialog> createState() => _UpdateEmailDialogState();
|
||||
}
|
||||
|
||||
class _UpdateEmailDialogState extends State<UpdateEmailDialog> {
|
||||
late FocusNode _textFieldFocusNode;
|
||||
late TextEditingController? textController;
|
||||
ProfileSettingsViewModel? profileSettingsViewModel;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_textFieldFocusNode = FocusNode();
|
||||
textController = TextEditingController();
|
||||
textController!.text = getIt.get<AppState>().getAuthenticatedUser()!.emailAddress ?? "";
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_textFieldFocusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
profileSettingsViewModel = Provider.of<ProfileSettingsViewModel>(context);
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
_textFieldFocusNode.unfocus();
|
||||
FocusScope.of(context).unfocus();
|
||||
},
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
"Enter the new email address to be updated in your HMG File: ".toText16(textAlign: TextAlign.start, weight: FontWeight.w500),
|
||||
SizedBox(height: 12.h),
|
||||
TextInputWidget(
|
||||
labelText: LocaleKeys.email.tr(),
|
||||
hintText: "demo@gmail.com",
|
||||
controller: textController,
|
||||
focusNode: _textFieldFocusNode,
|
||||
autoFocus: true,
|
||||
padding: EdgeInsets.all(8.h),
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
isEnable: true,
|
||||
isReadOnly: false,
|
||||
prefix: null,
|
||||
isBorderAllowed: false,
|
||||
isAllowLeadingIcon: true,
|
||||
fontSize: 14.f,
|
||||
isCountryDropDown: false,
|
||||
leadingIcon: AppAssets.email,
|
||||
fontFamily: "Poppins",
|
||||
),
|
||||
SizedBox(height: 12.h),
|
||||
CustomButton(
|
||||
text: LocaleKeys.submit.tr(context: context),
|
||||
onPressed: () {
|
||||
LoaderBottomSheet.showLoader(loadingText: LocaleKeys.updatingEmailAddress.tr(context: context));
|
||||
profileSettingsViewModel!.updatePatientInfo(
|
||||
patientInfo: {"EmailAddress": textController!.text},
|
||||
onSuccess: (response) {
|
||||
LoaderBottomSheet.hideLoader();
|
||||
showCommonBottomSheetWithoutHeight(context, title: LocaleKeys.success.tr(context: context), child: Utils.getSuccessWidget(loadingText: LocaleKeys.success.tr()),
|
||||
callBackFunc: () async {
|
||||
Navigator.of(context).pop();
|
||||
}, isFullScreen: false);
|
||||
},
|
||||
onError: (error) {
|
||||
LoaderBottomSheet.hideLoader();
|
||||
// Show error message
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(error)),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
backgroundColor: AppColors.primaryRedColor,
|
||||
borderColor: AppColors.primaryRedColor,
|
||||
textColor: const Color(0xFFffffff),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue