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