update Calendar nav

This commit is contained in:
2025-08-18 16:22:07 +02:00
parent e2c9b95b8d
commit 43ab2b6681
5 changed files with 407 additions and 226 deletions

View File

@@ -1,6 +1,6 @@
import 'dart:convert';
import 'package:mzansi_innovation_hub/mih_services/mih_notification_services.dart';
import 'package:go_router/go_router.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/appointment.dart';
@@ -8,19 +8,7 @@ import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart'
import 'package:mzansi_innovation_hub/mih_components/mih_objects/business.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/business_user.dart';
import 'package:flutter/material.dart';
// import '../mih_components/mih_pop_up_messages/mih_error_message.dart';
// import '../mih_components/mih_pop_up_messages/mih_success_message.dart';
// import '../mih_env/mih_env.dart';
// import '../mih_objects/app_user.dart';
// import '../mih_objects/arguments.dart';
// import '../mih_objects/business.dart';
// import '../mih_objects/business_user.dart';
// import '../mih_objects/notification.dart';
// import '../mih_objects/patient_access.dart';
// import '../mih_objects/patient_queue.dart';
// import '../mih_objects/patients.dart';
import 'package:supertokens_flutter/http.dart' as http;
import '../mih_components/mih_pop_up_messages/mih_error_message.dart';
import '../mih_components/mih_pop_up_messages/mih_success_message.dart';
import '../mih_config/mih_env.dart';
@@ -39,23 +27,12 @@ class MihMzansiCalendarApis {
String app_id,
String date,
) async {
//print("Patien manager page: $endpoint");
final response = await http.get(Uri.parse(
"${AppEnviroment.baseApiUrl}/appointments/personal/$app_id?date=$date"));
// print("Here");
// print("Body: ${response.body}");
// print("Code: ${response.statusCode}");
// errorCode = response.statusCode.toString();
// errorBody = response.body;
if (response.statusCode == 200) {
//print("Here1");
Iterable l = jsonDecode(response.body);
//print("Here2");
List<Appointment> personalAppointments =
List<Appointment>.from(l.map((model) => Appointment.fromJson(model)));
//print("Here3");
//print(patientQueue);
return personalAppointments;
} else {
throw Exception('failed to fatch personal appointments');
@@ -114,7 +91,7 @@ class MihMzansiCalendarApis {
/// BuildContext context,
///
/// Returns VOID (TRIGGERS NOTIGICATIOPN ON SUCCESS)
static Future<void> deleteAppointmentAPICall(
static Future<int> deleteAppointmentAPICall(
AppUser signedInUser,
bool personalSelected,
Business? business,
@@ -123,6 +100,7 @@ class MihMzansiCalendarApis {
int idappointments,
BuildContext context,
) async {
loadingPopUp(context);
var response = await http.delete(
Uri.parse("${AppEnviroment.baseApiUrl}/appointment/delete/"),
headers: <String, String>{
@@ -130,39 +108,41 @@ class MihMzansiCalendarApis {
},
body: jsonEncode(<String, dynamic>{"idappointments": idappointments}),
);
context.pop();
return response.statusCode;
//print("Here4");
//print(response.statusCode);
if (response.statusCode == 200) {
Navigator.of(context).pop();
Navigator.of(context).pop();
Navigator.of(context).pop();
if (inWaitingRoom == true && personalSelected == false) {
Navigator.of(context).pushNamed(
'/patient-manager',
arguments: PatManagerArguments(
signedInUser,
false,
business,
businessUser,
),
);
} else {
Navigator.of(context).pushNamed(
'/calendar',
arguments: CalendarArguments(
signedInUser,
personalSelected,
business,
businessUser,
),
);
}
String message =
"The appointment has been deleted successfully. This means it will no longer be visible in your Calendar.";
successPopUp(message, context);
} else {
internetConnectionPopUp(context);
}
// if (response.statusCode == 200) {
// Navigator.of(context).pop();
// Navigator.of(context).pop();
// Navigator.of(context).pop();
// if (inWaitingRoom == true && personalSelected == false) {
// Navigator.of(context).pushNamed(
// '/patient-manager',
// arguments: PatManagerArguments(
// signedInUser,
// false,
// business,
// businessUser,
// ),
// );
// } else {
// Navigator.of(context).pushNamed(
// '/calendar',
// arguments: CalendarArguments(
// signedInUser,
// personalSelected,
// business,
// businessUser,
// ),
// );
// }
// String message =
// "The appointment has been deleted successfully. This means it will no longer be visible in your Calendar.";
// successPopUp(message, context);
// } else {
// internetConnectionPopUp(context);
// }
}
/// This function is used to add an appointment to users mzansi Calendar.
@@ -177,7 +157,7 @@ class MihMzansiCalendarApis {
/// BuildContext context,
///
/// Returns VOID (TRIGGERS SUCCESS pop up)
static Future<void> addPersonalAppointment(
static Future<int> addPersonalAppointment(
AppUser signedInUser,
String title,
String description,
@@ -200,28 +180,30 @@ class MihMzansiCalendarApis {
"time": time,
}),
);
if (response.statusCode == 201) {
Navigator.pop(context);
Navigator.pop(context);
Navigator.pop(context);
String message =
"Your appointment \"$title\" for the $date $title has been deleted.";
context.pop();
return response.statusCode;
// if (response.statusCode == 201) {
// Navigator.pop(context);
// Navigator.pop(context);
// Navigator.pop(context);
// String message =
// "Your appointment \"$title\" for the $date $title has been deleted.";
// Navigator.pop(context);
Navigator.of(context).pushNamed(
'/calendar',
arguments: CalendarArguments(
signedInUser,
true,
null,
null,
),
);
successPopUp(message, context);
} else {
Navigator.pop(context);
internetConnectionPopUp(context);
}
// // Navigator.pop(context);
// Navigator.of(context).pushNamed(
// '/calendar',
// arguments: CalendarArguments(
// signedInUser,
// true,
// null,
// null,
// ),
// );
// successPopUp(message, context);
// } else {
// Navigator.pop(context);
// internetConnectionPopUp(context);
// }
}
/// This function is used to add an appointment to users mzansi Calendar.
@@ -236,7 +218,7 @@ class MihMzansiCalendarApis {
/// BuildContext context,
///
/// Returns VOID (TRIGGERS SUCCESS pop up)
static Future<void> addBusinessAppointment(
static Future<int> addBusinessAppointment(
AppUser signedInUser,
Business business,
BusinessUser businessUser,
@@ -262,42 +244,44 @@ class MihMzansiCalendarApis {
"time": time,
}),
);
if (response.statusCode == 201) {
// Navigator.pop(context);
Navigator.pop(context);
Navigator.pop(context);
Navigator.pop(context);
String message =
"Your appointment \"$title\" for the $date $title has been deleted.";
context.pop();
return response.statusCode;
// if (response.statusCode == 201) {
// // Navigator.pop(context);
// Navigator.pop(context);
// Navigator.pop(context);
// Navigator.pop(context);
// String message =
// "Your appointment \"$title\" for the $date $title has been deleted.";
// Navigator.pop(context);
if (inWaitingRoom) {
Navigator.of(context).pushNamed(
'/patient-manager',
arguments: PatManagerArguments(
signedInUser,
false,
business,
businessUser,
),
);
} else {
Navigator.of(context).pushNamed(
'/calendar',
arguments: CalendarArguments(
signedInUser,
false,
business,
businessUser,
),
);
}
// // Navigator.pop(context);
// if (inWaitingRoom) {
// Navigator.of(context).pushNamed(
// '/patient-manager',
// arguments: PatManagerArguments(
// signedInUser,
// false,
// business,
// businessUser,
// ),
// );
// } else {
// Navigator.of(context).pushNamed(
// '/calendar',
// arguments: CalendarArguments(
// signedInUser,
// false,
// business,
// businessUser,
// ),
// );
// }
successPopUp(message, context);
} else {
Navigator.pop(context);
internetConnectionPopUp(context);
}
// successPopUp(message, context);
// } else {
// Navigator.pop(context);
// internetConnectionPopUp(context);
// }
}
/// This function is used to add an appointment to users mzansi Calendar.
@@ -312,7 +296,7 @@ class MihMzansiCalendarApis {
/// BuildContext context,
///
/// Returns VOID (TRIGGERS SUCCESS pop up)
static Future<void> addPatientAppointment(
static Future<int> addPatientAppointment(
AppUser signedInUser,
bool personalSelected,
String patientAppId,
@@ -338,20 +322,22 @@ class MihMzansiCalendarApis {
"time": time,
}),
);
if (response.statusCode == 201) {
MihNotificationApis.addNewAppointmentNotificationAPICall(
patientAppId,
personalSelected,
date,
time,
businessArgs,
context,
);
// Navigator.pop(context);
} else {
Navigator.pop(context);
internetConnectionPopUp(context);
}
context.pop();
return response.statusCode;
// if (response.statusCode == 201) {
// MihNotificationApis.addNewAppointmentNotificationAPICall(
// patientAppId,
// personalSelected,
// date,
// time,
// businessArgs,
// context,
// );
// // Navigator.pop(context);
// } else {
// Navigator.pop(context);
// internetConnectionPopUp(context);
// }
}
/// This function is used to update an appointment to users mzansi Calendar.
@@ -367,7 +353,7 @@ class MihMzansiCalendarApis {
/// BuildContext context,
///
/// Returns VOID (TRIGGERS SUCCESS pop up)
static Future<void> updatePersonalAppointment(
static Future<int> updatePersonalAppointment(
AppUser signedInUser,
Business? business,
BusinessUser? businessUser,
@@ -392,28 +378,30 @@ class MihMzansiCalendarApis {
"time": time,
}),
);
if (response.statusCode == 200) {
Navigator.pop(context);
Navigator.pop(context);
Navigator.pop(context);
String message =
"Your appointment \"$title\" has been updates to the $date $title.";
context.pop();
return response.statusCode;
// if (response.statusCode == 200) {
// Navigator.pop(context);
// Navigator.pop(context);
// Navigator.pop(context);
// String message =
// "Your appointment \"$title\" has been updates to the $date $title.";
Navigator.pop(context);
Navigator.of(context).pushNamed(
'/calendar',
arguments: CalendarArguments(
signedInUser,
true,
business,
businessUser,
),
);
successPopUp(message, context);
} else {
Navigator.pop(context);
internetConnectionPopUp(context);
}
// Navigator.pop(context);
// Navigator.of(context).pushNamed(
// '/calendar',
// arguments: CalendarArguments(
// signedInUser,
// true,
// business,
// businessUser,
// ),
// );
// successPopUp(message, context);
// } else {
// Navigator.pop(context);
// internetConnectionPopUp(context);
// }
}
/// This function is used to update an appointment to users mzansi Calendar.
@@ -429,7 +417,7 @@ class MihMzansiCalendarApis {
/// BuildContext context,
///
/// Returns VOID (TRIGGERS SUCCESS pop up)
static Future<void> updateBusinessAppointment(
static Future<int> updateBusinessAppointment(
AppUser signedInUser,
Business? business,
BusinessUser? businessUser,
@@ -454,28 +442,30 @@ class MihMzansiCalendarApis {
"time": time,
}),
);
if (response.statusCode == 200) {
Navigator.pop(context);
Navigator.pop(context);
Navigator.pop(context);
String message =
"Your appointment \"$title\" has been updates to the $date $title.";
context.pop();
return response.statusCode;
// if (response.statusCode == 200) {
// Navigator.pop(context);
// Navigator.pop(context);
// Navigator.pop(context);
// String message =
// "Your appointment \"$title\" has been updates to the $date $title.";
Navigator.pop(context);
Navigator.of(context).pushNamed(
'/calendar',
arguments: CalendarArguments(
signedInUser,
false,
business,
businessUser,
),
);
successPopUp(message, context);
} else {
Navigator.pop(context);
internetConnectionPopUp(context);
}
// Navigator.pop(context);
// Navigator.of(context).pushNamed(
// '/calendar',
// arguments: CalendarArguments(
// signedInUser,
// false,
// business,
// businessUser,
// ),
// );
// successPopUp(message, context);
// } else {
// Navigator.pop(context);
// internetConnectionPopUp(context);
// }
}
/// This function is used to update an appointment to users mzansi Calendar.
@@ -491,7 +481,7 @@ class MihMzansiCalendarApis {
/// BuildContext context,
///
/// Returns VOID (TRIGGERS SUCCESS pop up)
static Future<void> updatePatientAppointment(
static Future<int> updatePatientAppointment(
AppUser signedInUser,
Business? business,
BusinessUser? businessUser,
@@ -516,29 +506,31 @@ class MihMzansiCalendarApis {
"time": time,
}),
);
if (response.statusCode == 200) {
Navigator.pop(context);
Navigator.pop(context);
Navigator.pop(context);
Navigator.pop(context);
String message =
"Your appointment \"$title\" has been updates to the $date $title.";
context.pop();
return response.statusCode;
// if (response.statusCode == 200) {
// Navigator.pop(context);
// Navigator.pop(context);
// Navigator.pop(context);
// Navigator.pop(context);
// String message =
// "Your appointment \"$title\" has been updates to the $date $title.";
// Navigator.pop(context);
Navigator.of(context).pushNamed(
'/patient-manager',
arguments: PatManagerArguments(
signedInUser,
false,
business,
businessUser,
),
);
successPopUp(message, context);
} else {
Navigator.pop(context);
internetConnectionPopUp(context);
}
// // Navigator.pop(context);
// Navigator.of(context).pushNamed(
// '/patient-manager',
// arguments: PatManagerArguments(
// signedInUser,
// false,
// business,
// businessUser,
// ),
// );
// successPopUp(message, context);
// } else {
// Navigator.pop(context);
// internetConnectionPopUp(context);
// }
}
//================== POP UPS ==========================================================================