diff --git a/.env b/.env index be67b867f..f91227cc7 100644 --- a/.env +++ b/.env @@ -132,11 +132,6 @@ REACT_APP_ATTIC_QUERY_OFFSET_MINUTES = 10 REACT_APP_MATOMO_URL='' REACT_APP_MATOMO_SITE_ID='' -# Optional URL to a JSON file containing system notices to be displayed to -# users, such as notice of upcoming maintenance. See: -# https://github.com/maproulette/maproulette3/wiki/Server-Admin:-System-Notices -# for details -REACT_APP_SYSTEM_NOTICES_URL='' REACT_APP_FUNDRAISING_NOTICES_URL='' # Custom keyword categories configuration # Additional categories of one or more keywords can be added into the Work On diff --git a/src/components/SystemNotices/SystemNotices.js b/src/components/SystemNotices/SystemNotices.js index 2a6849c99..d60e48093 100644 --- a/src/components/SystemNotices/SystemNotices.js +++ b/src/components/SystemNotices/SystemNotices.js @@ -16,9 +16,9 @@ const SystemNotices = function(props) { > diff --git a/src/services/Server/APIRoutes.js b/src/services/Server/APIRoutes.js index ae071fe2c..b2addf868 100644 --- a/src/services/Server/APIRoutes.js +++ b/src/services/Server/APIRoutes.js @@ -188,6 +188,7 @@ const apiRoutes = (factory) => { notifications: factory.get("/user/:userId/notifications"), markNotificationsRead: factory.put("/user/:userId/notifications"), deleteNotifications: factory.put("/user/:userId/notifications/delete"), + announcements: factory.get("/user/announcements") }, teams: { find: factory.get("/teams/find"), diff --git a/src/services/SystemNotices/SystemNotices.js b/src/services/SystemNotices/SystemNotices.js index 264675e17..31d6b773c 100644 --- a/src/services/SystemNotices/SystemNotices.js +++ b/src/services/SystemNotices/SystemNotices.js @@ -1,9 +1,8 @@ -import _isEmpty from 'lodash/isEmpty' import _isArray from 'lodash/isArray' import parse from 'date-fns/parse' import isFuture from 'date-fns/is_future' - -const NOTICES_URL = process.env.REACT_APP_SYSTEM_NOTICES_URL +import Endpoint from '../Server/Endpoint' +import { defaultRoutes as api } from "../Server/Server"; /** * Fetches system notices from the configured URL. Reponse is expected to be a @@ -32,26 +31,21 @@ const NOTICES_URL = process.env.REACT_APP_SYSTEM_NOTICES_URL * } * ``` */ -export const fetchActiveSystemNotices = async function() { - if (_isEmpty(NOTICES_URL)) { - return [] - } - - const response = await fetch(NOTICES_URL) - if (response.ok) { - const systemNotices = await response.json() - if (!systemNotices || !_isArray(systemNotices.notices)) { - return [] - } - - return systemNotices.notices.map(notice => { - // add Date instance for expiration timestamp - notice.expirationDate = parse(notice.expirationTimestamp) - return notice - }).filter(notice => isFuture(notice.expirationDate)) - } - else { - // Allow server admin to delete file when not in use - return [] - } +export const fetchActiveSystemNotices = () => { + return new Endpoint(api.user.announcements) + .execute() + .then(response => { + const systemNotices = response?.message?.notices + if (_isArray(systemNotices)) { + return systemNotices.map(notice => { + // add Date instance for expiration timestamp + notice.expirationDate = parse(notice.expirationTimestamp) + return notice + }).filter(notice => isFuture(notice.expirationDate)) + } + else { + // Allow server admin to delete file when not in use + return [] + } + }) }