mirror of
https://github.com/balzack/databag.git
synced 2025-03-13 00:50:03 +00:00
preparing web app for admin config
This commit is contained in:
parent
f8542a275d
commit
a82f67bb69
@ -1,7 +1,7 @@
|
||||
import React, { useContext } from 'react'
|
||||
import { Root } from './root/Root'
|
||||
import { Access } from './access/Access'
|
||||
import { Node } from './node/Node'
|
||||
import { Service } from './service/Service'
|
||||
import { Session } from './session/Session'
|
||||
import { createTheme, MantineProvider, virtualColor } from '@mantine/core'
|
||||
import { ModalsProvider } from '@mantine/modals'
|
||||
@ -62,7 +62,7 @@ const router = createHashRouter([
|
||||
{ path: '/', element: <></> },
|
||||
{ path: 'access', element: <Access /> },
|
||||
{ path: 'session', element: <Session /> },
|
||||
{ path: 'node', element: <Node /> },
|
||||
{ path: 'service', element: <Service /> },
|
||||
],
|
||||
},
|
||||
])
|
||||
|
@ -111,11 +111,11 @@ export function useAppContext() {
|
||||
return await sdk.current.username(username, token, node, secure)
|
||||
},
|
||||
adminLogin: async (token: string, node: string, secure: boolean, code: string) => {
|
||||
const login = await sdk.current.configure(node, secure, token, code)
|
||||
updateState({ node: login })
|
||||
const service = await sdk.current.configure(node, secure, token, code)
|
||||
updateState({ service })
|
||||
},
|
||||
adminLogout: async () => {
|
||||
updateState({ node: null })
|
||||
updateState({ service: null })
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ export function useRoot() {
|
||||
const [state, setState] = useState({
|
||||
pathname: '',
|
||||
session: null,
|
||||
node: null,
|
||||
service: null,
|
||||
})
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
@ -24,22 +24,22 @@ export function useRoot() {
|
||||
}, [location.pathname])
|
||||
|
||||
useEffect(() => {
|
||||
const { pathname, node, session } = app.state || {}
|
||||
const path = pathname === '/session' || pathname === '/node' || pathname === '/access' ? pathname : '/'
|
||||
const { pathname, service, session } = app.state || {}
|
||||
const path = pathname === '/session' || pathname === '/service' || pathname === '/access' ? pathname : '/'
|
||||
if (path === '/session' && !session) {
|
||||
navigate('/')
|
||||
} else if (path === '/node' && !node) {
|
||||
} else if (path === '/service' && !service) {
|
||||
navigate('/')
|
||||
} else if (path === '/' && !session && !node) {
|
||||
} else if (path === '/' && !session && !service) {
|
||||
navigate('/access')
|
||||
} else if (path !== '/node' && node) {
|
||||
navigate('/node')
|
||||
} else if (path !== '/service' && service) {
|
||||
navigate('/service')
|
||||
} else if (path !== '/session' && session) {
|
||||
navigate('/session')
|
||||
} else {
|
||||
navigate('/')
|
||||
}
|
||||
}, [state?.pathname, app.state?.session, app.state?.node])
|
||||
}, [state?.pathname, app.state?.session, app.state?.service])
|
||||
|
||||
const actions = {}
|
||||
|
||||
|
@ -3,7 +3,7 @@ import { Button } from '@mantine/core'
|
||||
import { AppContext } from '../context/AppContext'
|
||||
import { ContextType } from '../context/ContextType'
|
||||
|
||||
export function Node() {
|
||||
export function Service() {
|
||||
const app = useContext(AppContext) as ContextType
|
||||
|
||||
return <Button onClick={app.actions.adminLogout}>Node Logout</Button>
|
Loading…
Reference in New Issue
Block a user