diff --git a/lib/api_service.dart b/lib/api_service.dart index 6d2de28..e265ed1 100644 --- a/lib/api_service.dart +++ b/lib/api_service.dart @@ -64,6 +64,32 @@ class ApiService { } } + static Future> handleProjectDeletionRequest(int notificationId) async { + final accessToken = await getAccessToken(); + if (accessToken == null) { + throw Exception('JWT token not found'); + } + + final Uri url = Uri.parse('$baseUrl/delete_project_request/$notificationId'); + + try { + final http.Response response = await http.delete( + url, + headers: { + 'Authorization': 'Bearer $accessToken', + 'Accept-Encoding': 'gzip, deflate, br', // Specify the supported compression types + 'Content-Type': 'application/json', // Specify the content type as JSON + }, + ); + + final Map responseBody = jsonDecode(response.body); + + return responseBody; + } catch (e) { + rethrow; + } + } + static Future> updateNotice(Map updateNoticeData, int noticeID) async { final accessToken = await getAccessToken(); if (accessToken == null) { diff --git a/lib/views/screens/admin/project_overview/EditProjectScreenAdmin.dart b/lib/views/screens/admin/project_overview/EditProjectScreenAdmin.dart index 2187e80..a7980bf 100644 --- a/lib/views/screens/admin/project_overview/EditProjectScreenAdmin.dart +++ b/lib/views/screens/admin/project_overview/EditProjectScreenAdmin.dart @@ -2390,33 +2390,33 @@ class _EditProjectScreenAdminState extends State { ), ), const Spacer(), - Visibility( - visible: widget.projectID.isNotEmpty, - child: Padding( - padding: const EdgeInsets.only(right: kDefaultPadding), - child: SizedBox( - height: 40.0, - child: ElevatedButton( - style: themeData.extension()!.errorElevated, - onPressed: () => _doDelete(context), - child: Row( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Padding( - padding: const EdgeInsets.only(right: kDefaultPadding * 0.5), - child: Icon( - Icons.delete_rounded, - size: (themeData.textTheme.labelLarge!.fontSize! + 4.0), - ), - ), - const Text("Delete"), - ], - ), - ), - ), - ), - ), + // Visibility( + // visible: widget.projectID.isNotEmpty, + // child: Padding( + // padding: const EdgeInsets.only(right: kDefaultPadding), + // child: SizedBox( + // height: 40.0, + // child: ElevatedButton( + // style: themeData.extension()!.errorElevated, + // onPressed: () => _doDelete(context), + // child: Row( + // mainAxisSize: MainAxisSize.min, + // crossAxisAlignment: CrossAxisAlignment.center, + // children: [ + // Padding( + // padding: const EdgeInsets.only(right: kDefaultPadding * 0.5), + // child: Icon( + // Icons.delete_rounded, + // size: (themeData.textTheme.labelLarge!.fontSize! + 4.0), + // ), + // ), + // const Text("Delete"), + // ], + // ), + // ), + // ), + // ), + // ), Visibility( visible: widget.projectID.isNotEmpty, child: Padding( diff --git a/lib/views/screens/admin/project_overview/SearchProjectScreen.dart b/lib/views/screens/admin/project_overview/SearchProjectScreen.dart index 6310830..e61c224 100644 --- a/lib/views/screens/admin/project_overview/SearchProjectScreen.dart +++ b/lib/views/screens/admin/project_overview/SearchProjectScreen.dart @@ -141,9 +141,9 @@ class _SearchProjectScreenState extends State { _dataSource = DataSource( onViewButtonPressed: (data) => GoRouter.of(context).go('${RouteUri.viewprojectadmin}?projectid=${data['ProjectID']}'), onEditButtonPressed: (data) => GoRouter.of(context).go('${RouteUri.editprojectadmin}?projectid=${data['ProjectID']}'), - onDeleteButtonPressed: (data) { - deleteProject(data['ProjectID']); - }, + // onDeleteButtonPressed: (data) { + // deleteProject(data['ProjectID']); + // }, data: [], ); } @@ -345,13 +345,13 @@ class _SearchProjectScreenState extends State { class DataSource extends DataTableSource { final void Function(Map data) onEditButtonPressed; final void Function(Map data) onViewButtonPressed; - final void Function(Map data) onDeleteButtonPressed; + // final void Function(Map data) onDeleteButtonPressed; List data; DataSource({ required this.onEditButtonPressed, required this.onViewButtonPressed, - required this.onDeleteButtonPressed, + // required this.onDeleteButtonPressed, required this.data, }); @@ -390,11 +390,11 @@ class DataSource extends DataTableSource { child: const Text("Edit"), ), ), - OutlinedButton( - onPressed: () => onDeleteButtonPressed.call(data), - style: Theme.of(context).extension()!.errorOutlined, - child: const Text("Delete"), - ), + // OutlinedButton( + // onPressed: () => onDeleteButtonPressed.call(data), + // style: Theme.of(context).extension()!.errorOutlined, + // child: const Text("Delete"), + // ), ], ); }, diff --git a/lib/views/screens/admin/project_overview/ViewProjectScreenAdmin.dart b/lib/views/screens/admin/project_overview/ViewProjectScreenAdmin.dart index 2ca5dc5..a99541e 100644 --- a/lib/views/screens/admin/project_overview/ViewProjectScreenAdmin.dart +++ b/lib/views/screens/admin/project_overview/ViewProjectScreenAdmin.dart @@ -3068,33 +3068,33 @@ class _ViewProjectScreenAdminState extends State { ), ), ), - Visibility( - visible: widget.projectID.isNotEmpty, - child: Padding( - padding: const EdgeInsets.only(right: kDefaultPadding), - child: SizedBox( - height: 40.0, - child: ElevatedButton( - style: themeData.extension()!.infoOutlined, - onPressed: () => _goEditPage(context), - child: Row( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Padding( - padding: const EdgeInsets.only(right: kDefaultPadding * 0.5), - child: Icon( - Icons.mode_edit_outline_outlined, - size: (themeData.textTheme.labelLarge!.fontSize! + 4.0), - ), - ), - const Text("Edit Project"), - ], - ), - ), - ), - ), - ) + // Visibility( + // visible: widget.projectID.isNotEmpty, + // child: Padding( + // padding: const EdgeInsets.only(right: kDefaultPadding), + // child: SizedBox( + // height: 40.0, + // child: ElevatedButton( + // style: themeData.extension()!.infoOutlined, + // onPressed: () => _goEditPage(context), + // child: Row( + // mainAxisSize: MainAxisSize.min, + // crossAxisAlignment: CrossAxisAlignment.center, + // children: [ + // Padding( + // padding: const EdgeInsets.only(right: kDefaultPadding * 0.5), + // child: Icon( + // Icons.mode_edit_outline_outlined, + // size: (themeData.textTheme.labelLarge!.fontSize! + 4.0), + // ), + // ), + // const Text("Edit Project"), + // ], + // ), + // ), + // ), + // ), + // ) ], ), ], diff --git a/lib/views/screens/general/notification_panel/ViewIndividualNotificationScreen.dart b/lib/views/screens/general/notification_panel/ViewIndividualNotificationScreen.dart index 2ea2d66..41d9c38 100644 --- a/lib/views/screens/general/notification_panel/ViewIndividualNotificationScreen.dart +++ b/lib/views/screens/general/notification_panel/ViewIndividualNotificationScreen.dart @@ -63,12 +63,78 @@ class _ViewIndividualNotificationScreenState extends State _handleProjectDeletionRequest(BuildContext context) async { + // Extract project ID from the message + int notificationId = int.parse(widget.notificationID); + + // Call the API service to handle the project deletion request + final result = await ApiService.handleProjectDeletionRequest(notificationId); + + if (result['statuscode'] == 401) { + // Handle token expiration + final dialog = AwesomeDialog( + context: context, + dialogType: DialogType.error, + desc: "Token expired. Please login again.", + width: kDialogWidth, + btnOkText: 'OK', + btnOkOnPress: () { + GoRouter.of(context).go(RouteUri.logout); + }, + ); + dialog.show(); + } + if (result['statuscode'] == 404) { + // Handle token expiration + final dialog = AwesomeDialog( + context: context, + dialogType: DialogType.error, + desc: result['error'], + width: kDialogWidth, + btnOkText: 'OK', + btnOkOnPress: () { + GoRouter.of(context).go(RouteUri.viewallnotifications); + }, + ); + dialog.show(); + } + if (result['statuscode'] == 500) { + // Handle token expiration + final dialog = AwesomeDialog( + context: context, + dialogType: DialogType.error, + desc: result['error'], + width: kDialogWidth, + btnOkText: 'OK', + btnOkOnPress: () { + GoRouter.of(context).go(RouteUri.viewallnotifications); + }, + ); + dialog.show(); + } + if (result['statuscode'] == 200) { + final dialog = AwesomeDialog( + context: context, + dialogType: DialogType.success, + desc: result['message'], + width: kDialogWidth, + btnOkText: 'OK', + btnOkOnPress: () { + GoRouter.of(context).go(RouteUri.viewallnotifications); + }, + ); + dialog.show(); + } + } + @override Widget build(BuildContext context) { final themeData = Theme.of(context); @@ -279,34 +345,65 @@ class _ViewIndividualNotificationScreenState extends State()!.successOutlined, - // onPressed: () => _goSaveChanges(context), - // child: Row( - // mainAxisSize: MainAxisSize.min, - // crossAxisAlignment: CrossAxisAlignment.center, - // children: [ - // Padding( - // padding: const EdgeInsets.only(right: kDefaultPadding * 0.5), - // child: Icon( - // Icons.save_outlined, - // size: (themeData.textTheme.labelLarge!.fontSize! + 4.0), - // ), - // ), - // const Text("Save Changes"), - // ], - // ), - // ), - // ), - // ), - // ), + const Spacer(), + Visibility( + // if IsDeleted = 0 , then this project deletion request is not yet done + visible: _formData.message.startsWith('ProjectDeletionRequest') && _formData.isDeleted == 1, + child: Padding( + padding: const EdgeInsets.only(right: kDefaultPadding), + child: SizedBox( + height: 40.0, + child: Tooltip( + message: 'Already Deleted', + child: ElevatedButton( + style: themeData.extension()!.errorOutlined, + onPressed: null, + child: Row( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Padding( + padding: const EdgeInsets.only(right: kDefaultPadding * 0.5), + child: Icon( + Icons.delete_outline_outlined, + size: (themeData.textTheme.labelLarge!.fontSize! + 4.0), + ), + ), + const Text("Delete Requested Project"), + ], + ), + ), + )), + ), + ), + Visibility( + // if IsDeleted = 0 , then this project deletion request is not yet done + visible: _formData.message.startsWith('ProjectDeletionRequest') && _formData.isDeleted == 0, + child: Padding( + padding: const EdgeInsets.only(right: kDefaultPadding), + child: SizedBox( + height: 40.0, + child: ElevatedButton( + style: themeData.extension()!.errorOutlined, + onPressed: () => _handleProjectDeletionRequest(context), + child: Row( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Padding( + padding: const EdgeInsets.only(right: kDefaultPadding * 0.5), + child: Icon( + Icons.delete_outline_outlined, + size: (themeData.textTheme.labelLarge!.fontSize! + 4.0), + ), + ), + const Text("Delete Requested Project"), + ], + ), + ), + ), + ), + ), // Visibility( // visible: widget.notificationID.isNotEmpty, // child: Padding( @@ -357,4 +454,5 @@ class FormData { String message = ''; String timestamp = ''; String isRead = ''; + int isDeleted = 0; }