fix: address PR review feedback
- Use useIsAdmin and useIsSuperAdmin hooks instead of manual role checks - Close delete dialog on failure, not just on success
This commit is contained in:
1 parent
7c953978ed
commit
172467c0a6
1 file changed
+4
-3
@@ -20,6 +20,7 @@ import { useEffect, useState } from "react";
|
|||||||
import { DialogInput } from "@/Components/inputs/Dialog";
|
import { DialogInput } from "@/Components/inputs/Dialog";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import type { RootState } from "@/Types/state";
|
import type { RootState } from "@/Types/state";
|
||||||
|
import { useIsAdmin, useIsSuperAdmin } from "@/Hooks/useIsAdmin";
|
||||||
|
|
||||||
interface RoleOption {
|
interface RoleOption {
|
||||||
id: UserRole;
|
id: UserRole;
|
||||||
@@ -36,8 +37,8 @@ const EditUserPage = () => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
|
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
|
||||||
const currentUser = useSelector((state: RootState) => state.auth.user);
|
const currentUser = useSelector((state: RootState) => state.auth.user);
|
||||||
const isSuperAdmin = currentUser?.role?.includes("superadmin") ?? false;
|
const isSuperAdmin = useIsSuperAdmin();
|
||||||
const isAdmin = isSuperAdmin || (currentUser?.role?.includes("admin") ?? false);
|
const isAdmin = useIsAdmin();
|
||||||
|
|
||||||
const { data: user, isLoading } = useGet<User>(`/auth/users/${userId}`);
|
const { data: user, isLoading } = useGet<User>(`/auth/users/${userId}`);
|
||||||
|
|
||||||
@@ -77,8 +78,8 @@ const EditUserPage = () => {
|
|||||||
|
|
||||||
const handleDeleteUser = async () => {
|
const handleDeleteUser = async () => {
|
||||||
const result = await deleteFn(`/auth/users/${userId}`);
|
const result = await deleteFn(`/auth/users/${userId}`);
|
||||||
|
setShowDeleteDialog(false);
|
||||||
if (result) {
|
if (result) {
|
||||||
setShowDeleteDialog(false);
|
|
||||||
navigate("/account", { state: { tab: "team" } });
|
navigate("/account", { state: { tab: "team" } });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user