Skip to content

Commit

Permalink
feat: restrict admin actions to delete
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh committed Apr 29, 2022
1 parent c7c53fc commit 5cc9c76
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/components/MessageActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { useEditingContext } from '../context/EditingContext';

type Props = {
message: ChatMessage;
isOwn?: boolean;
deleteMessageFunction?: (message: PartialChatMessage) => void;
};

Expand All @@ -33,7 +34,11 @@ const useStyles = makeStyles(() => ({
},
}));

const MessageActions: FC<Props> = ({ message, deleteMessageFunction }) => {
const MessageActions: FC<Props> = ({
message,
deleteMessageFunction,
isOwn = false,
}) => {
const [menuOpen, setMenuOpen] = useState(false);
const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);
const classes = useStyles();
Expand Down Expand Up @@ -80,16 +85,21 @@ const MessageActions: FC<Props> = ({ message, deleteMessageFunction }) => {
horizontal: 'right',
}}
>
<MenuItem
data-cy={editMenuItemCypress}
onClick={handleEditMessage}
dense
>
<ListItemIcon className={classes.menu}>
<Edit color="primary" />
</ListItemIcon>
<ListItemText>{t(CHATBOX.EDIT_BUTTON)}</ListItemText>
</MenuItem>
{
// only show the edit button on own messages
isOwn && (
<MenuItem
data-cy={editMenuItemCypress}
onClick={handleEditMessage}
dense
>
<ListItemIcon className={classes.menu}>
<Edit color="primary" />
</ListItemIcon>
<ListItemText>{t(CHATBOX.EDIT_BUTTON)}</ListItemText>
</MenuItem>
)
}
<MenuItem
data-cy={deleteMenuItemCypress}
onClick={handleDeleteMessage}
Expand Down
1 change: 1 addition & 0 deletions src/components/Messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const Messages: FC<Props> = ({
{(isOwnMessage || isAdmin) && (
<MessageActions
message={message}
isOwn={isOwnMessage}
deleteMessageFunction={deleteMessageFunction}
/>
)}
Expand Down

0 comments on commit 5cc9c76

Please sign in to comment.