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:
gorkem-bwl committed 2026-03-06 15:19:01 -05:00
1 parent 7c953978ed
commit 172467c0a6
1 file changed
+4 -3
+4 -3
View File
@@ -20,6 +20,7 @@ import { useEffect, useState } from "react";
import { DialogInput } from "@/Components/inputs/Dialog";
import { useSelector } from "react-redux";
import type { RootState } from "@/Types/state";
import { useIsAdmin, useIsSuperAdmin } from "@/Hooks/useIsAdmin";
interface RoleOption {
id: UserRole;
@@ -36,8 +37,8 @@ const EditUserPage = () => {
const navigate = useNavigate();
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
const currentUser = useSelector((state: RootState) => state.auth.user);
const isSuperAdmin = currentUser?.role?.includes("superadmin") ?? false;
const isAdmin = isSuperAdmin || (currentUser?.role?.includes("admin") ?? false);
const isSuperAdmin = useIsSuperAdmin();
const isAdmin = useIsAdmin();
const { data: user, isLoading } = useGet<User>(`/auth/users/${userId}`);
@@ -77,8 +78,8 @@ const EditUserPage = () => {
const handleDeleteUser = async () => {
const result = await deleteFn(`/auth/users/${userId}`);
setShowDeleteDialog(false);
if (result) {
setShowDeleteDialog(false);
navigate("/account", { state: { tab: "team" } });
}
};