From 4aa3a83b31bc329e03928d6492e22834a59aa083 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 25 Feb 2024 07:18:45 -0800 Subject: Add announcements page --- modern/src/settings/AnnouncementPage.jsx | 106 ++++++++++++++++++++++++ modern/src/settings/components/SettingsMenu.jsx | 21 +++-- 2 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 modern/src/settings/AnnouncementPage.jsx (limited to 'modern/src/settings') diff --git a/modern/src/settings/AnnouncementPage.jsx b/modern/src/settings/AnnouncementPage.jsx new file mode 100644 index 00000000..39488f02 --- /dev/null +++ b/modern/src/settings/AnnouncementPage.jsx @@ -0,0 +1,106 @@ +import React, { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import { + Accordion, + AccordionSummary, + AccordionDetails, + Typography, + Container, + TextField, + Button, +} from '@mui/material'; +import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; +import { useTranslation } from '../common/components/LocalizationProvider'; +import PageLayout from '../common/components/PageLayout'; +import SettingsMenu from './components/SettingsMenu'; +import { useCatchCallback } from '../reactHelper'; +import useSettingsStyles from './common/useSettingsStyles'; +import SelectField from '../common/components/SelectField'; +import { prefixString } from '../common/util/stringUtils'; + +const AnnouncementPage = () => { + const navigate = useNavigate(); + const classes = useSettingsStyles(); + const t = useTranslation(); + + const [users, setUsers] = useState([]); + const [notificator, setNotificator] = useState(); + const [message, setMessage] = useState({}); + + const handleSend = useCatchCallback(async () => { + const query = new URLSearchParams(); + users.forEach((userId) => query.append('userId', userId)); + const response = await fetch(`/api/notifications/send/${notificator}?${query.toString()}`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(message), + }); + if (response.ok) { + navigate(-1); + } else { + throw Error(await response.text()); + } + }, [users, notificator, message, navigate]); + + return ( + } breadcrumbs={['serverAnnouncement']}> + + + }> + + {t('sharedRequired')} + + + + setUsers(e.target.value)} + endpoint="/api/users" + label={t('settingsUsers')} + /> + setNotificator(e.target.value)} + endpoint="/api/notifications/notificators" + keyGetter={(it) => it.type} + titleGetter={(it) => t(prefixString('notificator', it.type))} + label={t('notificationNotificators')} + /> + setMessage({ ...message, subject: e.target.value })} + label={t('sharedSubject')} + /> + setMessage({ ...message, body: e.target.value })} + label={t('commandMessage')} + /> + + +
+ + +
+
+
+ ); +}; + +export default AnnouncementPage; diff --git a/modern/src/settings/components/SettingsMenu.jsx b/modern/src/settings/components/SettingsMenu.jsx index 0f3ebbe5..6d8c0fd7 100644 --- a/modern/src/settings/components/SettingsMenu.jsx +++ b/modern/src/settings/components/SettingsMenu.jsx @@ -14,6 +14,7 @@ import TodayIcon from '@mui/icons-material/Today'; import PublishIcon from '@mui/icons-material/Publish'; import SmartphoneIcon from '@mui/icons-material/Smartphone'; import HelpIcon from '@mui/icons-material/Help'; +import CampaignIcon from '@mui/icons-material/Campaign'; import { Link, useLocation } from 'react-router-dom'; import { useSelector } from 'react-redux'; import { useTranslation } from '../../common/components/LocalizationProvider'; @@ -139,12 +140,20 @@ const SettingsMenu = () => { {admin && ( - } - selected={location.pathname === '/settings/server'} - /> + <> + } + selected={location.pathname === '/settings/announcement'} + /> + } + selected={location.pathname === '/settings/server'} + /> + )}