Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion client/src/Pages/Account/EditUser/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,28 @@ import Button from "@mui/material/Button";
import RoleTable from "../components/RoleTable";

// Utils
import { useParams } from "react-router-dom";
import { Navigate, useParams } from "react-router-dom";
import { useTheme } from "@emotion/react";
import { useTranslation } from "react-i18next";
import { useGetUser, useEditUser } from "../../../Hooks/userHooks";
import { EDITABLE_ROLES, ROLES } from "../../../Utils/roleUtils";
import { useEditUserForm, useValidateEditUserForm } from "./hooks/editUser";
import { useSelector } from "react-redux";

const EditUser = () => {
const { userId } = useParams();
const theme = useTheme();
const { t } = useTranslation();
const currentUser = useSelector((state) => state.auth.user);

if (currentUser?._id && userId === currentUser._id) {
return (
<Navigate
to="/account/profile"
replace
/>
);
}
const BREADCRUMBS = [
Copy link
Collaborator

@ajhollid ajhollid Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditionally returning a redirect before calling hooks is a violation of the rules of hooks.

This redirect should occur only after hooks have been called. Please use our include .eslintrc config to lint your code before submitting PRs, these types of errors should be caught by the linter.

{ name: t("menu.team"), path: "/account/team" },
{ name: t("editUserPage.title"), path: "" },
Expand All @@ -37,6 +48,15 @@ const EditUser = () => {
] = useEditUserForm(user);
const [errors, validateForm, validateField] = useValidateEditUserForm();

if (currentUser?._id && userId === currentUser._id) {
return (
<Navigate
to="/account/profile"
replace
/>
);
}

const onChange = (e) => {
const name = e.target.name;
const value = e.target.value;
Expand Down
4 changes: 2 additions & 2 deletions client/src/Pages/Account/components/TeamPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ const TeamPanel = () => {
};
let team = members;
if (filter !== "all")
team = members.filter((member) => {
team = members?.filter((member) => {
if (filter === "admin") {
return member.role.includes("admin") || member.role.includes("superadmin");
}
return member.role.includes(filter);
});

team = team.map((member) => ({
team = team?.map((member) => ({
...member,
id: member._id,
role: member.role.map((role) => ROLE_MAP[role]).join(","),
Expand Down