diff options
author | Anton Tananaev <anton@traccar.org> | 2022-07-22 17:32:07 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-07-22 17:32:07 -0700 |
commit | f9f5ea547e61b6ff527149fa5814851240d2c967 (patch) | |
tree | e2902f69760c2c2c4837752ef81f44883b231be1 /modern | |
parent | 98cb21230d938ac04f53a4425e5d3eae9cfdbfda (diff) | |
download | trackermap-web-f9f5ea547e61b6ff527149fa5814851240d2c967.tar.gz trackermap-web-f9f5ea547e61b6ff527149fa5814851240d2c967.tar.bz2 trackermap-web-f9f5ea547e61b6ff527149fa5814851240d2c967.zip |
Add device expiration (fix #85)
Diffstat (limited to 'modern')
-rw-r--r-- | modern/src/common/util/formatter.js | 2 | ||||
-rw-r--r-- | modern/src/settings/DevicePage.js | 22 | ||||
-rw-r--r-- | modern/src/settings/UserPage.js | 2 | ||||
-rw-r--r-- | modern/src/settings/UsersPage.js | 4 |
4 files changed, 19 insertions, 11 deletions
diff --git a/modern/src/common/util/formatter.js b/modern/src/common/util/formatter.js index ea18713d..88398c68 100644 --- a/modern/src/common/util/formatter.js +++ b/modern/src/common/util/formatter.js @@ -17,7 +17,7 @@ export const formatNumber = (value, precision = 1) => Number(value.toFixed(preci export const formatPercentage = (value) => `${value}%`; -export const formatTime = (value, format = 'YYYY-MM-DD HH:mm:ss') => moment(value).format(format); +export const formatTime = (value, format = 'YYYY-MM-DD HH:mm:ss') => (value ? moment(value).format(format) : ''); export const formatStatus = (value, t) => t(prefixString('deviceStatus', value)); export const formatAlarm = (value, t) => (value ? t(prefixString('alarm', value)) : ''); diff --git a/modern/src/settings/DevicePage.js b/modern/src/settings/DevicePage.js index b54c7c81..49f765a7 100644 --- a/modern/src/settings/DevicePage.js +++ b/modern/src/settings/DevicePage.js @@ -1,6 +1,5 @@ import React, { useState } from 'react'; -import TextField from '@mui/material/TextField'; - +import moment from 'moment'; import { Accordion, AccordionSummary, @@ -8,6 +7,7 @@ import { Typography, FormControlLabel, Checkbox, + TextField, } from '@mui/material'; import makeStyles from '@mui/styles/makeStyles'; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; @@ -132,12 +132,18 @@ const DevicePage = () => { }))} label={t('deviceCategory')} /> - {admin && ( - <FormControlLabel - control={<Checkbox checked={item.disabled} onChange={(event) => setItem({ ...item, disabled: event.target.checked })} />} - label={t('sharedDisabled')} - /> - )} + <TextField + label={t('userExpirationTime')} + type="date" + value={(item.expirationTime && moment(item.expirationTime).locale('en').format(moment.HTML5_FMT.DATE)) || '2099-01-01'} + onChange={(e) => setItem({ ...item, expirationTime: moment(e.target.value, moment.HTML5_FMT.DATE).format() })} + disabled={!admin} + /> + <FormControlLabel + control={<Checkbox checked={item.disabled} onChange={(event) => setItem({ ...item, disabled: event.target.checked })} />} + label={t('sharedDisabled')} + disabled={!admin} + /> </AccordionDetails> </Accordion> {item.id && ( diff --git a/modern/src/settings/UserPage.js b/modern/src/settings/UserPage.js index 8bae2e59..392339d0 100644 --- a/modern/src/settings/UserPage.js +++ b/modern/src/settings/UserPage.js @@ -287,7 +287,7 @@ const UserPage = () => { <TextField label={t('userExpirationTime')} type="date" - value={(item.expirationTime && moment(item.expirationTime).format(moment.HTML5_FMT.DATE)) || '2999-01-01'} + value={(item.expirationTime && moment(item.expirationTime).locale('en').format(moment.HTML5_FMT.DATE)) || '2099-01-01'} onChange={(e) => setItem({ ...item, expirationTime: moment(e.target.value, moment.HTML5_FMT.DATE).format() })} disabled={!manager} /> diff --git a/modern/src/settings/UsersPage.js b/modern/src/settings/UsersPage.js index 5b2c1833..dc061adc 100644 --- a/modern/src/settings/UsersPage.js +++ b/modern/src/settings/UsersPage.js @@ -5,7 +5,7 @@ import { import LoginIcon from '@mui/icons-material/Login'; import makeStyles from '@mui/styles/makeStyles'; import { useCatch, useEffectAsync } from '../reactHelper'; -import { formatBoolean } from '../common/util/formatter'; +import { formatBoolean, formatTime } from '../common/util/formatter'; import { useTranslation } from '../common/components/LocalizationProvider'; import PageLayout from '../common/components/PageLayout'; import SettingsMenu from './components/SettingsMenu'; @@ -69,6 +69,7 @@ const UsersPage = () => { <TableCell>{t('userEmail')}</TableCell> <TableCell>{t('userAdmin')}</TableCell> <TableCell>{t('sharedDisabled')}</TableCell> + <TableCell>{t('userExpirationTime')}</TableCell> <TableCell className={classes.columnAction} /> </TableRow> </TableHead> @@ -79,6 +80,7 @@ const UsersPage = () => { <TableCell>{item.email}</TableCell> <TableCell>{formatBoolean(item.administrator, t)}</TableCell> <TableCell>{formatBoolean(item.disabled, t)}</TableCell> + <TableCell>{formatTime(item.expirationTime, 'YYYY-MM-DD')}</TableCell> <TableCell className={classes.columnAction} padding="none"> <CollectionActions itemId={item.id} |