File tree Expand file tree Collapse file tree 1 file changed +29
-3
lines changed
src/components/pages/dashboard Expand file tree Collapse file tree 1 file changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -135,14 +135,40 @@ export default function NotificationsPopup() {
135135 } ;
136136 } , [ isOpen ] ) ;
137137
138- const markAsRead = ( id ) => {
138+ const markAsRead = async ( id ) => {
139139 setNotifications ( ( prev ) =>
140140 prev . map ( ( n ) => ( n . _id === id ? { ...n , read : true } : n ) )
141141 ) ;
142+ try {
143+ const response = await fetch ( "/api/notifications/read" , {
144+ method : "PATCH" ,
145+ headers : { "Content-Type" : "application/json" , uid : uid } ,
146+ body : JSON . stringify ( { nid : id } ) ,
147+ } ) ;
148+
149+ if ( ! response . ok ) {
150+ throw new Error ( "Failed to mark notification as read" ) ;
151+ }
152+ } catch ( error ) {
153+ console . error ( "Error marking notification as read:" , error ) ;
154+ }
142155 } ;
143156
144- const removeNotification = ( id ) => {
145- setNotifications ( notifications . filter ( ( n ) => n . _id !== id ) ) ;
157+ const removeNotification = async ( id ) => {
158+ setNotifications ( ( prev ) => prev . filter ( ( n ) => n . _id !== id ) ) ;
159+ try {
160+ const response = await fetch ( "/api/notifications/delete" , {
161+ method : "DELETE" ,
162+ headers : { "Content-Type" : "application/json" , uid : uid } ,
163+ body : JSON . stringify ( { nid : id } ) ,
164+ } ) ;
165+
166+ if ( ! response . ok ) {
167+ throw new Error ( "Failed to delete notification" ) ;
168+ }
169+ } catch ( error ) {
170+ console . error ( "Error deleting notification:" , error ) ;
171+ }
146172 } ;
147173
148174 return (
You can’t perform that action at this time.
0 commit comments