From ef8532b1c52128199fd3c38d9dd22a2ccfccbd07 Mon Sep 17 00:00:00 2001 From: Sultan khan Date: Tue, 22 Jul 2025 11:49:06 +0300 Subject: [PATCH] updated login flow --- lib/core/service/medical/medical_service.dart | 4 +- lib/pages/MyAppointments/SchedulePage.dart | 353 +++--------------- lib/pages/login/saved_login.dart | 22 +- lib/pages/login/welcome.dart | 15 + lib/uitl/utils.dart | 2 +- 5 files changed, 84 insertions(+), 312 deletions(-) diff --git a/lib/core/service/medical/medical_service.dart b/lib/core/service/medical/medical_service.dart index 1fafa1c1..fee1a4ec 100644 --- a/lib/core/service/medical/medical_service.dart +++ b/lib/core/service/medical/medical_service.dart @@ -55,7 +55,7 @@ class MedicalService extends BaseService { getSchedule(DoctorList doctorRequest) async { Map request; - request = {'DoctorID': doctorRequest.doctorID, 'ProjectID': doctorRequest.projectID, 'ClinicID': doctorRequest.clinicID, 'DoctorWorkingHoursDays': 7}; + request = {'DoctorID': doctorRequest.doctorID, 'ProjectID': doctorRequest.projectID, 'ClinicID': doctorRequest.clinicID, 'DoctorWorkingHoursDays': 90}; dynamic localRes; await baseAppClient.post(DOCTOR_SCHEDULE_URL, onSuccess: (response, statusCode) async { localRes = response; @@ -68,7 +68,7 @@ class MedicalService extends BaseService { getFreeSlot(DoctorList doctorRequest) async { Map request; - request = {'DoctorID': doctorRequest.doctorID, 'ProjectID': doctorRequest.projectID, 'ClinicID': doctorRequest.clinicID, 'DoctorWorkingHoursDays': 7}; + request = {'DoctorID': doctorRequest.doctorID, 'ProjectID': doctorRequest.projectID, 'ClinicID': doctorRequest.clinicID, 'DoctorWorkingHoursDays': 90}; dynamic localRes; await baseAppClient.post(GET_DOCTOR_FREE_SLOTS, onSuccess: (response, statusCode) async { localRes = response; diff --git a/lib/pages/MyAppointments/SchedulePage.dart b/lib/pages/MyAppointments/SchedulePage.dart index dd8c59b5..5890f1ec 100644 --- a/lib/pages/MyAppointments/SchedulePage.dart +++ b/lib/pages/MyAppointments/SchedulePage.dart @@ -183,16 +183,18 @@ class _SchedulePageState extends State { ))); })); } - - generateWeeksSchedules() { - this.weeks.clear(); - for (var i = 0; i < 8; i++) { - var weekSchedule = generateNewWeekSchedule(i); - this.markWeekFreeDays(weekSchedule); - this.weeks.add(weekSchedule); - } - //print(this.weeks); - } + // + // generateWeeksSchedules() { + // + // + // this.weeks.clear(); + // for (var i = 0; i < 20; i++) { + // var weekSchedule = generateNewWeekSchedule(i); + // this.markWeekFreeDays(weekSchedule); + // this.weeks.add(weekSchedule); + // } + // //print(this.weeks); + // } markWeekFreeDays(schedule) { for (var workDay in schedule) { @@ -200,20 +202,43 @@ class _SchedulePageState extends State { } } - generateNewWeekSchedule(weekIndex) { - var weekMSOffset = weekIndex * weekMS; + // generateNewWeekSchedule(weekIndex) { + // var weekMSOffset = weekIndex * weekMS; + // var newWeekSchedule = []; + // for (var workDay in this.doctorScheduleResponse) { + // Map newWorkDay = Map(); + // newWorkDay['Date'] = DateUtil.convertDateMSToJsonDate(DateUtil.convertStringToDate(workDay.date!).millisecondsSinceEpoch + weekMSOffset); + // newWorkDay['DayName'] = workDay.dayName; + // newWorkDay['WorkingHours'] = workDay.workingHours; + // newWeekSchedule.add(newWorkDay); + // } + // return newWeekSchedule; + // } - var newWeekSchedule = []; - for (var workDay in this.doctorScheduleResponse) { - Map newWorkDay = Map(); - newWorkDay['Date'] = DateUtil.convertDateMSToJsonDate(DateUtil.convertStringToDate(workDay.date!).millisecondsSinceEpoch + weekMSOffset); - newWorkDay['DayName'] = workDay.dayName; - newWorkDay['WorkingHours'] = workDay.workingHours; - newWeekSchedule.add(newWorkDay); + void generateWeeksSchedules() { + this.weeks.clear(); + List> paginated = paginateSchedules(this.doctorScheduleResponse, 7); + for (var weekSchedule in paginated) { + List> week = []; + for (var workDay in weekSchedule) { + Map newWorkDay = {}; + newWorkDay['Date'] = DateUtil.convertDateMSToJsonDate(DateUtil.convertStringToDate(workDay.date!).millisecondsSinceEpoch); + newWorkDay['DayName'] = workDay.dayName; + newWorkDay['WorkingHours'] = workDay.workingHours; + week.add(newWorkDay); + } + this.markWeekFreeDays(week); + this.weeks.add(week); } - return newWeekSchedule; } - + List> paginateSchedules(List schedules, int pageSize) { + List> pages = []; + for (int i = 0; i < schedules.length; i += pageSize) { + int end = (i + pageSize < schedules.length) ? i + pageSize : schedules.length; + pages.add(schedules.sublist(i, end)); + } + return pages; + } hasFreeSlot(String jsonDate) { var date = DateUtil.convertStringToDate(jsonDate); var scheduleDay = date; @@ -247,289 +272,3 @@ class _SchedulePageState extends State { // ); } } - -// import 'package:hmg_patient_app/models/Appointments/DoctorListResponse.dart'; -// import 'package:hmg_patient_app/pages/MyAppointments/AppointmentDetails.dart'; -// -// import 'package:hmg_patient_app/pages/MyAppointments/models/DoctorScheduleResponse.dart'; -// import 'package:hmg_patient_app/pages/MyAppointments/widgets/indicator.dart'; -// import 'package:hmg_patient_app/services/appointment_services/GetDoctorsList.dart'; -// import 'package:hmg_patient_app/uitl/translations_delegate_base.dart'; -// import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart'; -// import 'package:hmg_patient_app/uitl/date_uitl.dart'; -// import 'package:hmg_patient_app/widgets/transitions/fade_page.dart'; -// import 'package:flutter/material.dart'; -// import 'package:hmg_patient_app/widgets/data_display/text.dart'; -// import 'package:hmg_patient_app/core/viewModels/medical/medical_view_model.dart'; -// import 'package:hmg_patient_app/pages/base/base_view.dart'; -// import 'package:hmg_patient_app/uitl/app_shared_preferences.dart'; -// import 'package:hmg_patient_app/config/shared_pref_kay.dart'; -// import 'package:hmg_patient_app/models/Appointments/AppoimentAllHistoryResultList.dart'; -// import 'package:hmg_patient_app/uitl/app_toast.dart'; -// import 'package:hmg_patient_app/uitl/date_uitl.dart'; -// import 'package:hmg_patient_app/core/viewModels/project_view_model.dart'; -// import 'package:provider/provider.dart'; -// import 'package:hmg_patient_app/core/enum/viewstate.dart'; -// -// class SchedulePage extends StatefulWidget { -// DoctorList doctorList; -// AppoitmentAllHistoryResultList appo; -// SchedulePage({ -// this.appo, -// this.doctorList, -// }); -// @override -// _SchedulePageState createState() => _SchedulePageState(); -// } -// -// class _SchedulePageState extends State { -// DoctorsListService service; -// PageController _pageController = PageController(); -// double currentPage = 0; -// int selectedindex = 0; -// List weeks = []; -// List doctorScheduleResponse = []; -// int weekMS = 604800 * 1000; -// DoctorList doctorList; -// List freeSlots = []; -// bool isPageChange = false; -// -// AppSharedPreferences sharedPref = AppSharedPreferences(); -// @override -// void initState() { -// this.doctorList = widget.doctorList; -// -// super.initState(); -// } -// -// @override -// Widget build(BuildContext context) { -// ProjectViewModel projectViewModel = Provider.of(context); -// return BaseView( -// onModelReady: (model) => model.getDoctorSchedule(doctorList), -// allowAny: true, -// builder: (_, model, widget) => BaseView( -// onModelReady: (model2) => model2.getFreeSlots(doctorList), -// allowAny: true, -// builder: (_, model2, widget2) { -// if (model2.freeSlots.length > 0 && isPageChange == false && model2.state == ViewState.Idle) { -// this.freeSlots = model2.freeSlots; -// this.doctorScheduleResponse = model.getDoctorScheduleList; -// -// this.generateWeeksSchedules(); -// } else if (model2.freeSlots.length == 0 && model2.state == ViewState.Idle) { -// AppToast.showErrorToast(message: TranslationBase.of(context).emptySchedule); -// Navigator.pop(context); -// } -// return AppScaffold( -// appBarTitle: TranslationBase.of(context).schedule, -// showNewAppBar: true, -// showNewAppBarTitle: true, -// isShowAppBar: true, -// backgroundColor: Color(0xffF7F7F7), -// baseViewModel: model2, -// isShowDecPage: false, -// body: Column( -// children: [ -// SizedBox(height: 21), -// PageViewIndicator( -// isActive: true, -// currentPage: this.currentPage, -// length: weeks.length, -// ), -// Expanded( -// child: PageView.builder( -// controller: _pageController, -// itemCount: weeks.length, -// onPageChanged: (index) { -// setState(() { -// isPageChange = true; -// this.currentPage = index.toDouble(); -// }); -// }, -// itemBuilder: (context, index) { -// return ListView.separated( -// itemCount: weeks[index].length, -// padding: EdgeInsets.all(21), -// separatorBuilder: (context, index) => SizedBox(height: 12), -// itemBuilder: (context, index2) { -// bool isToday = DateUtil.convertStringToDate(weeks[index][index2]['Date']).toString().substring(0, 10) == DateTime.now().toString().substring(0, 10); -// Color toDayColor = isToday ? Color(0xff359846) : Colors.white; -// return InkWell( -// onTap: () { -// openBookAppointment(weeks[index][index2]); -// }, -// child: Row( -// crossAxisAlignment: CrossAxisAlignment.start, -// children: [ -// Expanded( -// flex: 1, -// child: Column( -// mainAxisSize: MainAxisSize.min, -// crossAxisAlignment: CrossAxisAlignment.start, -// children: [ -// Text( -// weeks[index][index2]['DayName'], -// style: TextStyle( -// fontSize: 13, -// fontWeight: FontWeight.w600, -// color: Color(0xff2E303A), -// letterSpacing: -0.52, -// ), -// ), -// Text( -// getDayMonths(DateUtil.convertStringToDate(weeks[index][index2]['Date'])), -// style: TextStyle( -// fontSize: 18, -// fontWeight: FontWeight.w700, -// color: Color(0xff2E303A), -// letterSpacing: -0.72, -// ), -// ), -// ], -// ), -// ), -// Expanded( -// flex: 3, -// child: Container( -// decoration: BoxDecoration( -// color: toDayColor, -// borderRadius: BorderRadius.all( -// Radius.circular(10.0), -// ), -// boxShadow: [ -// BoxShadow( -// color: Color(0xff000000).withOpacity(.05), -// blurRadius: 27, -// offset: Offset(0, -3), -// ), -// ], -// ), -// child: Container( -// margin: EdgeInsets.only(left: projectViewModel.isArabic ? 0 : 6, right: projectViewModel.isArabic ? 6 : 0), -// padding: EdgeInsets.symmetric(vertical: 14, horizontal: 12), -// decoration: BoxDecoration( -// color: Colors.white, -// border: Border.all(color: Colors.white, width: 1), -// borderRadius: BorderRadius.only( -// bottomRight: projectViewModel.isArabic ? Radius.circular(0) : Radius.circular(10.0), -// topRight: projectViewModel.isArabic ? Radius.circular(0) : Radius.circular(10.0), -// bottomLeft: projectViewModel.isArabic ? Radius.circular(10.0) : Radius.circular(0), -// topLeft: projectViewModel.isArabic ? Radius.circular(10.0) : Radius.circular(0), -// ), -// ), -// child: Row( -// crossAxisAlignment: CrossAxisAlignment.center, -// children: [ -// Expanded( -// child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ -// if (isToday) -// Text( -// TranslationBase.of(context).today, -// style: TextStyle( -// fontSize: 12, -// fontWeight: FontWeight.w600, -// color: toDayColor, -// letterSpacing: -0.48, -// ), -// ), -// Row( -// children: [ -// Expanded( -// child: Text( -// weeks[index][index2]['WorkingHours'], -// style: TextStyle( -// fontSize: 13, -// fontWeight: FontWeight.w600, -// color: Color(0xff2E303A), -// letterSpacing: -0.56, -// ), -// ), -// ), -// ], -// ) -// ]), -// ), -// Icon(Icons.arrow_forward, color: Color(0xff2B353E)), -// ], -// ), -// ), -// ), -// ), -// ], -// ), -// ); -// }); -// }, -// ), -// ), -// ], -// ), -// ); -// }), -// ); -// } -// -// generateWeeksSchedules() { -// this.weeks.clear(); -// for (var i = 0; i < 8; i++) { -// var weekSchedule = generateNewWeekSchedule(i); -// this.markWeekFreeDays(weekSchedule); -// this.weeks.add(weekSchedule); -// } -// //print(this.weeks); -// } -// -// markWeekFreeDays(schedule) { -// for (var workDay in schedule) { -// workDay['fullDay'] = !this.hasFreeSlot(workDay['Date']); -// } -// } -// -// generateNewWeekSchedule(weekIndex) { -// var weekMSOffset = weekIndex * weekMS; -// -// var newWeekSchedule = []; -// for (var workDay in this.doctorScheduleResponse) { -// Map newWorkDay = Map(); -// newWorkDay['Date'] = DateUtil.convertDateMSToJsonDate(DateUtil.convertStringToDate(workDay.date).millisecondsSinceEpoch + weekMSOffset); -// newWorkDay['DayName'] = workDay.dayName; -// newWorkDay['WorkingHours'] = workDay.workingHours; -// newWeekSchedule.add(newWorkDay); -// } -// return newWeekSchedule; -// } -// -// hasFreeSlot(String jsonDate) { -// var date = DateUtil.convertStringToDate(jsonDate); -// var scheduleDay = date; -// for (var event in this.freeSlots) { -// var date = DateUtil.convertStringToDate(event); -// var nDate = DateTime(date.year, date.month, date.day); -// -// if (nDate.millisecondsSinceEpoch == scheduleDay.millisecondsSinceEpoch) { -// return true; -// } -// } -// return false; -// } -// -// String getDayMonths(DateTime dateTime) { -// String dateFormat = '${dateTime.day} ${DateUtil.getMonth(dateTime.month).toString().substring(0, 3)}'; -// return dateFormat; -// } -// -// openBookAppointment(selectedDate) { -// //sharedPref.setObject(DOCTOR_SCHEDULE_DATE_SEL, selectedDate); -// Navigator.of(context).pop(selectedDate); -// // Navigator.push( -// // context, -// // FadePage( -// // page: AppointmentDetails( -// // appo: widget.appo, -// // doctorSchedule: selectedDate, -// // ), -// // ), -// // ); -// } -// } diff --git a/lib/pages/login/saved_login.dart b/lib/pages/login/saved_login.dart index 2c906795..a4204994 100644 --- a/lib/pages/login/saved_login.dart +++ b/lib/pages/login/saved_login.dart @@ -17,6 +17,7 @@ import 'package:hmg_patient_app/models/InPatientServices/get_admission_info_resp import 'package:hmg_patient_app/models/InPatientServices/get_admission_request_info_response_model.dart'; import 'package:hmg_patient_app/new_ui/otp/otp_validation_bootmsheet_widget.dart'; import 'package:hmg_patient_app/pages/landing/landing_page.dart'; +import 'package:hmg_patient_app/pages/login/register_new.dart'; import 'package:hmg_patient_app/pages/login/user-login-agreement-page.dart'; import 'package:hmg_patient_app/pages/login/welcome.dart'; import 'package:hmg_patient_app/pages/rateAppointment/rate_appointment_doctor.dart'; @@ -36,6 +37,8 @@ import 'package:hmg_patient_app/widgets/transitions/fade_page.dart'; import 'package:local_auth/local_auth.dart'; import 'package:provider/provider.dart'; +import '../../widgets/dialogs/confirm_dialog.dart'; + class SavedLogin extends StatefulWidget { final SelectDeviceIMEIRES savedLoginData; @@ -160,7 +163,7 @@ class _SavedLogin extends State { margin: EdgeInsets.all(16), child: SvgPicture.asset( getTypeIcons(widget.savedLoginData.logInType!, context), - color: Color(0xFFED1C2B), + // color: Color(0xFFED1C2B), height: 64, width: 64, ), @@ -232,7 +235,7 @@ class _SavedLogin extends State { onPressed: () { int? val = Utils.onOtpBtnPressed(OTPType.sms, phoneController); if (val != null) { - checkUserAuthentication(val); + checkUserAuthentication(val,); } }, backgroundColor: CustomColors.bgRedColor, @@ -621,8 +624,23 @@ class _SavedLogin extends State { } }) .catchError((err) { + + print(err); GifLoaderDialogUtils.hideDialog(context); + ConfirmDialog dialog = new ConfirmDialog( + context: context, + confirmMessage: err, + okText: TranslationBase.of(context).confirm, + cancelText: TranslationBase.of(context).cancel_nocaps, + okFunction: () => { + ConfirmDialog.closeAlertDialog(context), + Navigator.of(context).push(FadePage(page: RegisterNew())), + }, + cancelFunction: () => {}); + dialog.showAlertDialog(context); + projectViewModel.analytics.loginRegistration + .login_fail(error: err.toString()); }); } diff --git a/lib/pages/login/welcome.dart b/lib/pages/login/welcome.dart index 0e4a6d42..b1aafc0f 100644 --- a/lib/pages/login/welcome.dart +++ b/lib/pages/login/welcome.dart @@ -39,6 +39,8 @@ import 'package:flutter_svg/svg.dart'; import 'package:intl/src/intl/date_format.dart'; import 'package:provider/provider.dart'; +import '../../widgets/dialogs/confirm_dialog.dart'; + class WelcomeLogin extends StatefulWidget { @override _WelcomeLogin createState() => _WelcomeLogin(); @@ -320,6 +322,19 @@ class _WelcomeLogin extends State { .catchError((err) { print(err); GifLoaderDialogUtils.hideDialog(context); + ConfirmDialog dialog = new ConfirmDialog( + context: context, + confirmMessage: err, + okText: TranslationBase.of(context).confirm, + cancelText: TranslationBase.of(context).cancel_nocaps, + okFunction: () => { + ConfirmDialog.closeAlertDialog(context), + Navigator.of(context).push(FadePage(page: RegisterNew())), + }, + cancelFunction: () => {}); + dialog.showAlertDialog(context); + projectViewModel.analytics.loginRegistration + .login_fail(error: err.toString()); }); } diff --git a/lib/uitl/utils.dart b/lib/uitl/utils.dart index 2413846f..559b3350 100644 --- a/lib/uitl/utils.dart +++ b/lib/uitl/utils.dart @@ -91,7 +91,7 @@ class Utils { print("Requesting OTP for ${controller.text} via ${type == OTPType.whatsapp ? "WhatsApp" : "SMS"} and " //$"{nationIdController.text}" ); - return type == OTPType.sms ? 1 : 2; + return type == OTPType.sms ? 1 : 4; } static bool validateIqama(String iqamaNumber) {