Skip to content

Commit

Permalink
block menu for non owners
Browse files Browse the repository at this point in the history
  • Loading branch information
mlsmaycon committed Dec 6, 2023
1 parent 32a8e16 commit e38445c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/views/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export const Settings = () => {
const [dangerClicked, setDangerClicked] = useState(false);
const [accountDeleting, setAccountDeleting] = useState(false);

const [isOwner, setIsOwner] = useState(false);


const [filterGroup, setFilterGroup] = useState([]);
const [textToSearch, setTextToSearch] = useState(
getFilterState("groupsManagementPage", "search")
Expand Down Expand Up @@ -141,6 +144,16 @@ export const Settings = () => {
const { confirm } = Modal;

const [form] = Form.useForm();

useEffect(() => {
if (users) {
let currentUser = users.find((user) => user?.is_current);
if (currentUser) {
setIsOwner(currentUser.role === "owner");
}
}
}, [users]);

useEffect(() => {
dispatch(
accountActions.getAccounts.request({
Expand Down Expand Up @@ -665,14 +678,16 @@ export const Settings = () => {
key: React.Key,
icon?: React.ReactNode,
children?: MenuItem[],
type?: "group"
type?: "group",
disabled?: boolean
): MenuItem {
return {
key,
icon,
children,
label,
type,
disabled,
} as MenuItem;
}

Expand All @@ -681,7 +696,7 @@ export const Settings = () => {
"System settings",
"sub2",
<SettingOutlined />,
[getItem("Authentication", "auth"), getItem("Groups", "groups"), getItem("Danger zone", "danger")],
[getItem("Authentication", "auth"), getItem("Groups", "groups"), getItem("Danger zone", "danger", undefined, undefined, undefined, !isOwner)],
"group"
),
];
Expand Down

0 comments on commit e38445c

Please sign in to comment.