added view as button to user menu
This commit is contained in:
parent
cf3eefccdd
commit
d19d37410e
2 changed files with 60 additions and 10 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { Avatar, Box, Button, IconButton, ListItemIcon, ListItemText, Menu, MenuItem, PaletteColor, Theme, Tooltip, useTheme } from "@mui/material";
|
||||
import { Avatar, Box, Button, Checkbox, IconButton, ListItemIcon, ListItemText, Menu, MenuItem, PaletteColor, Theme, Tooltip, useTheme } from "@mui/material";
|
||||
import { useGlobalState } from "../providers/StateContainer";
|
||||
import { getSecondaryColour, getSignatureAccentColour } from "../services/whiteLabel";
|
||||
import { makeStyles } from "@mui/styles";
|
||||
|
|
@ -14,6 +14,7 @@ import { purple } from "@mui/material/colors";
|
|||
import { useNavigate } from "react-router-dom";
|
||||
import TeamDialog from "teams/TeamDialog";
|
||||
import AccessObject from "./AccessObject";
|
||||
import { useSnackbar, useUserAPI } from "hooks";
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) => ({
|
||||
accessIcon: {
|
||||
|
|
@ -80,19 +81,20 @@ interface Props {
|
|||
export default function UserMenu(props: Props) {
|
||||
|
||||
const { toggleTheme } = props;
|
||||
const [{ user, team, as }] = useGlobalState();
|
||||
const [{ user, team, as }, dispatch] = useGlobalState();
|
||||
const { loginWithRedirect } = useAuth0();
|
||||
const classes = useStyles();
|
||||
const theme = useTheme();
|
||||
|
||||
const userAPI = useUserAPI()
|
||||
const snackbar = useSnackbar()
|
||||
|
||||
const name = user.name();
|
||||
const picture = user.settings.avatar;
|
||||
const [lockIsHovered, setLockIsHovered] = useState<boolean>(false);
|
||||
const [userMenuIsOpen, setUserMenuIsOpen] = useState(false);
|
||||
const [anchorEl, setAnchorEl] = useState<any>(null);
|
||||
const [userSettingsIsOpen, setUserSettingsIsOpen] = useState<boolean>(false);
|
||||
// const hasAdmin = user.hasFeature ? user.hasFeature("admin") : false;
|
||||
// const allowedToCopyToken = user.allowedTo("copy-token");
|
||||
const hasTeams = user.hasFeature ? user.hasFeature("teams") : false;
|
||||
const [teamDialogIsOpen, setTeamDialogIsOpen] = useState<boolean>(false);
|
||||
const [accessDialogOpen, setAccessDialogOpen] = useState<boolean>(false);
|
||||
|
|
@ -242,6 +244,36 @@ export default function UserMenu(props: Props) {
|
|||
<ListItemText primary="Select Team" />
|
||||
</MenuItem>
|
||||
)}
|
||||
{hasTeams && (
|
||||
<MenuItem
|
||||
onClick={() => {
|
||||
if (as.length > 1) {
|
||||
user.settings.useTeam = false;
|
||||
dispatch({ key: "as", value: "" });
|
||||
userAPI.updateUser(user.id(), user.protobuf()).then(_resp => {
|
||||
snackbar.info("Will no longer view as team by default");
|
||||
});
|
||||
} else {
|
||||
user.settings.useTeam = true;
|
||||
dispatch({ key: "as", value: team.key() });
|
||||
userAPI.updateUser(user.id(), user.protobuf()).then(_resp => {
|
||||
snackbar.info("Will now view as " + team.name() + " by default");
|
||||
});
|
||||
}
|
||||
}}
|
||||
disabled={user.settings.defaultTeam.length < 1}
|
||||
aria-label="Open Team Menu"
|
||||
dense>
|
||||
<ListItemIcon>
|
||||
<Checkbox
|
||||
disabled={user.settings.defaultTeam.length < 1}
|
||||
checked={as.length > 1}
|
||||
style={{ margin: 0, padding: 0 }}
|
||||
/>
|
||||
</ListItemIcon>
|
||||
<ListItemText primary="View Site as Team" />
|
||||
</MenuItem>
|
||||
)}
|
||||
{hasAdmin && (
|
||||
<Tooltip title="Access Object">
|
||||
<MenuItem onClick={() => openAccessObject()} aria-label="Access Object" dense>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue