@samitouri / QOSami-HFS / commits / 53b59f08

admin/logout: quit button

Massimo Melina committed May 4, 2023 at 00:18 UTC 53b59f083b3f8738159d621ac6e595de0ff0dfdb
2 files changed +33 -16
admin/src/LogoutPage.ts
+28 -16
@@ -1,29 +1,41 @@
1 // This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3 -import { createElement as h } from "react"
4 -import { Alert, Box, Button } from '@mui/material'
3 +import { createElement as h, Fragment } from "react"
4 +import { Alert, Box } from '@mui/material'
5 import { apiCall, useApiEx } from './api'
6 import { alertDialog } from "./dialog"
7 import { useSnapState } from './state'
8 +import { Btn } from './misc'
9 +import { Logout, PowerSettingsNew } from '@mui/icons-material'
10
11 export default function LogoutPage() {
12 const { element } = useApiEx('get_config', { only: [] }) // sort of noop, just to get the 'element' part
13 const { username } = useSnapState()
14 if (element)
15 return element
14 - if (!username)
15 - return h(Alert, { severity: 'info' }, "You are not logged in, because authentication is not required on localhost")
16 - return h(Box, { display: 'flex', flexDirection:'column', gap: 2 },
17 - "You are logged in as " + username,
18 - h(Box, {},
19 - h(Button, {
20 - size: 'large',
21 - variant: 'contained',
22 - onClick() {
23 - apiCall('logout').catch(err => // we expect 401
24 - err.code !== 401 && alertDialog(err))
25 - }
26 - }, "Yes, I want to logout")
27 - )
16 + return h(Box, { display: 'flex', flexDirection:'column', alignItems: 'flex-start', gap: 2 },
17 + !username ? h(Alert, { severity: 'info' }, "You are not logged in, because authentication is not required on localhost")
18 + : h(Fragment, {},
19 + "You are logged in as: " + username,
20 + h(Btn, {
21 + icon: Logout,
22 + size: 'large',
23 + variant: 'contained',
24 + onClick: () => apiCall('logout').catch(err => // we expect 401
25 + err.code !== 401 && alertDialog(err))
26 + }, "I want to logout")
27 + ),
28 + h(Btn, {
29 + icon: PowerSettingsNew,
30 + size: 'large',
31 + variant: 'contained',
32 + color: 'warning',
33 + confirm: "After you quit, this interface won't respond anymore",
34 + async onClick() {
35 + await apiCall('quit')
36 + await alertDialog("Good-bye", 'success')
37 + location.reload()
38 + },
39 + }, "Quit HFS")
40 )
41 }
src/adminApis.ts
+5
@@ -72,6 +72,11 @@ export const adminApis: ApiHandlers = {
72 return {}
73 },
74
75 + quit() {
76 + setTimeout(() => process.exit())
77 + return {}
78 + },
79 +
80 async get_status() {
81 return {
82 started: HFS_STARTED,