aboutsummaryrefslogtreecommitdiff
path: root/modern/src/settings
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-09-30 22:43:57 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-09-30 22:43:57 -0700
commit66d2b91dfdcfb4b5c5fe90ddb7a3e3e66e01e502 (patch)
tree1817859d1baab737de93e433315b9e549e6f0895 /modern/src/settings
parent542f96da0ef323f286aa9caa8cfffaa98094467e (diff)
downloadtrackermap-web-66d2b91dfdcfb4b5c5fe90ddb7a3e3e66e01e502.tar.gz
trackermap-web-66d2b91dfdcfb4b5c5fe90ddb7a3e3e66e01e502.tar.bz2
trackermap-web-66d2b91dfdcfb4b5c5fe90ddb7a3e3e66e01e502.zip
Migrate Select to SelectField
Diffstat (limited to 'modern/src/settings')
-rw-r--r--modern/src/settings/NotificationPage.js85
1 files changed, 30 insertions, 55 deletions
diff --git a/modern/src/settings/NotificationPage.js b/modern/src/settings/NotificationPage.js
index 5a772d0c..2cf8a62f 100644
--- a/modern/src/settings/NotificationPage.js
+++ b/modern/src/settings/NotificationPage.js
@@ -2,10 +2,10 @@ import React, { useState } from 'react';
import t, { findStringKeys } from '../common/localization';
import EditItemView from '../EditItemView';
-import { Accordion, AccordionSummary, AccordionDetails, makeStyles, Typography, FormControlLabel, Checkbox, FormControl, InputLabel, Select, MenuItem } from '@material-ui/core';
+import { Accordion, AccordionSummary, AccordionDetails, makeStyles, Typography, FormControlLabel, Checkbox } from '@material-ui/core';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
-import { useEffectAsync } from '../reactHelper';
import { prefixString, unprefixString } from '../common/stringUtils';
+import SelectField from '../form/SelectField';
const useStyles = makeStyles(() => ({
details: {
@@ -17,28 +17,12 @@ const NotificationPage = () => {
const classes = useStyles();
const [item, setItem] = useState();
- const [types, setTypes] = useState();
- const [notificators, setNotificators] = useState();
const alarms = findStringKeys(it => it.startsWith('alarm')).map(it => ({
key: unprefixString('alarm', it),
name: t(it),
}));
- useEffectAsync(async () => {
- const response = await fetch('/api/notifications/types');
- if (response.ok) {
- setTypes(await response.json());
- }
- }, []);
-
- useEffectAsync(async () => {
- const response = await fetch('/api/notifications/notificators');
- if (response.ok) {
- setNotificators(await response.json());
- }
- }, []);
-
return (
<EditItemView endpoint="notifications" item={item} setItem={setItem}>
{item &&
@@ -50,44 +34,35 @@ const NotificationPage = () => {
</Typography>
</AccordionSummary>
<AccordionDetails className={classes.details}>
- {types &&
- <FormControl margin="normal" variant="filled">
- <InputLabel>{t('sharedType')}</InputLabel>
- <Select
- native
- defaultValue={item.type}
- onChange={e => setItem({...item, type: e.target.value})}>
- {types.map(it => (
- <option key={it.type} value={it.type}>{t(prefixString('event', it.type))}</option>
- ))}
- </Select>
- </FormControl>
- }
- {notificators &&
- <FormControl margin="normal" variant="filled">
- <InputLabel>{t('notificationNotificators')}</InputLabel>
- <Select
- multiple
- defaultValue={item.notificators ? item.notificators.split(/[, ]+/) : []}
- onChange={e => setItem({...item, notificators: e.target.value.join()})}>
- {notificators.map(it => (
- <MenuItem key={it.type} value={it.type}>{t(prefixString('notificator', it.type))}</MenuItem>
- ))}
- </Select>
- </FormControl>
- }
+ <SelectField
+ margin="normal"
+ defaultValue={item.type}
+ onChange={e => setItem({...item, type: e.target.value})}
+ endpoint="/api/notifications/types"
+ keyGetter={it => it.type}
+ titleGetter={it => t(prefixString('event', it.type))}
+ label={t('sharedType')}
+ variant="filled" />
+ <SelectField
+ multiple
+ margin="normal"
+ defaultValue={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')}
+ variant="filled" />
{item.type === 'alarm' &&
- <FormControl margin="normal" variant="filled">
- <InputLabel>{t('sharedAlarms')}</InputLabel>
- <Select
- multiple
- defaultValue={item.attributes && item.attributes.alarms ? item.attributes.alarms.split(/[, ]+/) : []}
- onChange={e => setItem({...item, attributes: {...item.attributes, alarms: e.target.value.join()}})}>
- {alarms.map(it => (
- <MenuItem key={it.key} value={it.key}>{it.name}</MenuItem>
- ))}
- </Select>
- </FormControl>
+ <SelectField
+ multiple
+ margin="normal"
+ defaultValue={item.attributes && item.attributes.alarms ? item.attributes.alarms.split(/[, ]+/) : []}
+ onChange={e => setItem({...item, attributes: {...item.attributes, alarms: e.target.value.join()}})}
+ data={alarms}
+ keyGetter={it => it.key}
+ label={t('sharedAlarms')}
+ variant="filled" />
}
<FormControlLabel
control={