Skip to content

Commit

Permalink
Disable My Project page context menu options for non-owner of project (
Browse files Browse the repository at this point in the history
  • Loading branch information
entrotech authored Nov 20, 2023
1 parent 73abdaa commit f6618d0
Showing 1 changed file with 66 additions and 48 deletions.
114 changes: 66 additions & 48 deletions client/src/components/Projects/ProjectContextMenu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from "react";
import React, { useContext } from "react";
import UserContext from "../../contexts/UserContext";
import { useState } from "react";
import PropTypes from "prop-types";

import { createUseStyles } from "react-jss";
Expand Down Expand Up @@ -39,11 +41,20 @@ const ProjectContextMenu = ({
handlePrintPdf,
handleHide
}) => {
const userContext = useContext(UserContext);
const account = userContext.account;
const [projectVisibility, SetProjectVisibility] = useState(
project.dateHidden
);
const toggleProjectVisibility = () => {
SetProjectVisibility(!projectVisibility);
};

const classes = useStyles();

return (
<ul className={classes.list}>
{project.dateSnapshotted ? null : (
{project.dateSnapshotted || project.loginId !== account.id ? null : (
<li
className={classes.listItem}
onClick={() => handleSnapshotModalOpen(project)}
Expand Down Expand Up @@ -87,52 +98,59 @@ const ProjectContextMenu = ({
/>
Duplicate
</li>
<li onClick={() => handleHide(project)} className={classes.listItem}>
{project.dateHidden ? (
<>
<FontAwesomeIcon
icon={faEyeSlash}
className={classes.listItemIcon}
alt={`Unhide Project #${project.id} as CSV Icon`}
/>
Unhide
</>
) : (
<>
<FontAwesomeIcon
icon={faEye}
className={classes.listItemIcon}
alt={`Hide Project #${project.id} as CSV Icon`}
/>
Hide from View
</>
)}
</li>
<li
onClick={() => handleDeleteModalOpen(project)}
className={classes.listItem}
style={{ borderTop: "1px solid black", color: "red" }}
>
{project.dateTrashed ? (
<>
<FontAwesomeIcon
icon={faTrash}
className={classes.listItemIcon}
alt={`Remove Project #${project.id} from Trash Icon`}
/>
Remove from Trash
</>
) : (
<>
<FontAwesomeIcon
icon={faTrash}
className={classes.listItemIcon}
alt={`Move Project #${project.id} to Trash Icon`}
/>
Move to Trash
</>
)}
</li>
{project.loginId !== account.id ? null : (
<li
onClick={() => toggleProjectVisibility(project)}
className={classes.listItem}
>
{projectVisibility ? (
<>
<FontAwesomeIcon
icon={faEyeSlash}
className={classes.listItemIcon}
alt={`Unhide Project #${project.id} as CSV Icon`}
/>
Unhide
</>
) : (
<>
<FontAwesomeIcon
icon={faEye}
className={classes.listItemIcon}
alt={`Hide Project #${project.id} as CSV Icon`}
/>
Hide from View
</>
)}
</li>
)}
{project.loginId !== account.id ? null : (
<li
onClick={() => handleDeleteModalOpen(project)}
className={classes.listItem}
style={{ borderTop: "1px solid black", color: "red" }}
>
{project.dateTrashed ? (
<>
<FontAwesomeIcon
icon={faTrash}
className={classes.listItemIcon}
alt={`Remove Project #${project.id} from Trash Icon`}
/>
Remove from Trash
</>
) : (
<>
<FontAwesomeIcon
icon={faTrash}
className={classes.listItemIcon}
alt={`Move Project #${project.id} to Trash Icon`}
/>
Move to Trash
</>
)}
</li>
)}
</ul>
);
};
Expand Down

0 comments on commit f6618d0

Please sign in to comment.