diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-26 19:27:47 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-26 19:27:47 -0700 |
commit | f673b9ae8d2aa1b6b7bf13484b02cc8d4f46cd08 (patch) | |
tree | dfb5d0b1703e19864160d7b7018e3d1a17761d01 /modern/src/settings | |
parent | ff8e5ad793352facbd6200d0b059a0c970b6da84 (diff) | |
download | trackermap-web-f673b9ae8d2aa1b6b7bf13484b02cc8d4f46cd08.tar.gz trackermap-web-f673b9ae8d2aa1b6b7bf13484b02cc8d4f46cd08.tar.bz2 trackermap-web-f673b9ae8d2aa1b6b7bf13484b02cc8d4f46cd08.zip |
Add notification testing
Diffstat (limited to 'modern/src/settings')
-rw-r--r-- | modern/src/settings/NotificationPage.js | 41 |
1 files changed, 32 insertions, 9 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={( |