import React from 'react'; import TextField from '@material-ui/core/TextField'; import { Accordion, AccordionSummary, AccordionDetails, makeStyles, Typography, Button, FormControl, Container, Checkbox, FormControlLabel, } from '@material-ui/core'; import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; import { useHistory } from 'react-router-dom'; import { useDispatch, useSelector } from 'react-redux'; import t from '../common/localization'; import MainToolbar from '../MainToolbar'; import { sessionActions } from '../store'; import EditAttributesView from '../attributes/EditAttributesView'; import deviceAttributes from '../attributes/deviceAttributes'; import userAttributes from '../attributes/userAttributes'; const useStyles = makeStyles((theme) => ({ container: { marginTop: theme.spacing(2), }, buttons: { display: 'flex', justifyContent: 'space-evenly', '& > *': { flexBasis: '33%', }, }, details: { flexDirection: 'column', }, })); const ServerPage = () => { const history = useHistory(); const dispatch = useDispatch(); const classes = useStyles(); const item = useSelector((state) => state.session.server); const setItem = (updatedItem) => dispatch(sessionActions.updateServer(updatedItem)); const handleSave = async () => { const response = await fetch('/api/server', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(item), }); if (response.ok) { history.goBack(); } }; return ( <> {item && ( <> }> {t('sharedPreferences')} setItem({ ...item, announcement: event.target.value })} label={t('serverAnnouncement')} variant="filled" /> }> {t('sharedPermissions')} setItem({ ...item, registration: event.target.checked })} />} label={t('serverRegistration')} /> setItem({ ...item, readonly: event.target.checked })} />} label={t('serverReadonly')} /> setItem({ ...item, deviceReadonly: event.target.checked })} />} label={t('userDeviceReadonly')} /> setItem({ ...item, limitCommands: event.target.checked })} />} label={t('userLimitCommands')} /> }> {t('sharedAttributes')} setItem({ ...item, attributes })} definitions={{ ...userAttributes, ...deviceAttributes }} /> > )} history.goBack()}> {t('sharedCancel')} {t('sharedSave')} > ); }; export default ServerPage;