import React, { useState } from 'react'; import { useSelector } from 'react-redux'; import { useNavigate, useParams } from 'react-router-dom'; import { Accordion, AccordionSummary, AccordionDetails, Typography, Container, Button, FormControl, InputLabel, Select, MenuItem, FormControlLabel, Checkbox, TextField, } from '@mui/material'; import makeStyles from '@mui/styles/makeStyles'; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; import { useTranslation } from '../common/components/LocalizationProvider'; import PageLayout from '../common/components/PageLayout'; import SettingsMenu from './components/SettingsMenu'; import { useCatch } from '../reactHelper'; const useStyles = makeStyles((theme) => ({ container: { marginTop: theme.spacing(2), }, buttons: { marginTop: theme.spacing(2), marginBottom: theme.spacing(2), display: 'flex', justifyContent: 'space-evenly', '& > *': { flexBasis: '33%', }, }, details: { display: 'flex', flexDirection: 'column', gap: theme.spacing(2), paddingBottom: theme.spacing(3), }, })); const CommandDevicePage = () => { const navigate = useNavigate(); const classes = useStyles(); const t = useTranslation(); const { id } = useParams(); const textEnabled = useSelector((state) => state.session.server.textEnabled); const [item, setItem] = useState({ type: 'custom', attributes: {} }); const handleSend = useCatch(async () => { const query = new URLSearchParams({ groupId: id }); const response = await fetch(`/api/commands/send?${query.toString()}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(item), }); if (response.ok) { navigate(-1); } else { throw Error(await response.text()); } }); return ( } breadcrumbs={['settingsTitle', 'deviceCommand']}> }> {t('sharedRequired')} {t('sharedType')} setItem({ ...item, attributes: { ...item.attributes, data: e.target.value } })} label={t('commandData')} /> {textEnabled && ( setItem({ ...item, textChannel: event.target.checked })} />} label={t('commandSendSms')} /> )}
); }; export default CommandDevicePage;