import React, { useState } from 'react';
import TextField from '@mui/material/TextField';
import {
Accordion,
AccordionSummary,
AccordionDetails,
Typography,
FormControl,
InputLabel,
Select,
MenuItem,
FormControlLabel,
Checkbox,
InputAdornment,
IconButton,
OutlinedInput,
} from '@mui/material';
import makeStyles from '@mui/styles/makeStyles';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import CachedIcon from '@mui/icons-material/Cached';
import { useDispatch, useSelector } from 'react-redux';
import moment from 'moment';
import EditItemView from './components/EditItemView';
import EditAttributesView from './components/EditAttributesView';
import LinkField from '../common/components/LinkField';
import { useTranslation } from '../common/components/LocalizationProvider';
import useUserAttributes from '../common/attributes/useUserAttributes';
import { sessionActions } from '../store';
import SelectField from '../common/components/SelectField';
import SettingsMenu from './components/SettingsMenu';
import useCommonUserAttributes from '../common/attributes/useCommonUserAttributes';
import { useAdministrator, useManager } from '../common/util/permissions';
import { prefixString } from '../common/util/stringUtils';
const useStyles = makeStyles(() => ({
details: {
flexDirection: 'column',
},
}));
const UserPage = () => {
const classes = useStyles();
const dispatch = useDispatch();
const t = useTranslation();
const admin = useAdministrator();
const manager = useManager();
const currentUserId = useSelector((state) => state.session.user.id);
const commonUserAttributes = useCommonUserAttributes(t);
const userAttributes = useUserAttributes(t);
const [item, setItem] = useState();
const onItemSaved = (result) => {
if (result.id === currentUserId) {
dispatch(sessionActions.updateUser(result));
}
};
const validate = () => item && item.name && item.email && (item.id || item.password);
return (
}
breadcrumbs={['settingsTitle', 'settingsUser']}
>
{item && (
<>
}>
{t('sharedRequired')}
setItem({ ...item, name: event.target.value })}
label={t('sharedName')}
/>
setItem({ ...item, email: event.target.value })}
label={t('userEmail')}
/>
setItem({ ...item, password: event.target.value })}
label={t('userPassword')}
/>
}>
{t('sharedPreferences')}
setItem({ ...item, phone: event.target.value })}
label={t('sharedPhone')}
/>
setItem({ ...item, latitude: Number(event.target.value) })}
label={t('positionLatitude')}
/>
setItem({ ...item, longitude: Number(event.target.value) })}
label={t('positionLongitude')}
/>
setItem({ ...item, zoom: Number(event.target.value) })}
label={t('serverZoom')}
/>
{t('settingsCoordinateFormat')}
{t('settingsSpeedUnit')}
{t('settingsDistanceUnit')}
{t('settingsVolumeUnit')}
setItem({ ...item, attributes: { ...item.attributes, timezone: e.target.value } })}
endpoint="/api/server/timezones"
keyGetter={(it) => it}
titleGetter={(it) => it}
label={t('sharedTimezone')}
/>
setItem({ ...item, poiLayer: event.target.value })}
label={t('mapPoiLayer')}
/>
setItem({ ...item, twelveHourFormat: event.target.checked })} />}
label={t('settingsTwelveHourFormat')}
/>
}>
{t('sharedPermissions')}
{t('userToken')}
setItem({ ...item, token: e.target.value })}
endAdornment={(
{
const token = [...Array(30)].map(() => Math.random().toString(36)[2]).join('');
setItem({ ...item, token });
}}
>
)}
/>
setItem({ ...item, expirationTime: moment(e.target.value, moment.HTML5_FMT.DATE) })}
disabled={!manager}
/>
setItem({ ...item, deviceLimit: Number(e.target.value) })}
label={t('userDeviceLimit')}
disabled={!admin}
/>
setItem({ ...item, userLimit: Number(e.target.value) })}
label={t('userUserLimit')}
disabled={!admin}
/>
setItem({ ...item, disabled: e.target.checked })} />}
label={t('sharedDisabled')}
disabled={!manager}
/>
setItem({ ...item, administrator: e.target.checked })} />}
label={t('userAdmin')}
disabled={!admin}
/>
setItem({ ...item, readonly: e.target.checked })} />}
label={t('serverReadonly')}
disabled={!manager}
/>
setItem({ ...item, deviceReadonly: e.target.checked })} />}
label={t('userDeviceReadonly')}
disabled={!manager}
/>
setItem({ ...item, limitCommands: e.target.checked })} />}
label={t('userLimitCommands')}
disabled={!manager}
/>
setItem({ ...item, disableReports: e.target.checked })} />}
label={t('userDisableReports')}
disabled={!manager}
/>
}>
{t('sharedAttributes')}
setItem({ ...item, attributes })}
definitions={{ ...commonUserAttributes, ...userAttributes }}
/>
{item.id && manager && (
}>
{t('sharedConnections')}
t(prefixString('event', it.type))}
label={t('sharedNotifications')}
/>
it.description}
label={t('sharedComputedAttributes')}
/>
it.description}
label={t('sharedSavedCommands')}
/>
)}
>
)}
);
};
export default UserPage;