Skip to content
Merged
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
29 changes: 20 additions & 9 deletions client/views/teams/contextualBar/channels/RoomActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand Down Expand Up @@ -83,7 +91,7 @@ const RoomActions = ({ room, reload }) => {
const AutoJoinAction = async () => {
try {
await updateRoomEndpoint({
roomId: room._id,
roomId: rid,
isDefault: !room.teamDefault,
});
} catch (error) {
Expand All @@ -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 (
Expand All @@ -144,7 +155,7 @@ const RoomActions = ({ room, reload }) => {
</Box>
)
}
options={menuOptions}
options={(canEditTeamChannel || canRemoveTeamChannel || canDeleteTeamChannel) && menuOptions}
/>
);
};
Expand Down
24 changes: 17 additions & 7 deletions client/views/teams/contextualBar/channels/TeamsChannelItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -39,13 +47,15 @@ const TeamsChannelItem = ({ room, onClickView, reload }) => {
)}
</Box>
</Option.Content>
<Option.Menu onClick={onClick}>
{showButton ? (
<RoomActions room={room} reload={reload} />
) : (
<ActionButton ghost tiny icon='kebab' />
)}
</Option.Menu>
{(canRemoveTeamChannel || canEditTeamChannel || canDeleteTeamChannel) && (
<Option.Menu onClick={onClick}>
{showButton ? (
<RoomActions room={room} reload={reload} />
) : (
<ActionButton ghost tiny icon='kebab' />
)}
</Option.Menu>
)}
</Option>
);
};
Expand Down