Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add delete button #198

Merged
merged 3 commits into from
Dec 3, 2021
Merged
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
36 changes: 32 additions & 4 deletions client/src/pages/LocationPage/ReviewSection/Review.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
import { IconButton } from '@mui/material';
import type { UserType } from '../../../types/UserType';
import './Review.scss';
import { useState, MouseEvent } from 'react';
import { useSelector } from 'react-redux';
import type { RootState } from '../../../reducers';
import { Fragment } from 'react';
import Menu from '@mui/material/Menu';
import MenuItem from '@mui/material/MenuItem';

export type ReviewType = {
_id: string;
Expand All @@ -15,6 +20,15 @@ export type ReviewType = {
const Review = ({ comm }: { comm: ReviewType }) => {
console.log(comm);
console.log(comm.author);
const currentUser = useSelector((state: RootState) => state.currentUser);

const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const handleClick = (event: MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
return (
<li className="review-container">
<div className="review-header-container">
Expand All @@ -36,9 +50,23 @@ const Review = ({ comm }: { comm: ReviewType }) => {
</div>
</div>
<div className="review-header-rightside">
<IconButton>
<MoreHorizIcon />
</IconButton>
{currentUser && currentUser.account_type === 'Admin' && (
<Fragment>
<button onClick={handleClick}>
<MoreHorizIcon />
</button>
<Menu
anchorEl={anchorEl}
open={anchorEl !== null}
onClose={handleClose}
onClick={handleClose}
transformOrigin={{ horizontal: 'right', vertical: 'top' }}
anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }}
>
<MenuItem>Delete</MenuItem>
</Menu>
</Fragment>
)}
</div>
</div>
<div className="review-text-container">
Expand Down