From 2a819a2d9752be7916b9e441a5d64f8364c3e1b9 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Mon, 16 Feb 2026 14:33:12 +0300 Subject: [PATCH] Ancillary order fixes --- .../my_appointments_view_model.dart | 7 +- .../todo_section/todo_section_repo.dart | 2 + .../appointment_details_page.dart | 14 ++- .../ancillary_order_payment_page.dart | 89 +++++-------------- 4 files changed, 43 insertions(+), 69 deletions(-) diff --git a/lib/features/my_appointments/my_appointments_view_model.dart b/lib/features/my_appointments/my_appointments_view_model.dart index 03fbc61..35bf29b 100644 --- a/lib/features/my_appointments/my_appointments_view_model.dart +++ b/lib/features/my_appointments/my_appointments_view_model.dart @@ -518,7 +518,12 @@ class MyAppointmentsViewModel extends ChangeNotifier { final result = await myAppointmentsRepo.cancelAppointment(patientAppointmentHistoryResponseModel: patientAppointmentHistoryResponseModel); result.fold( - (failure) async => await errorHandlerService.handleError(failure: failure), + // (failure) async => await errorHandlerService.handleError(failure: failure), + (failure) async { + if(onError != null) { + onError(failure.message); + } + }, (apiResponse) { if (apiResponse.messageStatus == 2) { onError!(apiResponse.errorMessage!); diff --git a/lib/features/todo_section/todo_section_repo.dart b/lib/features/todo_section/todo_section_repo.dart index 76a4438..6d58d80 100644 --- a/lib/features/todo_section/todo_section_repo.dart +++ b/lib/features/todo_section/todo_section_repo.dart @@ -96,6 +96,8 @@ class TodoSectionRepoImp implements TodoSectionRepo { } } + ancillaryOrders.sort((a, b) => b.orderDate!.compareTo(a.orderDate!)); + apiResponse = GenericApiModel>( messageStatus: messageStatus, statusCode: statusCode, diff --git a/lib/presentation/appointments/appointment_details_page.dart b/lib/presentation/appointments/appointment_details_page.dart index dee1328..e5961e3 100644 --- a/lib/presentation/appointments/appointment_details_page.dart +++ b/lib/presentation/appointments/appointment_details_page.dart @@ -145,8 +145,6 @@ class _AppointmentDetailsPageState extends State { }); }, onCancelTap: () async { - myAppointmentsViewModel.setIsAppointmentDataToBeLoaded(true); - LoaderBottomSheet.showLoader(loadingText: LocaleKeys.cancellingAppointmentPleaseWait.tr(context: context)); await myAppointmentsViewModel.cancelAppointment( patientAppointmentHistoryResponseModel: widget.patientAppointmentHistoryResponseModel, @@ -165,6 +163,18 @@ class _AppointmentDetailsPageState extends State { isDismissible: false, isFullScreen: false, ); + }, + onError: (err) { + LoaderBottomSheet.hideLoader(); + showCommonBottomSheetWithoutHeight( + context, + child: Utils.getErrorWidget(loadingText: err.toString()), + callBackFunc: () {}, + title: "", + isCloseButtonVisible: true, + isDismissible: false, + isFullScreen: false, + ); }); var isEventAddedOrRemoved = await CalenderUtilsNew.instance.checkAndRemove( id:"${widget.patientAppointmentHistoryResponseModel.appointmentNo}", ); setState(() { diff --git a/lib/presentation/todo_section/ancillary_order_payment_page.dart b/lib/presentation/todo_section/ancillary_order_payment_page.dart index fe07186..b34bf21 100644 --- a/lib/presentation/todo_section/ancillary_order_payment_page.dart +++ b/lib/presentation/todo_section/ancillary_order_payment_page.dart @@ -103,7 +103,7 @@ class _AncillaryOrderPaymentPageState extends State { Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - LocaleKeys.visaOrMastercard.tr(context: context).toText16(isBold: true).toShimmer2(isShow: todoVM.isProcessingPayment), + Image.asset(AppAssets.mada, width: 50.h, height: 50.h), SizedBox(height: 16.h), LocaleKeys.mada.tr(context: context).toText16(isBold: true).toShimmer2(isShow: todoVM.isProcessingPayment), ], @@ -468,86 +468,43 @@ class _AncillaryOrderPaymentPageState extends State { languageID: appState.isArabic() ? 1 : 2, onSuccess: (response) { LoaderBottomSheet.hideLoader(); - final invoiceNo = response['AncillaryOrderInvoiceList']?[0]?['InvoiceNo']; - _showSuccessDialog(invoiceNo); }, onError: (error) { LoaderBottomSheet.hideLoader(); todoSectionViewModel.setProcessingPayment(false); - Utils.showToast(error); + showCommonBottomSheetWithoutHeight(context, + child: Utils.getErrorWidget(loadingText: error.toString()), isCloseButtonVisible: true, isDismissible: true, isFullScreen: false, callBackFunc: () {}); }, ); } void _showSuccessDialog(dynamic invoiceNo) { todoSectionViewModel.setProcessingPayment(false); - - log("Ancillary order payment successful! Invoice #: $invoiceNo"); - // Show success message and navigate - Utils.showToast("Payment successful! Invoice #: $invoiceNo"); + // Utils.showToast("Payment successful! Invoice #: $invoiceNo"); // Navigate back to home after a short delay - Future.delayed(Duration(seconds: 1), () { - showCommonBottomSheetWithoutHeight( - context, - child: Column( - children: [ - Row( - children: [ - LocaleKeys.hereIsYourInvoiceNumber.tr(context: context).toText14( - color: AppColors.textColorLight, - weight: FontWeight.w500, - ), - SizedBox(width: 4.w), - ("12345").toText16(isBold: true), - ], - ), - SizedBox(height: 24.h), - Row( - children: [ - Expanded( - child: CustomButton( - height: 56.h, - text: LocaleKeys.ok.tr(context: context), - onPressed: () { - Navigator.pushAndRemoveUntil( - context, - CustomPageRoute( - page: LandingNavigation(), - ), - (r) => false); - }, - backgroundColor: AppColors.secondaryLightRedColor, - borderColor: AppColors.secondaryLightRedColor, - textColor: AppColors.primaryRedColor, - ), - ), - ], - ), - ], - ), - // title: LocaleKeys.paymentCompletedSuccessfully.tr(context: context), - titleWidget: Utils.getSuccessWidget(loadingText: LocaleKeys.paymentCompletedSuccessfully.tr(context: context)), - isCloseButtonVisible: false, - isDismissible: false, - isFullScreen: false, - ); + // Future.delayed(Duration(seconds: 1), () { + showCommonBottomSheetWithoutHeight(context, + child: Utils.getSuccessWidget(loadingText: "${LocaleKeys.paymentCompletedSuccessfully.tr(context: context)}, ${LocaleKeys.hereIsYourInvoiceNumber.tr(context: context)}$invoiceNo"), + isCloseButtonVisible: true, + isDismissible: true, + isFullScreen: false, callBackFunc: () { + // Pop until we reach the LandingPage + todoSectionViewModel.setIsAncillaryOrdersNeedReloading(true); + Navigator.pushAndRemoveUntil( + context, + CustomPageRoute( + page: LandingNavigation(), + ), + (r) => false); }); + // }); } _startApplePay() async { - showCommonBottomSheet( - context, - child: Utils.getLoadingWidget(), - callBackFunc: (str) {}, - title: "", - height: ResponsiveExtension.screenHeight * 0.3, - isCloseButtonVisible: false, - isDismissible: false, - isFullScreen: false, - ); + LoaderBottomSheet.showLoader(loadingText: LocaleKeys.fetchingApplePayDetails.tr(context: context)); final user = appState.getAuthenticatedUser(); transID = Utils.getAdvancePaymentTransID(widget.projectID, user!.patientId!); @@ -604,7 +561,7 @@ class _AncillaryOrderPaymentPageState extends State { await payfortViewModel.applePayRequestInsert(applePayInsertRequest: applePayInsertRequest); } catch (error) { log("Apple Pay Insert Request Failed: $error"); - Navigator.of(context).pop(); + LoaderBottomSheet.hideLoader(); showCommonBottomSheetWithoutHeight( context, child: Utils.getErrorWidget(loadingText: LocaleKeys.failedToInitializeApplePay.tr(context: context)), @@ -627,7 +584,7 @@ class _AncillaryOrderPaymentPageState extends State { currency: appState.getAuthenticatedUser()!.outSa! == 0 ? "SAR" : "AED", onFailed: (failureResult) async { log("failureResult: ${failureResult.message.toString()}"); - Navigator.of(context).pop(); + LoaderBottomSheet.hideLoader(); showCommonBottomSheetWithoutHeight( context, child: Utils.getErrorWidget(loadingText: failureResult.message.toString()), @@ -637,7 +594,7 @@ class _AncillaryOrderPaymentPageState extends State { ); }, onSucceeded: (successResult) async { - Navigator.of(context).pop(); + LoaderBottomSheet.hideLoader(); log("successResult: ${successResult.responseMessage.toString()}"); selectedPaymentMethod = successResult.paymentOption ?? "VISA"; _checkPaymentStatus();