diff --git a/client/views/teams/contextualBar/channels/RoomActions.js b/client/views/teams/contextualBar/channels/RoomActions.js index 2a5d14581aec5..7b177d6fcf8c7 100644 --- a/client/views/teams/contextualBar/channels/RoomActions.js +++ b/client/views/teams/contextualBar/channels/RoomActions.js @@ -3,6 +3,7 @@ import { useMutableCallback } from '@rocket.chat/fuselage-hooks'; import React, { useMemo } from 'react'; import { roomTypes } from '../../../../../app/utils/client'; +import { usePermission } from '../../../../contexts/AuthorizationContext'; import { useSetModal } from '../../../../contexts/ModalContext'; import { useToastMessageDispatch } from '../../../../contexts/ToastMessagesContext'; import { useTranslation } from '../../../../contexts/TranslationContext'; @@ -23,8 +24,15 @@ const useReactModal = (Component, props) => { const RoomActions = ({ room, reload }) => { const t = useTranslation(); + const rid = room._id; + const type = room.t; + const dispatchToastMessage = useToastMessageDispatch(); + const canDeleteTeamChannel = usePermission(type === 'c' ? 'delete-c' : 'delete-p', rid); + const canEditTeamChannel = usePermission('edit-team-channel'); + const canRemoveTeamChannel = usePermission('remove-team-channel'); + const updateRoomEndpoint = useEndpointActionExperimental('POST', 'teams.updateRoom'); const removeRoomEndpoint = useEndpointActionExperimental( 'POST', @@ -83,7 +91,7 @@ const RoomActions = ({ room, reload }) => { const AutoJoinAction = async () => { try { await updateRoomEndpoint({ - roomId: room._id, + roomId: rid, isDefault: !room.teamDefault, }); } catch (error) { @@ -94,38 +102,41 @@ const RoomActions = ({ room, reload }) => { }; return [ - { + canEditTeamChannel && { label: { label: t('Team_Auto-join'), - icon: room.t === 'c' ? 'hash' : 'hashtag-lock', + icon: type === 'c' ? 'hash' : 'hashtag-lock', }, action: AutoJoinAction, }, - { + canRemoveTeamChannel && { label: { label: t('Team_Remove_from_team'), icon: 'cross', }, action: RemoveFromTeamAction, }, - { + canDeleteTeamChannel && { label: { label: t('Delete'), icon: 'trash', }, action: DeleteChannelAction, }, - ]; + ].filter(Boolean); }, [ DeleteChannelAction, RemoveFromTeamAction, - room._id, - room.t, + rid, + type, room.teamDefault, t, updateRoomEndpoint, reload, dispatchToastMessage, + canDeleteTeamChannel, + canRemoveTeamChannel, + canEditTeamChannel, ]); return ( @@ -144,7 +155,7 @@ const RoomActions = ({ room, reload }) => { ) } - options={menuOptions} + options={(canEditTeamChannel || canRemoveTeamChannel || canDeleteTeamChannel) && menuOptions} /> ); }; diff --git a/client/views/teams/contextualBar/channels/TeamsChannelItem.js b/client/views/teams/contextualBar/channels/TeamsChannelItem.js index 73ff3cffbbe4f..5107b74f505cb 100644 --- a/client/views/teams/contextualBar/channels/TeamsChannelItem.js +++ b/client/views/teams/contextualBar/channels/TeamsChannelItem.js @@ -4,14 +4,22 @@ import React, { useState } from 'react'; import { roomTypes } from '../../../../../app/utils/client'; import RoomAvatar from '../../../../components/avatar/RoomAvatar'; +import { usePermission } from '../../../../contexts/AuthorizationContext'; import { useTranslation } from '../../../../contexts/TranslationContext'; import { usePreventProgation } from '../../../../hooks/usePreventProgation'; import RoomActions from './RoomActions'; const TeamsChannelItem = ({ room, onClickView, reload }) => { const t = useTranslation(); + const rid = room._id; + const type = room.t; + const [showButton, setShowButton] = useState(); + const canRemoveTeamChannel = usePermission('remove-team-channel'); + const canEditTeamChannel = usePermission('edit-team-channel'); + const canDeleteTeamChannel = usePermission(type === 'c' ? 'delete-c' : 'delete-p', rid); + const isReduceMotionEnabled = usePrefersReducedMotion(); const handleMenuEvent = { [isReduceMotionEnabled ? 'onMouseEnter' : 'onTransitionEnd']: setShowButton, @@ -39,13 +47,15 @@ const TeamsChannelItem = ({ room, onClickView, reload }) => { )} - - {showButton ? ( - - ) : ( - - )} - + {(canRemoveTeamChannel || canEditTeamChannel || canDeleteTeamChannel) && ( + + {showButton ? ( + + ) : ( + + )} + + )} ); };