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 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'; import useSettingsStyles from './common/useSettingsStyles'; const CommandDevicePage = () => { const navigate = useNavigate(); const classes = useSettingsStyles(); 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;