-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(page): fetch notifications and pass them as props to Header comp…
…onent
- Loading branch information
Showing
6 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,5 @@ yarn-error.log* | |
|
||
# new relic agent | ||
newrelic_agent.log | ||
|
||
.yalc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import axios from 'axios'; | ||
|
||
const mapResponseToNotification = ({ | ||
id, | ||
date, | ||
status, | ||
title, | ||
content, | ||
acf, | ||
}) => { | ||
return { | ||
id, | ||
dateCreated: date, | ||
status, | ||
title: title.rendered, | ||
content: content.rendered, | ||
icon: acf.notification_icon, | ||
date: acf.notification_date, | ||
}; | ||
}; | ||
|
||
export const getPublishedNotifications = async () => { | ||
try { | ||
const notificationsData = await axios.get( | ||
`${process.env.NEXT_PUBLIC_WORDPRESS_URL}/wp/v2/notice?per_page=100&page=1&orderby=date&order=desc` | ||
); | ||
|
||
return notificationsData?.data.map((item) => | ||
mapResponseToNotification(item) | ||
); | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.error('error trying to fetch notifications', e); | ||
return null; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters