From c65cb5d6ca40563d0b0e87eaef33c49f20787416 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Tue, 16 Jan 2024 15:36:33 +0200 Subject: [PATCH] List users that have a role in the role menu --- src/pages/admin/Roles.tsx | 48 +++++++++++++++++++++++++++++++++++---- src/pages/admin/Users.tsx | 1 - 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/pages/admin/Roles.tsx b/src/pages/admin/Roles.tsx index e4d0069..f81e1ac 100644 --- a/src/pages/admin/Roles.tsx +++ b/src/pages/admin/Roles.tsx @@ -1,8 +1,8 @@ import React, { useContext, useEffect, useRef, useState } from 'react'; import { Route, Routes, useNavigate, useParams } from 'react-router'; import ErrorBoundary from '../../util/ErrorBoundary'; -import { Permissions as PermissionsStruct, Role as RoleStruct } from '../../@types/ApiStructures'; -import { BasePaginatedCard, DataCard, RefresherState } from '../../components/PageElements'; +import { Permissions as PermissionsStruct, Role as RoleStruct, User } from '../../@types/ApiStructures'; +import { BasePaginatedCard, DataCard, PaginatedCard, RefresherState } from '../../components/PageElements'; import { dateString, del, errorToast, get, patch, post, successToast } from '../../util/Util'; import { BackButton } from '../../components/PageControls'; import { ClickToEdit } from '../../components/InputElements'; @@ -24,11 +24,14 @@ const RolesContext = ({ children }: {children: React.ReactNode}) => type RoleProps = { refreshList: () => void } + const Role = ({ refreshList }: RoleProps) => { const { roles } = useContext(Context); const { roleId } = useParams(); const navigate = useNavigate(); + const [ role, setRole ] = useState(roleId ? roles.get(roleId) ?? null : null); + const [ refresh, setRefresh ] = useState(false); if (!roleId) return
@@ -36,7 +39,6 @@ const Role = ({ refreshList }: RoleProps) =>

Invalid userId

; - const [ role, setRole ] = useState(roles.get(roleId) ?? null); useEffect(() => { @@ -77,7 +79,7 @@ const Role = ({ refreshList }: RoleProps) => successToast('Permissions updated'); }; - const deleteRole = async (e:React.MouseEvent) => + const deleteRole = async (e: React.MouseEvent) => { const button = e.target as HTMLButtonElement; button.disabled = true; @@ -90,6 +92,27 @@ const Role = ({ refreshList }: RoleProps) => navigate('..'); }; + const removeUserFomRole = async (e: React.MouseEvent, user: User) => + { + e.stopPropagation(); + const button = e.target as HTMLButtonElement; + button.disabled = true; + const response = await patch(`/api/users/${user.id}`, { roles: user.roles.filter(role => role.id !== roleId) }); + button.disabled = false; + if (!response.success) + return errorToast(response.message); + setRefresh(val => !val); + }; + + const userFormatter = (user: User) => + { + return navigate(`../../users/${user.id}`)}> + {user.name} + {user.id} + + ; + }; + return
@@ -147,6 +170,23 @@ const Role = ({ refreshList }: RoleProps) =>
+ +
+ + Users + + Name + ID + + + +
; }; diff --git a/src/pages/admin/Users.tsx b/src/pages/admin/Users.tsx index 37fac4b..2ffa311 100644 --- a/src/pages/admin/Users.tsx +++ b/src/pages/admin/Users.tsx @@ -65,7 +65,6 @@ const UserData = ({ user, updateUser }: {user: UserStruct | null, updateUser: (u const disableRef = useRef(null); const disablePermsRef = useRef(null); const noteRef = useRef(null); - const altsRef = useRef(null); const navigate = useNavigate(); useEffect(() =>