import React, { useState } from 'react'; import TextField from '@material-ui/core/TextField'; import { Accordion, AccordionSummary, AccordionDetails, makeStyles, Typography, Button, FormControl, Container, Checkbox, FormControlLabel, InputLabel, Select, MenuItem, } from '@material-ui/core'; import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; import { useHistory } from 'react-router-dom'; import { useDispatch, useSelector } from 'react-redux'; import { sessionActions } from '../store'; import EditAttributesView from './components/EditAttributesView'; import { useTranslation } from '../common/components/LocalizationProvider'; import SelectField from '../common/components/SelectField'; import PageLayout from '../common/components/PageLayout'; import SettingsMenu from './components/SettingsMenu'; import useCommonDeviceAttributes from '../common/attributes/useCommonDeviceAttributes'; import useCommonUserAttributes from '../common/attributes/useCommonUserAttributes'; import { useCatch } from '../reactHelper'; const useStyles = makeStyles((theme) => ({ container: { marginTop: theme.spacing(2), }, buttons: { display: 'flex', justifyContent: 'space-evenly', '& > *': { flexBasis: '33%', }, }, details: { flexDirection: 'column', }, })); const ServerPage = () => { const classes = useStyles(); const history = useHistory(); const dispatch = useDispatch(); const t = useTranslation(); const commonUserAttributes = useCommonUserAttributes(t); const commonDeviceAttributes = useCommonDeviceAttributes(t); const original = useSelector((state) => state.session.server); const [item, setItem] = useState({ ...original }); const handleSave = useCatch(async () => { const response = await fetch('/api/server', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(item), }); if (response.ok) { dispatch(sessionActions.updateServer(await response.json())); history.goBack(); } else { throw Error(await response.text()); } }); return ( } breadcrumbs={['settingsTitle', 'settingsServer']}> {item && ( <> }> {t('sharedPreferences')} setItem({ ...item, mapUrl: event.target.value })} label={t('mapCustomLabel')} variant="filled" /> setItem({ ...item, latitude: Number(event.target.value) })} label={t('positionLatitude')} variant="filled" /> setItem({ ...item, longitude: Number(event.target.value) })} label={t('positionLongitude')} variant="filled" /> setItem({ ...item, zoom: Number(event.target.value) })} label={t('serverZoom')} variant="filled" /> {t('settingsCoordinateFormat')} setItem({ ...item, coordinateFormat: event.target.value })} > {t('sharedDecimalDegrees')} {t('sharedDegreesDecimalMinutes')} {t('sharedDegreesMinutesSeconds')} {t('settingsSpeedUnit')} setItem({ ...item, attributes: { ...item.attributes, speedUnit: e.target.value } })} > {t('sharedKn')} {t('sharedKmh')} {t('sharedMph')} {t('settingsDistanceUnit')} setItem({ ...item, attributes: { ...item.attributes, distanceUnit: e.target.value } })} > {t('sharedKm')} {t('sharedMi')} {t('sharedNmi')} {t('settingsVolumeUnit')} setItem({ ...item, attributes: { ...item.attributes, volumeUnit: e.target.value } })} > {t('sharedLiter')} {t('sharedUsGallon')} {t('sharedImpGallon')} setItem({ ...item, attributes: { ...item.attributes, timezone: e.target.value } })} endpoint="/api/server/timezones" keyGetter={(it) => it} titleGetter={(it) => it} label={t('sharedTimezone')} variant="filled" /> setItem({ ...item, poiLayer: event.target.value })} label={t('mapPoiLayer')} variant="filled" /> setItem({ ...item, announcement: event.target.value })} label={t('serverAnnouncement')} variant="filled" /> setItem({ ...item, twelveHourFormat: event.target.checked })} />} label={t('settingsTwelveHourFormat')} /> setItem({ ...item, forceSettings: event.target.checked })} />} label={t('serverForceSettings')} /> }> {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')} /> setItem({ ...item, disableReports: event.target.checked })} />} label={t('userDisableReports')} /> }> {t('sharedAttributes')} setItem({ ...item, attributes })} definitions={{ ...commonUserAttributes, ...commonDeviceAttributes }} /> > )} history.goBack()}> {t('sharedCancel')} {t('sharedSave')} ); }; export default ServerPage;