mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 12:49:32 +00:00
improvement: hide some elements base on user profile
This commit is contained in:
@@ -4,7 +4,14 @@ const rules = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
admin: {
|
admin: {
|
||||||
static: ["drawer-admin-items:view", "tickets-manager:showall"],
|
static: [
|
||||||
|
"drawer-admin-items:view",
|
||||||
|
"tickets-manager:showall",
|
||||||
|
"user-modal:editProfile",
|
||||||
|
"user-modal:editQueues",
|
||||||
|
"ticket-options:deleteTicket",
|
||||||
|
"contacts-page:deleteContact",
|
||||||
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -36,4 +36,4 @@ Can.defaultProps = {
|
|||||||
no: () => null,
|
no: () => null,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Can;
|
export { Can };
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useRef, useState } from "react";
|
import React, { useContext, useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
import MenuItem from "@material-ui/core/MenuItem";
|
import MenuItem from "@material-ui/core/MenuItem";
|
||||||
import Menu from "@material-ui/core/Menu";
|
import Menu from "@material-ui/core/Menu";
|
||||||
@@ -8,11 +8,14 @@ import api from "../../services/api";
|
|||||||
import ConfirmationModal from "../ConfirmationModal";
|
import ConfirmationModal from "../ConfirmationModal";
|
||||||
import TransferTicketModal from "../TransferTicketModal";
|
import TransferTicketModal from "../TransferTicketModal";
|
||||||
import toastError from "../../errors/toastError";
|
import toastError from "../../errors/toastError";
|
||||||
|
import { Can } from "../Can";
|
||||||
|
import { AuthContext } from "../../context/Auth/AuthContext";
|
||||||
|
|
||||||
const TicketOptionsMenu = ({ ticket, menuOpen, handleClose, anchorEl }) => {
|
const TicketOptionsMenu = ({ ticket, menuOpen, handleClose, anchorEl }) => {
|
||||||
const [confirmationOpen, setConfirmationOpen] = useState(false);
|
const [confirmationOpen, setConfirmationOpen] = useState(false);
|
||||||
const [transferTicketModalOpen, setTransferTicketModalOpen] = useState(false);
|
const [transferTicketModalOpen, setTransferTicketModalOpen] = useState(false);
|
||||||
const isMounted = useRef(true);
|
const isMounted = useRef(true);
|
||||||
|
const { user } = useContext(AuthContext);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
@@ -62,9 +65,16 @@ const TicketOptionsMenu = ({ ticket, menuOpen, handleClose, anchorEl }) => {
|
|||||||
open={menuOpen}
|
open={menuOpen}
|
||||||
onClose={handleClose}
|
onClose={handleClose}
|
||||||
>
|
>
|
||||||
<MenuItem onClick={handleOpenConfirmationModal}>
|
<Can
|
||||||
{i18n.t("ticketOptionsMenu.delete")}
|
role={user.profile}
|
||||||
</MenuItem>
|
perform="ticket-options:deleteTicket"
|
||||||
|
yes={() => (
|
||||||
|
<MenuItem onClick={handleOpenConfirmationModal}>
|
||||||
|
{i18n.t("ticketOptionsMenu.delete")}
|
||||||
|
</MenuItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
<MenuItem onClick={handleOpenTransferModal}>
|
<MenuItem onClick={handleOpenTransferModal}>
|
||||||
{i18n.t("ticketOptionsMenu.transfer")}
|
{i18n.t("ticketOptionsMenu.transfer")}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import TabPanel from "../TabPanel";
|
|||||||
|
|
||||||
import { i18n } from "../../translate/i18n";
|
import { i18n } from "../../translate/i18n";
|
||||||
import { AuthContext } from "../../context/Auth/AuthContext";
|
import { AuthContext } from "../../context/Auth/AuthContext";
|
||||||
import Can from "../Can";
|
import { Can } from "../Can";
|
||||||
import TicketsQueueSelect from "../TicketsQueueSelect";
|
import TicketsQueueSelect from "../TicketsQueueSelect";
|
||||||
import { Button } from "@material-ui/core";
|
import { Button } from "@material-ui/core";
|
||||||
import { useLocalStorage } from "../../hooks/useLocalStorage";
|
import { useLocalStorage } from "../../hooks/useLocalStorage";
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import { i18n } from "../../translate/i18n";
|
|||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
import toastError from "../../errors/toastError";
|
import toastError from "../../errors/toastError";
|
||||||
import QueueSelect from "../QueueSelect";
|
import QueueSelect from "../QueueSelect";
|
||||||
|
import { Can } from "../Can";
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -182,25 +183,40 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
className={classes.formControl}
|
className={classes.formControl}
|
||||||
margin="dense"
|
margin="dense"
|
||||||
>
|
>
|
||||||
<InputLabel id="profile-selection-input-label">
|
<Can
|
||||||
{i18n.t("userModal.form.profile")}
|
role={user.profile}
|
||||||
</InputLabel>
|
perform="user-modal:editProfile"
|
||||||
<Field
|
yes={() => (
|
||||||
as={Select}
|
<>
|
||||||
label={i18n.t("userModal.form.profile")}
|
<InputLabel id="profile-selection-input-label">
|
||||||
name="profile"
|
{i18n.t("userModal.form.profile")}
|
||||||
labelId="profile-selection-label"
|
</InputLabel>
|
||||||
id="profile-selection"
|
|
||||||
required
|
<Field
|
||||||
>
|
as={Select}
|
||||||
<MenuItem value="admin">Admin</MenuItem>
|
label={i18n.t("userModal.form.profile")}
|
||||||
<MenuItem value="user">User</MenuItem>
|
name="profile"
|
||||||
</Field>
|
labelId="profile-selection-label"
|
||||||
|
id="profile-selection"
|
||||||
|
required
|
||||||
|
>
|
||||||
|
<MenuItem value="admin">Admin</MenuItem>
|
||||||
|
<MenuItem value="user">User</MenuItem>
|
||||||
|
</Field>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
</div>
|
</div>
|
||||||
<QueueSelect
|
<Can
|
||||||
selectedQueueIds={selectedQueueIds}
|
role={user.profile}
|
||||||
onChange={values => setSelectedQueueIds(values)}
|
perform="user-modal:editQueues"
|
||||||
|
yes={() => (
|
||||||
|
<QueueSelect
|
||||||
|
selectedQueueIds={selectedQueueIds}
|
||||||
|
onChange={values => setSelectedQueueIds(values)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
|
|||||||
@@ -5,11 +5,18 @@ import useAuth from "./useAuth";
|
|||||||
const AuthContext = createContext();
|
const AuthContext = createContext();
|
||||||
|
|
||||||
const AuthProvider = ({ children }) => {
|
const AuthProvider = ({ children }) => {
|
||||||
const { loading, user, isAuth, handleLogin, handleLogout } = useAuth();
|
const {
|
||||||
|
loading,
|
||||||
|
user,
|
||||||
|
setUser,
|
||||||
|
isAuth,
|
||||||
|
handleLogin,
|
||||||
|
handleLogout,
|
||||||
|
} = useAuth();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AuthContext.Provider
|
<AuthContext.Provider
|
||||||
value={{ loading, user, isAuth, handleLogin, handleLogout }}
|
value={{ loading, user, setUser, isAuth, handleLogin, handleLogout }}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</AuthContext.Provider>
|
</AuthContext.Provider>
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import AccountTreeOutlinedIcon from "@material-ui/icons/AccountTreeOutlined";
|
|||||||
import { i18n } from "../translate/i18n";
|
import { i18n } from "../translate/i18n";
|
||||||
import { WhatsAppsContext } from "../context/WhatsApp/WhatsAppsContext";
|
import { WhatsAppsContext } from "../context/WhatsApp/WhatsAppsContext";
|
||||||
import { AuthContext } from "../context/Auth/AuthContext";
|
import { AuthContext } from "../context/Auth/AuthContext";
|
||||||
import Can from "../components/Can";
|
import { Can } from "../components/Can";
|
||||||
|
|
||||||
function ListItemLink(props) {
|
function ListItemLink(props) {
|
||||||
const { icon, primary, to, className } = props;
|
const { icon, primary, to, className } = props;
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import MainHeaderButtonsWrapper from "../../components/MainHeaderButtonsWrapper"
|
|||||||
import MainContainer from "../../components/MainContainer";
|
import MainContainer from "../../components/MainContainer";
|
||||||
import toastError from "../../errors/toastError";
|
import toastError from "../../errors/toastError";
|
||||||
import { AuthContext } from "../../context/Auth/AuthContext";
|
import { AuthContext } from "../../context/Auth/AuthContext";
|
||||||
|
import { Can } from "../../components/Can";
|
||||||
|
|
||||||
const reducer = (state, action) => {
|
const reducer = (state, action) => {
|
||||||
if (action.type === "LOAD_CONTACTS") {
|
if (action.type === "LOAD_CONTACTS") {
|
||||||
@@ -318,15 +319,21 @@ const Contacts = () => {
|
|||||||
>
|
>
|
||||||
<EditIcon />
|
<EditIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<IconButton
|
<Can
|
||||||
size="small"
|
role={user.profile}
|
||||||
onClick={e => {
|
perform="contacts-page:deleteContact"
|
||||||
setConfirmOpen(true);
|
yes={() => (
|
||||||
setDeletingContact(contact);
|
<IconButton
|
||||||
}}
|
size="small"
|
||||||
>
|
onClick={e => {
|
||||||
<DeleteOutlineIcon />
|
setConfirmOpen(true);
|
||||||
</IconButton>
|
setDeletingContact(contact);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DeleteOutlineIcon />
|
||||||
|
</IconButton>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
|
|||||||
Reference in New Issue
Block a user