1- import { Fragment , type ReactElement , useEffect , useRef , useState } from "react" ;
1+ import { Fragment , type ReactElement , useRef } from "react" ;
22import styles from "./tables.module.css" ;
33
44import { EditIcon , EllipsisVerticalIcon , RectangleEllipsisIcon , TrashIcon } from "lucide-react" ;
@@ -14,7 +14,7 @@ import {
1414 useProjects ,
1515 useUsers ,
1616} from "../../api" ;
17- import { cls } from "../../utils" ;
17+ import { cls , getUsername } from "../../utils" ;
1818import { createToast } from "../toast" ;
1919
2020type DropdownOptions = Record < string , ( ( close : ( ) => void ) => ReactElement ) | null > ;
@@ -74,6 +74,7 @@ const ProjectDropdown = ({ project }: { project: ProjectResponse }) => {
7474
7575export const ProjectsTable = ( ) => {
7676 const { projects, isLoading } = useProjects ( ) ;
77+
7778 const columns : Column < ( typeof projects ) [ number ] > [ ] = [
7879 {
7980 id : "displayName" ,
@@ -164,9 +165,9 @@ const EntityDropdown = ({ entity }: { entity: EntityResponse }) => {
164165} ;
165166
166167export const EntitiesTable = ( ) => {
167- const { entities, isLoading } = useEntities ( ) ;
168+ const { entities, isLoading, authError } = useEntities ( ) ;
168169
169- if ( ! useAdminPerms ( ) ) {
170+ if ( authError ) {
170171 return "You don't have permission to view this page." ;
171172 }
172173
@@ -211,7 +212,7 @@ export const EntitiesTable = () => {
211212} ;
212213
213214const UserDropdown = ( { user } : { user : UserResponse } ) => {
214- const { username } = useMe ( ) ;
215+ const username = getUsername ( ) ;
215216 const options : DropdownOptions = {
216217 edit :
217218 username !== user . username
@@ -256,20 +257,12 @@ const UserDropdown = ({ user }: { user: UserResponse }) => {
256257 return < Dropdown options = { options } /> ;
257258} ;
258259
259- const useAdminPerms = ( ) => {
260- const { role } = useMe ( ) ;
261- const [ isMounted , setIsMounted ] = useState ( false ) ;
262- useEffect ( ( ) => {
263- setIsMounted ( true ) ;
264- } ) ;
265- return ! isMounted || role === "admin" ;
266- } ;
267-
268260export const UsersTable = ( ) => {
269- const { users, isLoading } = useUsers ( ) ;
261+ const { users, isLoading, authError } = useUsers ( ) ;
270262 const rows = users . map ( ( user ) => ( { id : user . username , ...user } ) ) ?? [ ] ;
271263
272- if ( ! useAdminPerms ( ) ) {
264+ // TODO: if the user isn't an admin, show no perms
265+ if ( authError ) {
273266 return "You don't have permission to view this page." ;
274267 }
275268
0 commit comments