import React, { useEffect, useState } from 'react'; import { useSelector } from 'react-redux'; import { useHistory, useParams } from 'react-router-dom'; import { Accordion, AccordionSummary, AccordionDetails, makeStyles, Typography, Container, TextField, FormControl, Button, } from '@material-ui/core'; import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; import { useTranslation } from '../common/components/LocalizationProvider'; import OptionsLayout from './components/OptionsLayout'; const useStyles = makeStyles((theme) => ({ container: { marginTop: theme.spacing(2), }, buttons: { display: 'flex', justifyContent: 'space-evenly', '& > *': { flexBasis: '33%', }, }, details: { flexDirection: 'column', }, })); const AccumulatorsPage = () => { const history = useHistory(); const classes = useStyles(); const t = useTranslation(); const { deviceId } = useParams(); const position = useSelector((state) => state.positions.items[deviceId]); const [item, setItem] = useState(); useEffect(() => { if (position) { setItem({ deviceId: parseInt(deviceId, 10), hours: position.attributes.hours || 0, totalDistance: position.attributes.totalDistance || 0, }); } }, [deviceId, position]); const handleSave = async () => { const response = await fetch(`/api/devices/${deviceId}/accumulators`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(item), }); if (response.ok) { history.goBack(); } }; return ( {item && ( }> {t('sharedRequired')} setItem({ ...item, hours: Number(event.target.value) })} label={t('positionHours')} variant="filled" /> setItem({ ...item, totalDistance: Number(event.target.value) })} label={t('deviceTotalDistance')} variant="filled" />
)}
); }; export default AccumulatorsPage;