Skip to content

Commit

Permalink
feat(notice-board): use axios instead of unnecesary apiFetch
Browse files Browse the repository at this point in the history
  • Loading branch information
wri7tno committed Oct 12, 2023
1 parent 344036c commit 901704d
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pages/dashboards/[[...location]].js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const getServerSideProps = async ({ params, query, req }) => {
}

let countryData = await getCategorisedCountries(true);
const notifications = await getPublishedNotifications({});
const notifications = await getPublishedNotifications();

if (!type || type === 'global') {
// get global data
Expand Down
2 changes: 1 addition & 1 deletion pages/grants-and-fellowships/[section].js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const getServerSideProps = async ({ query }) => {
};
}

const notifications = await getPublishedNotifications({});
const notifications = await getPublishedNotifications();

if (query?.section === 'projects') {
const pageTexts = await getSGFPage();
Expand Down
2 changes: 1 addition & 1 deletion pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const HomePage = (props) => (

export const getStaticProps = async () => {
const newsArticles = await getNewsArticles();
const notifications = await getPublishedNotifications({});
const notifications = await getPublishedNotifications();

return {
props: {
Expand Down
2 changes: 1 addition & 1 deletion pages/map/[[...location]].js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const ALLOWED_TYPES = ['global', 'country', 'wdpa', 'use', 'geostore', 'aoi'];
export const getServerSideProps = async ({ req, params }) => {
const [type] = params?.location || [];
let userToken = null;
const notifications = await getPublishedNotifications({});
const notifications = await getPublishedNotifications();

try {
userToken = parse(req.headers.cookie)['gfw-token'];
Expand Down
2 changes: 1 addition & 1 deletion pages/my-gfw.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const MyGfwPage = (props) => (
);

export const getStaticProps = async () => {
const notifications = await getPublishedNotifications({});
const notifications = await getPublishedNotifications();

return {
props: {
Expand Down
4 changes: 2 additions & 2 deletions services/__tests__/notifications.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe.skip('getPublishedNotifications', () => {

axios.get.mockResolvedValueOnce(response);

const result = await getPublishedNotifications({});
const result = await getPublishedNotifications();

expect(result).toEqual(expectedResult);
});
Expand All @@ -46,7 +46,7 @@ describe.skip('getPublishedNotifications', () => {

axios.get.mockRejectedValueOnce(new Error(message));

const result = await getPublishedNotifications({});
const result = await getPublishedNotifications();

expect(result).toBe(null);
});
Expand Down
12 changes: 4 additions & 8 deletions services/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,11 @@ apiFetch.setFetchHandler(async (options) => {
});
});

export const getPublishedNotifications = async ({ cancelToken }) => {
export const getPublishedNotifications = async () => {
try {
const notificationsData = await apiFetch({
url: `${process.env.NEXT_PUBLIC_WORDPRESS_URL}/wp/v2/notice?per_page=100&page=1&orderby=date&order=desc`,
params: {
_embed: true,
},
cancelToken,
});
const notificationsData = await axios(
`${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)
Expand Down

0 comments on commit 901704d

Please sign in to comment.