From ed156c003177a577a1356a6e3d1ff3ca05b761fe Mon Sep 17 00:00:00 2001 From: yaso Date: Mon, 7 Oct 2024 14:51:34 +0200 Subject: [PATCH] update notification to read on click --- .../mih_layout/mih_notification_drawer.dart | 53 ++++++++++++++++--- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/Frontend/patient_manager/lib/mih_components/mih_layout/mih_notification_drawer.dart b/Frontend/patient_manager/lib/mih_components/mih_layout/mih_notification_drawer.dart index 083a034b..0851ea31 100644 --- a/Frontend/patient_manager/lib/mih_components/mih_layout/mih_notification_drawer.dart +++ b/Frontend/patient_manager/lib/mih_components/mih_layout/mih_notification_drawer.dart @@ -1,7 +1,10 @@ import 'package:flutter/material.dart'; import 'package:patient_manager/main.dart'; +import 'package:patient_manager/mih_components/mih_pop_up_messages/mih_error_message.dart'; +import 'package:patient_manager/mih_env/env.dart'; import 'package:patient_manager/mih_objects/app_user.dart'; import 'package:patient_manager/mih_objects/notification.dart'; +import 'package:supertokens_flutter/http.dart' as http; class MIHNotificationDrawer extends StatefulWidget { final AppUser signedInUser; @@ -20,6 +23,35 @@ class MIHNotificationDrawer extends StatefulWidget { class _MIHNotificationDrawerState extends State { late List> notificationList; + final baseAPI = AppEnviroment.baseApiUrl; + Future updateNotificationAPICall(int index) async { + var response = await http.put( + Uri.parse( + "$baseAPI/notifications/update/${widget.notifications[index].idnotifications}"), + ); + if (response.statusCode == 200) { + Navigator.of(context).pop(); + Navigator.of(context).pop(); + Navigator.of(context).pushNamed( + "/", + ); + Navigator.of(context).pushNamed( + widget.notifications[index].action_path, + arguments: widget.signedInUser, + ); + } else { + internetConnectionPopUp(); + } + } + + void internetConnectionPopUp() { + showDialog( + context: context, + builder: (context) { + return const MIHErrorMessage(errorType: "Internet Connection"); + }, + ); + } List> setTempNofitications() { List> temp = []; @@ -52,9 +84,7 @@ class _MIHNotificationDrawerState extends State { color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), ), ), - onTap: () { - //viewApprovalPopUp(index); - }, + onTap: () {}, ); } @@ -65,7 +95,10 @@ class _MIHNotificationDrawerState extends State { if (widget.notifications[index].notification_read == "No") { notificationTitle = Row( children: [ - const Icon(Icons.circle_notifications), + Icon( + Icons.circle_notifications, + color: MzanziInnovationHub.of(context)!.theme.errorColor(), + ), const SizedBox( width: 5, ), @@ -103,10 +136,14 @@ class _MIHNotificationDrawerState extends State { ), ), onTap: () { - Navigator.of(context).pushNamed( - widget.notifications[index].action_path, - arguments: widget.signedInUser, - ); + if (widget.notifications[index].notification_read == "No") { + updateNotificationAPICall(index); + } else { + Navigator.of(context).pushNamed( + widget.notifications[index].action_path, + arguments: widget.signedInUser, + ); + } }, ); }