@@ -47,15 +47,7 @@ const Announcements = () => {
4747 } = useAnnouncements ( ) ;
4848
4949 useEffect ( ( ) => {
50- if ( announcementsData ) {
51- const newRows = announcementsData . map ( ( announcement ) => ( {
52- announcementId : announcement . id ,
53- title : announcement . title ,
54- description : announcement . description ,
55- is_enabled : announcement . is_enabled ,
56- } ) ) ;
57- setRows ( newRows ) ;
58- }
50+ setRows ( announcementsData || [ ] ) ;
5951 } , [ announcementsData ] ) ;
6052
6153 const handleModalClose = ( ) => {
@@ -73,12 +65,17 @@ const Announcements = () => {
7365
7466 const handleIsEnabled = async ( announcementId , isEnabled ) => {
7567 try {
76- await announcementService . update ( announcementId , { is_enabled : isEnabled } ) ;
77- setRows ( ( prevRows ) =>
78- prevRows . map ( ( row ) =>
79- row . announcementId === announcementId ? { ...row , is_enabled : isEnabled } : row
80- )
68+ const announcement = rows . find (
69+ ( row ) => row . announcementId === announcementId
8170 ) ;
71+ if ( ! announcement ) throw new Error ( "Announcement not found" ) ;
72+
73+ await announcementService . update ( announcementId , {
74+ title : announcement . title ,
75+ description : announcement . description ,
76+ is_enabled : isEnabled ,
77+ } ) ;
78+ await announcementRefetch ( ) ;
8279 } catch ( error ) {
8380 console . error ( "Error updating announcement:" , error ) ;
8481 }
@@ -174,7 +171,7 @@ const Announcements = () => {
174171 < TableCell align = "left" > Announcement ID </ TableCell >
175172 < TableCell align = "left" > Announcement Title</ TableCell >
176173 < TableCell align = "left" > Announcement Description</ TableCell >
177- < TableCell align = "left" > Is Enabled? </ TableCell >
174+ < TableCell align = "left" > Enabled</ TableCell >
178175 < TableCell />
179176 </ TableRow >
180177 </ TableHead >
@@ -311,7 +308,7 @@ const Announcements = () => {
311308 onChange = { announcementFormik . handleChange }
312309 />
313310 }
314- label = "Globally Enable "
311+ label = "Enabled "
315312 />
316313 </ Box >
317314 < Box mt = { 3 } display = "flex" justifyContent = "space-between" >
@@ -381,7 +378,7 @@ const Announcements = () => {
381378 onChange = { editFormik . handleChange }
382379 />
383380 }
384- label = "Globally Enable "
381+ label = "Enabled "
385382 />
386383 </ Box >
387384 < Box mt = { 3 } display = "flex" justifyContent = "space-between" >
0 commit comments