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
5 changes: 5 additions & 0 deletions .changeset/hide-create-new-no-perms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Hides the "Create New" button in the navbar when the user has no creation permissions, instead of showing a disabled or empty menu.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const NavBarItemCreateNew = (props: CreateRoomProps) => {

const sections = useCreateNewMenu();

if (sections.length === 0) {
return null;
}

return <GenericMenu icon='plus' sections={sections} title={t('Create_new')} is={SidebarV2Action} {...props} />;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { useAtLeastOnePermission } from '@rocket.chat/ui-contexts';
import { useTranslation } from 'react-i18next';

import { useCreateNewItems } from './useCreateNewItems';

const CREATE_ROOM_PERMISSIONS = ['create-c', 'create-p', 'create-d', 'start-discussion', 'start-discussion-other-user'];

export const useCreateNewMenu = () => {
const { t } = useTranslation();
const showCreate = useAtLeastOnePermission(CREATE_ROOM_PERMISSIONS);

const createRoomItems = useCreateNewItems();

const sections = [{ title: t('Create_new'), items: createRoomItems, permission: showCreate }];
const sections = [{ title: t('Create_new'), items: createRoomItems }];

return sections.filter((section) => section.permission);
return sections.filter((section) => section.items.length > 0);
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type GenericMenuConditionalProps =
sections?: {
title?: ReactNode;
items: GenericMenuItemProps[];
permission?: boolean | '' | 0 | null | undefined;
}[];
items?: never;
}
Expand Down