11import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" ;
22import { faBell } from "@fortawesome/free-solid-svg-icons" ;
33import { useEffect , useState } from "react" ;
4- import { api } from "../../api" ;
4+ //import { api } from "../../api"; //todo: swap out dummy data with real api fetch when backend is ready
5+ import NotificationPopup from "../notifications/NotificationPopup" ;
6+ import { setNotifications as setNotificationsAction } from "../../external/bcanSatchel/actions" ;
7+ import { getAppStore } from "../../external/bcanSatchel/store" ;
8+
59
610// get current user id
711// const currUserID = sessionStorage.getItem('userId');
8- const currUserID = "bcanuser33" ;
12+ // const currUserID = "bcanuser33";
913
1014const BellButton = ( ) => {
1115 // stores notifications for the current user
12- const [ notifications , setNotifications ] = useState < any [ ] > ( [ ] ) ;
16+ const store = getAppStore ( ) ;
17+ const notifications = store . notifications ?? [ ] ;
1318
1419 // determines whether bell has been clicked
1520 const [ isClicked , setClicked ] = useState ( false ) ;
@@ -21,55 +26,45 @@ const BellButton = () => {
2126
2227 // function that handles when button is clicked and fetches notifications
2328 const handleClick = async ( ) => {
24- const response = await api (
25- `/notifications/user/${ currUserID } ` ,
26- {
27- method : "GET" ,
28- }
29- ) ;
30- console . log ( response ) ;
31- const currNotifications = await response . json ( ) ;
32- setNotifications ( currNotifications ) ;
29+ //temporary dummy data for now
30+ const dummyNotifications = [
31+ { id : 1 , title : "Grant Deadline" , message : "Grant A deadline approaching in 3 days" } ,
32+ { id : 2 , title : "Grant Deadline" , message : "Grant B deadline tomorrow!" } ,
33+ { id : 3 , title : "Grant Deadline" , message : "Grant C deadline passed yesterday!" } ,
34+ { id : 4 , title : "Grant Deadline" , message : "Grant D deadline tomorrow!" }
35+ ] ;
36+ //previous api logic (for later)
37+ //const response = await api(
38+ //`/notifications/user/${currUserID}`,
39+ //{
40+ //method: "GET",
41+ //}
42+ //);
43+ //console.log(response);
44+ //const currNotifications = await response.json();
45+ setNotificationsAction ( dummyNotifications ) ;
3346 setClicked ( ! isClicked ) ;
3447 return notifications ;
3548 } ;
3649
50+ const handleClose = ( ) => setClicked ( false ) ;
51+
3752 return (
38- < >
53+ < div className = "bell-container" >
3954 < button
4055 className = { `bell-button ${ isClicked ? "hovered" : "" } ` }
4156 onClick = { handleClick }
4257 >
4358 < FontAwesomeIcon icon = { faBell } style = { { color : "black" } } />
4459 </ button >
60+
4561 { isClicked && (
46- < div className = "notification-modal" >
47- < div className = "notification-modal-content" >
48- < h4 >
49- { currUserID ? `Notifications for ${ currUserID } ` : "Notifications" }
50- </ h4 >
51- { notifications . length > 0 ? (
52- < ul >
53- { notifications . map ( ( notification , index ) => (
54- < li key = { index } className = "notification-item" >
55- { notification . message } < br />
56- < small > Alert Time: { notification . alertTime } </ small >
57- </ li >
58- ) ) }
59- </ ul >
60- ) : (
61- < p > No new notifications</ p >
62- ) }
63- < button
64- onClick = { ( ) => setClicked ( false ) }
65- className = "notification-close-button"
66- >
67- Close
68- </ button >
69- </ div >
70- </ div >
62+ < NotificationPopup
63+ notifications = { notifications }
64+ onClose = { handleClose }
65+ />
7166 ) }
72- </ >
67+ </ div >
7368 ) ;
7469} ;
7570
0 commit comments