diff --git a/interface/src/framework/Settings.tsx b/interface/src/framework/Settings.tsx index 6164406ad..c21a0bd15 100644 --- a/interface/src/framework/Settings.tsx +++ b/interface/src/framework/Settings.tsx @@ -1,5 +1,4 @@ import { type FC, useState } from 'react'; -import { toast } from 'react-toastify'; import AccessTimeIcon from '@mui/icons-material/AccessTime'; import CancelIcon from '@mui/icons-material/Cancel'; @@ -7,7 +6,6 @@ import DeviceHubIcon from '@mui/icons-material/DeviceHub'; import ImportExportIcon from '@mui/icons-material/ImportExport'; import LockIcon from '@mui/icons-material/Lock'; import MemoryIcon from '@mui/icons-material/Memory'; -import PowerSettingsNewIcon from '@mui/icons-material/PowerSettingsNew'; import SettingsBackupRestoreIcon from '@mui/icons-material/SettingsBackupRestore'; import SettingsEthernetIcon from '@mui/icons-material/SettingsEthernet'; import SettingsInputAntennaIcon from '@mui/icons-material/SettingsInputAntenna'; @@ -19,6 +17,7 @@ import { DialogActions, DialogContent, DialogTitle, + Divider, List } from '@mui/material'; @@ -26,118 +25,25 @@ import * as SystemApi from 'api/system'; import { dialogStyle } from 'CustomTheme'; import { useRequest } from 'alova'; -import { ButtonRow, SectionContent, useLayoutTitle } from 'components'; +import { SectionContent, useLayoutTitle } from 'components'; import ListMenuItem from 'components/layout/ListMenuItem'; import { useI18nContext } from 'i18n/i18n-react'; -import RestartMonitor from './system/RestartMonitor'; - const Settings: FC = () => { const { LL } = useI18nContext(); useLayoutTitle(LL.SETTINGS(0)); - const [confirmRestart, setConfirmRestart] = useState(false); const [confirmFactoryReset, setConfirmFactoryReset] = useState(false); - const [processing, setProcessing] = useState(false); - const [restarting, setRestarting] = useState(); - - const { send: restartCommand } = useRequest(SystemApi.restart(), { - immediate: false - }); const { send: factoryResetCommand } = useRequest(SystemApi.factoryReset(), { immediate: false }); - const { send: partitionCommand } = useRequest(SystemApi.partition(), { - immediate: false - }); - - const restart = async () => { - setProcessing(true); - await restartCommand() - .then(() => { - setRestarting(true); - }) - .catch((error: Error) => { - toast.error(error.message); - }) - .finally(() => { - setConfirmRestart(false); - setProcessing(false); - }); - }; - const factoryReset = async () => { - setProcessing(true); - await factoryResetCommand() - .then(() => { - setRestarting(true); - }) - .catch((error: Error) => { - toast.error(error.message); - }) - .finally(() => { - setConfirmFactoryReset(false); - setProcessing(false); - }); + await factoryResetCommand(); + setConfirmFactoryReset(false); }; - const partition = async () => { - setProcessing(true); - await partitionCommand() - .then(() => { - setRestarting(true); - }) - .catch((error: Error) => { - toast.error(error.message); - }) - .finally(() => { - setConfirmRestart(false); - setProcessing(false); - }); - }; - - const renderRestartDialog = () => ( - setConfirmRestart(false)} - > - {LL.RESTART()} - {LL.RESTART_CONFIRM()} - - - - - - - ); - const renderFactoryResetDialog = () => ( { startIcon={} variant="outlined" onClick={() => setConfirmFactoryReset(false)} - disabled={processing} color="secondary" > {LL.CANCEL()} @@ -160,7 +65,6 @@ const Settings: FC = () => { startIcon={} variant="outlined" onClick={factoryReset} - disabled={processing} color="error" > {LL.FACTORY_RESET()} @@ -219,6 +123,8 @@ const Settings: FC = () => { to="security" /> + + { /> - {renderRestartDialog()} {renderFactoryResetDialog()} - - - - - - - - - - - + + ); - return ( - {restarting ? : content()} - ); + return {content()}; }; export default Settings; diff --git a/interface/src/framework/system/SystemStatus.tsx b/interface/src/framework/system/SystemStatus.tsx index 1b023cde6..4e9eaec6b 100644 --- a/interface/src/framework/system/SystemStatus.tsx +++ b/interface/src/framework/system/SystemStatus.tsx @@ -8,6 +8,7 @@ import DeviceHubIcon from '@mui/icons-material/DeviceHub'; import DirectionsBusIcon from '@mui/icons-material/DirectionsBus'; import MemoryIcon from '@mui/icons-material/Memory'; import PermScanWifiIcon from '@mui/icons-material/PermScanWifi'; +import PowerSettingsNewIcon from '@mui/icons-material/PowerSettingsNew'; import RefreshIcon from '@mui/icons-material/Refresh'; import SettingsInputAntennaIcon from '@mui/icons-material/SettingsInputAntenna'; import TimerIcon from '@mui/icons-material/Timer'; @@ -39,6 +40,8 @@ import { useI18nContext } from 'i18n/i18n-react'; import { busConnectionStatus } from 'project/types'; import { NTPSyncStatus } from 'types'; +import RestartMonitor from './RestartMonitor'; + const SystemStatus: FC = () => { const { LL } = useI18nContext(); @@ -46,7 +49,18 @@ const SystemStatus: FC = () => { const { me } = useContext(AuthenticatedContext); + const [confirmRestart, setConfirmRestart] = useState(false); const [confirmScan, setConfirmScan] = useState(false); + const [processing, setProcessing] = useState(false); + const [restarting, setRestarting] = useState(); + + const { send: restartCommand } = useRequest(SystemApi.restart(), { + immediate: false + }); + + const { send: partitionCommand } = useRequest(SystemApi.partition(), { + immediate: false + }); const { data: data, @@ -180,6 +194,76 @@ const SystemStatus: FC = () => { ); + const restart = async () => { + setProcessing(true); + await restartCommand() + .then(() => { + setRestarting(true); + }) + .catch((error: Error) => { + toast.error(error.message); + }) + .finally(() => { + setConfirmRestart(false); + setProcessing(false); + }); + }; + + const partition = async () => { + setProcessing(true); + await partitionCommand() + .then(() => { + setRestarting(true); + }) + .catch((error: Error) => { + toast.error(error.message); + }) + .finally(() => { + setConfirmRestart(false); + setProcessing(false); + }); + }; + + const renderRestartDialog = () => ( + setConfirmRestart(false)} + > + {LL.RESTART()} + {LL.RESTART_CONFIRM()} + + + + + + + ); + const content = () => { if (!data) { return ; @@ -198,13 +282,28 @@ const SystemStatus: FC = () => { - + + + + + + + + {me.admin && ( + + )} + + @@ -288,6 +387,7 @@ const SystemStatus: FC = () => { {renderScanDialog()} + {renderRestartDialog()}