From f2bd440c7fdf8857a5704f214d96aba3345a14e7 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 20 Apr 2022 18:11:16 -0700 Subject: Add saved commands --- modern/src/settings/CommandPage.js | 85 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 modern/src/settings/CommandPage.js (limited to 'modern/src/settings/CommandPage.js') diff --git a/modern/src/settings/CommandPage.js b/modern/src/settings/CommandPage.js new file mode 100644 index 00000000..8a7f5b94 --- /dev/null +++ b/modern/src/settings/CommandPage.js @@ -0,0 +1,85 @@ +import React, { useEffect, useState } from 'react'; +import { + Accordion, AccordionSummary, AccordionDetails, makeStyles, Typography, TextField, FormControlLabel, Checkbox, +} from '@material-ui/core'; +import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; +import EditItemView from '../EditItemView'; +import { useTranslation } from '../LocalizationProvider'; +import SelectField from '../form/SelectField'; +import { prefixString } from '../common/stringUtils'; +import useCommandAttributes from '../attributes/useCommandAttributes'; + +const useStyles = makeStyles(() => ({ + details: { + flexDirection: 'column', + }, +})); + +const CommandPage = () => { + const classes = useStyles(); + const t = useTranslation(); + + const availableAttributes = useCommandAttributes(t); + + const [item, setItem] = useState(); + const [attributes, setAttributes] = useState([]); + + useEffect(() => { + if (item && item.type) { + setAttributes(availableAttributes[item.type] || []); + } + }, [availableAttributes, item]); + + return ( + + {item && ( + + }> + + {t('sharedRequired')} + + + + setItem({ ...item, description: event.target.value })} + label={t('sharedDescription')} + variant="filled" + /> + setItem({ ...item, type: e.target.value, attributes: {} })} + endpoint="/api/commands/types" + keyGetter={(it) => it.type} + titleGetter={(it) => t(prefixString('command', it.type))} + label={t('sharedType')} + variant="filled" + /> + {attributes.map((attribute) => ( + { + const updateItem = { ...item, attributes: { ...item.attributes } }; + updateItem.attributes[attribute.key] = e.target.value; + setItem(updateItem); + }} + label={attribute.name} + variant="filled" + /> + ))} + setItem({ ...item, textChannel: event.target.checked })} />} + label={t('commandSendSms')} + /> + + + )} + + ); +}; + +export default CommandPage; -- cgit v1.2.3