From 89a40e48259ce39959101b4f1f7dc5e26c630b74 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 24 Feb 2024 13:47:19 -0800 Subject: Unify settings styles --- .../components/EditAttributesAccordion.jsx | 16 ++------------- modern/src/settings/components/EditItemView.jsx | 23 ++-------------------- 2 files changed, 4 insertions(+), 35 deletions(-) (limited to 'modern/src/settings/components') diff --git a/modern/src/settings/components/EditAttributesAccordion.jsx b/modern/src/settings/components/EditAttributesAccordion.jsx index 214ddb0e..4d4ae254 100644 --- a/modern/src/settings/components/EditAttributesAccordion.jsx +++ b/modern/src/settings/components/EditAttributesAccordion.jsx @@ -15,7 +15,6 @@ import { Typography, AccordionDetails, } from '@mui/material'; -import makeStyles from '@mui/styles/makeStyles'; import CloseIcon from '@mui/icons-material/Close'; import AddIcon from '@mui/icons-material/Add'; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; @@ -26,21 +25,10 @@ import { distanceFromMeters, distanceToMeters, distanceUnitString, speedFromKnots, speedToKnots, speedUnitString, volumeFromLiters, volumeToLiters, volumeUnitString, } from '../../common/util/converter'; import useFeatures from '../../common/util/useFeatures'; - -const useStyles = makeStyles((theme) => ({ - removeButton: { - marginRight: theme.spacing(1.5), - }, - details: { - display: 'flex', - flexDirection: 'column', - gap: theme.spacing(2), - paddingBottom: theme.spacing(3), - }, -})); +import useSettingsStyles from '../common/useSettingsStyles'; const EditAttributesAccordion = ({ attribute, attributes, setAttributes, definitions, focusAttribute }) => { - const classes = useStyles(); + const classes = useSettingsStyles(); const t = useTranslation(); const features = useFeatures(); diff --git a/modern/src/settings/components/EditItemView.jsx b/modern/src/settings/components/EditItemView.jsx index d45855dd..61bc4161 100644 --- a/modern/src/settings/components/EditItemView.jsx +++ b/modern/src/settings/components/EditItemView.jsx @@ -1,37 +1,18 @@ import React from 'react'; import { useNavigate, useParams } from 'react-router-dom'; -import makeStyles from '@mui/styles/makeStyles'; import { Container, Button, Accordion, AccordionDetails, AccordionSummary, Skeleton, Typography, TextField, } from '@mui/material'; import { useCatch, useEffectAsync } from '../../reactHelper'; import { useTranslation } from '../../common/components/LocalizationProvider'; import PageLayout from '../../common/components/PageLayout'; - -const useStyles = makeStyles((theme) => ({ - container: { - marginTop: theme.spacing(2), - }, - buttons: { - marginTop: theme.spacing(2), - marginBottom: theme.spacing(2), - display: 'flex', - justifyContent: 'space-evenly', - '& > *': { - flexBasis: '33%', - }, - }, - details: { - display: 'flex', - flexDirection: 'column', - }, -})); +import useSettingsStyles from '../common/useSettingsStyles'; const EditItemView = ({ children, endpoint, item, setItem, defaultItem, validate, onItemSaved, menu, breadcrumbs, }) => { const navigate = useNavigate(); - const classes = useStyles(); + const classes = useSettingsStyles(); const t = useTranslation(); const { id } = useParams(); -- cgit v1.2.3 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/Navigation.jsx | 2 + modern/src/resources/l10n/en.json | 1 + modern/src/settings/AnnouncementPage.jsx | 106 ++++++++++++++++++++++++ modern/src/settings/components/SettingsMenu.jsx | 21 +++-- 4 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 modern/src/settings/AnnouncementPage.jsx (limited to 'modern/src/settings/components') diff --git a/modern/src/Navigation.jsx b/modern/src/Navigation.jsx index 2bec6456..37a6ddb5 100644 --- a/modern/src/Navigation.jsx +++ b/modern/src/Navigation.jsx @@ -56,6 +56,7 @@ import GroupConnectionsPage from './settings/GroupConnectionsPage'; import UserConnectionsPage from './settings/UserConnectionsPage'; import LogsPage from './reports/LogsPage'; import SharePage from './settings/SharePage'; +import AnnouncementPage from './settings/AnnouncementPage'; const Navigation = () => { const navigate = useNavigate(); @@ -111,6 +112,7 @@ const Navigation = () => { } /> + } /> } /> } /> } /> diff --git a/modern/src/resources/l10n/en.json b/modern/src/resources/l10n/en.json index b91312c7..39fb219b 100644 --- a/modern/src/resources/l10n/en.json +++ b/modern/src/resources/l10n/en.json @@ -11,6 +11,7 @@ "sharedRemove": "Remove", "sharedRemoveConfirm": "Remove item?", "sharedNoData": "No data", + "sharedSubject": "Subject", "sharedYes": "Yes", "sharedNo": "No", "sharedKm": "km", 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'} + /> + )}