aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-26 19:27:47 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-26 19:27:47 -0700
commitf673b9ae8d2aa1b6b7bf13484b02cc8d4f46cd08 (patch)
treedfb5d0b1703e19864160d7b7018e3d1a17761d01
parentff8e5ad793352facbd6200d0b059a0c970b6da84 (diff)
downloadtrackermap-web-f673b9ae8d2aa1b6b7bf13484b02cc8d4f46cd08.tar.gz
trackermap-web-f673b9ae8d2aa1b6b7bf13484b02cc8d4f46cd08.tar.bz2
trackermap-web-f673b9ae8d2aa1b6b7bf13484b02cc8d4f46cd08.zip
Add notification testing
-rw-r--r--modern/src/settings/NotificationPage.js41
-rw-r--r--web/l10n/en.json2
2 files changed, 33 insertions, 10 deletions
diff --git a/modern/src/settings/NotificationPage.js b/modern/src/settings/NotificationPage.js
index 4aa318ae..a5a9d8d2 100644
--- a/modern/src/settings/NotificationPage.js
+++ b/modern/src/settings/NotificationPage.js
@@ -8,6 +8,7 @@ import {
FormControlLabel,
Checkbox,
FormGroup,
+ Button,
} from '@mui/material';
import makeStyles from '@mui/styles/makeStyles';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
@@ -16,6 +17,7 @@ import EditItemView from './components/EditItemView';
import { prefixString, unprefixString } from '../common/util/stringUtils';
import SelectField from '../common/components/SelectField';
import SettingsMenu from './components/SettingsMenu';
+import { useCatch } from '../reactHelper';
const useStyles = makeStyles((theme) => ({
details: {
@@ -37,6 +39,19 @@ const NotificationPage = () => {
name: t(it),
}));
+ const testNotificators = useCatch(async () => {
+ await Promise.all(item.notificators.split(/[, ]+/).map(async (notificator) => {
+ const response = await fetch(`/api/notifications/test/${notificator}`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify(item),
+ });
+ if (!response.ok) {
+ throw Error(await response.text());
+ }
+ }));
+ });
+
const validate = () => item && item.type && item.notificators;
return (
@@ -66,15 +81,6 @@ const NotificationPage = () => {
titleGetter={(it) => t(prefixString('event', it.type))}
label={t('sharedType')}
/>
- <SelectField
- multiple
- value={item.notificators ? item.notificators.split(/[, ]+/) : []}
- onChange={(e) => setItem({ ...item, notificators: e.target.value.join() })}
- endpoint="/api/notifications/notificators"
- keyGetter={(it) => it.type}
- titleGetter={(it) => t(prefixString('notificator', it.type))}
- label={t('notificationNotificators')}
- />
{item.type === 'alarm' && (
<SelectField
multiple
@@ -85,6 +91,23 @@ const NotificationPage = () => {
label={t('sharedAlarms')}
/>
)}
+ <SelectField
+ multiple
+ value={item.notificators ? item.notificators.split(/[, ]+/) : []}
+ onChange={(e) => setItem({ ...item, notificators: e.target.value.join() })}
+ endpoint="/api/notifications/notificators"
+ keyGetter={(it) => it.type}
+ titleGetter={(it) => t(prefixString('notificator', it.type))}
+ label={t('notificationNotificators')}
+ />
+ <Button
+ variant="outlined"
+ color="primary"
+ onClick={testNotificators}
+ disabled={!item.notificators}
+ >
+ {t('sharedTestNotificators')}
+ </Button>
<FormGroup>
<FormControlLabel
control={(
diff --git a/web/l10n/en.json b/web/l10n/en.json
index 4db574e2..fc5a13a1 100644
--- a/web/l10n/en.json
+++ b/web/l10n/en.json
@@ -59,7 +59,7 @@
"sharedDevice": "Device",
"sharedTest": "Test",
"sharedTestNotification": "Send Test Notification",
- "sharedTestChannels": "Test Channels",
+ "sharedTestNotificators": "Test Channels",
"sharedTestExpression": "Test Expression",
"sharedCalendar": "Calendar",
"sharedCalendars": "Calendars",