continue go stuff
This commit is contained in:
parent
2ebcf0a8c4
commit
39860c84e6
1132
src/actions.tsx
1132
src/actions.tsx
File diff suppressed because it is too large
Load Diff
@ -81,14 +81,14 @@ export const api: AxiosInstance = axios.create({
|
||||
|
||||
export function ApiWrapper(p: { children: ReactNode}) {
|
||||
const {children} = p
|
||||
const token = localStorage.getItem('token')
|
||||
const token = Cookies.get('auth')
|
||||
if (token) {
|
||||
api.defaults.headers.common.Authorization = `Bearer ${token}`;
|
||||
|
||||
}
|
||||
|
||||
const [apiAuthenticated, setApiAuthenticated] = useState(Boolean(token))
|
||||
if (!apiAuthenticated) {
|
||||
localStorage.removeItem('token')
|
||||
Cookies.remove('auth')
|
||||
}
|
||||
const path = useLocation()
|
||||
return (<apiAuthenticatedContext.Provider value={[apiAuthenticated, setApiAuthenticated]}>
|
||||
|
@ -2,7 +2,7 @@ import { TableRow, TableCell, Chip } from "@mui/material"
|
||||
import { useContext, Dispatch, useState, useEffect, Context, createContext } from "react"
|
||||
import { apiAuthenticatedContext, api, ActionInfo, ActionGroup, actionIdentifierContext, DataTable } from "./common"
|
||||
import { User } from './interfaces'
|
||||
import { INVITE_USER_ACTION, Permission } from "./actions";
|
||||
import { INVITE_USER_ACTION, Permission, USERS_ACTIONS } from "./actions";
|
||||
|
||||
const UserActionsContext: Context<ActionInfo[]> = createContext([] as ActionInfo[])
|
||||
function getPermissionStrings(permissions: number){
|
||||
@ -26,7 +26,7 @@ function getPermissionStrings(permissions: number){
|
||||
strings.push("Delete")
|
||||
}
|
||||
if (permissions & Permission.RunCommand){
|
||||
strings.push("RunCommand")
|
||||
strings.push("Run Command")
|
||||
}
|
||||
return strings
|
||||
}
|
||||
@ -48,6 +48,7 @@ function UserItem(p: { user: User }) {
|
||||
export function UsersPage({ }) {
|
||||
const [apiAuthenticated, setApiAuthenticated] = useContext(apiAuthenticatedContext)
|
||||
const [users, setUsers]: [User[], Dispatch<User[]>] = useState([] as User[])
|
||||
console.log({apiAuthenticated: apiAuthenticated, users: users})
|
||||
|
||||
const action: ActionInfo|undefined = INVITE_USER_ACTION
|
||||
|
||||
@ -55,7 +56,9 @@ export function UsersPage({ }) {
|
||||
if (!apiAuthenticated) {
|
||||
return
|
||||
}
|
||||
api.get('/users').then((response) => { setUsers(response.data) }).catch(
|
||||
api.get('/users').then((response) => {
|
||||
setUsers(response.data)
|
||||
}).catch(
|
||||
(error) => {
|
||||
console.log('Failed to get servers: ' + error);
|
||||
if (error.response) {
|
||||
@ -70,7 +73,10 @@ export function UsersPage({ }) {
|
||||
)
|
||||
|
||||
const interval = setInterval(() => {
|
||||
api.get('/users').then((response) => { setUsers(response.data) }).catch(
|
||||
api.get('/users').then((response) => {
|
||||
setUsers(response.data)
|
||||
|
||||
}).catch(
|
||||
(error) => {
|
||||
console.log('Failed to get users: ' + error);
|
||||
if (error.response) {
|
||||
@ -96,7 +102,7 @@ export function UsersPage({ }) {
|
||||
}
|
||||
|
||||
return <DataTable headers={['Username', 'Email', 'Permissions', 'Actions']} actionInfo={action}>
|
||||
<UserActionsContext.Provider value={[]}>
|
||||
<UserActionsContext.Provider value={USERS_ACTIONS}>
|
||||
{userComponents}
|
||||
</UserActionsContext.Provider>
|
||||
</DataTable>
|
||||
|
Loading…
x
Reference in New Issue
Block a user