From f9f5ea547e61b6ff527149fa5814851240d2c967 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 22 Jul 2022 17:32:07 -0700 Subject: Add device expiration (fix #85) --- modern/src/common/util/formatter.js | 2 +- modern/src/settings/DevicePage.js | 22 ++++++++++++++-------- modern/src/settings/UserPage.js | 2 +- modern/src/settings/UsersPage.js | 4 +++- 4 files changed, 19 insertions(+), 11 deletions(-) (limited to 'modern/src') 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 && ( - setItem({ ...item, disabled: event.target.checked })} />} - label={t('sharedDisabled')} - /> - )} + setItem({ ...item, expirationTime: moment(e.target.value, moment.HTML5_FMT.DATE).format() })} + disabled={!admin} + /> + setItem({ ...item, disabled: event.target.checked })} />} + label={t('sharedDisabled')} + disabled={!admin} + /> {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 = () => { 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 = () => { {t('userEmail')} {t('userAdmin')} {t('sharedDisabled')} + {t('userExpirationTime')} @@ -79,6 +80,7 @@ const UsersPage = () => { {item.email} {formatBoolean(item.administrator, t)} {formatBoolean(item.disabled, t)} + {formatTime(item.expirationTime, 'YYYY-MM-DD')}