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]); const validate = () => item && item.type; 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;