diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx
index a736599f..01ab169c 100644
--- a/frontend/src/App.jsx
+++ b/frontend/src/App.jsx
@@ -49,37 +49,8 @@ if ( window.location.port === "3000") {
const App = (message, props) => {
const [userdata, setUserData] = useState({});
- const [notifications, setNotifications] = useState([
- {
- "image": "https://dytvr9ot2sszz.cloudfront.net/whats-new-announcements/billboard_metricsdashbd_sept2021.png",
- "created_at": 1519211809934,
- "updated_at": 1519211809934,
- "title": "some title",
- "description": "This is a description",
- "dismissable": true,
- "personal": false,
- "org_id": "",
- "tags": ["tag1", "tag2"],
- "amount": 3,
- "id": "123",
- "read": false,
- },
- {
- "image": "https://dytvr9ot2sszz.cloudfront.net/whats-new-announcements/billboard_metricsdashbd_sept2021.png",
- "created_at": 1519211809934,
- "updated_at": 1519211809934,
- "title": "some title",
- "description": "This is a description",
- "dismissable": true,
- "personal": false,
- "org_id": "",
- "tags": ["tag1", "tag2"],
- "amount": 3,
- "id": "456",
- "read": true,
- }
- ]);
- const [cookies, setCookie, removeCookie] = useCookies([]);
+ const [notifications, setNotifications] = useState([])
+ const [cookies, setCookie, removeCookie] = useCookies([])
const [isLoggedIn, setIsLoggedIn] = useState(false);
const [dataset, setDataset] = useState(false);
const [isLoaded, setIsLoaded] = useState(false);
@@ -106,7 +77,7 @@ const App = (message, props) => {
})
.then(response => response.json())
.then(responseJson => {
- if (responseJson.success === true && responseJson.notifications !== null && responseJson.notifications !== undefined) {
+ if (responseJson.success === true && responseJson.notifications !== null && responseJson.notifications !== undefined && responseJson.notifications.length > 0) {
console.log("RESP: ", responseJson)
setNotifications(responseJson.notifications)
}
@@ -157,8 +128,8 @@ const App = (message, props) => {
:
-
-
+
+
} />
} />
} />
diff --git a/frontend/src/components/Header.js b/frontend/src/components/Header.js
index ce5dab2f..d15b37b9 100644
--- a/frontend/src/components/Header.js
+++ b/frontend/src/components/Header.js
@@ -13,7 +13,7 @@ const hoverColor = "#f85a3e"
const hoverOutColor = "#e8eaf6"
const Header = props => {
- const { globalUrl, notifications, isLoggedIn, removeCookie, homePage, isLoaded, userdata, cookies } = props;
+ const { globalUrl, setNotifications, notifications, isLoggedIn, removeCookie, homePage, isLoaded, userdata, cookies } = props;
const theme = useTheme();
const [HomeHoverColor, setHomeHoverColor] = useState(hoverOutColor);
@@ -34,7 +34,7 @@ const Header = props => {
// Don't really care about the logout
fetch(`${globalUrl}/api/v1/notifications/${alert_id}/markasread`, {
credentials: "include",
- method: 'POST',
+ method: 'GET',
headers: {
'Content-Type': 'application/json',
},
@@ -46,16 +46,16 @@ const Header = props => {
return response.json();
}).then(function(responseJson) {
- if (responseJson.success !== undefined && responseJson.success) {
- setTimeout(() => {
- window.location.reload()
- }, 2000)
+ if (responseJson.success === true) {
+ const newNotifications = notifications.filter(data => data.id !== alert_id)
+ console.log("NEW NOTIFICATIONS: ", newNotifications)
+ setNotifications(newNotifications)
} else {
- alert.error("Failed changing org: ", responseJson.reason)
+ alert.error("Failed dismissing notification. Please try again later.")
}
})
.catch(error => {
- console.log("error changing: ", error)
+ console.log("error in notification dismissal: ", error)
//removeCookie("session_token", {path: "/"})
})
}
@@ -187,13 +187,22 @@ const Header = props => {
const {data} = props
return (
-
-
+
+ {/*
{new Date(data.updated_at).toISOString()}
-
-
- {data.title}
-
+ */}
+ {data.reference_url !== undefined && data.reference_url !== null && data.reference_url.length > 0 ?
+
+
+ {data.title}
+
+
+ :
+
+ {data.title}
+
+ }
+
{data.image !== undefined && data.image !== null && data.image.length > 0 ?
:
@@ -372,7 +381,7 @@ const Header = props => {
{avatarMenu}
- {/*notificationMenu*/}
+ {notificationMenu}
{userdata === undefined || userdata.admin === undefined || userdata.admin === null || !userdata.admin ? null :