account tab fix
This commit is contained in:
1 parent
71f3c90472
commit
442fc2ce22
2 files changed
+117
-205
No files matched your search
@@ -1,103 +1,75 @@
|
|||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import Tooltip from "@mui/material/Tooltip";
|
|
||||||
import IconButton from "@mui/material/IconButton";
|
import IconButton from "@mui/material/IconButton";
|
||||||
import { Avatar, Icon } from "@/Components/v2/design-elements";
|
|
||||||
import Menu from "@mui/material/Menu";
|
import Menu from "@mui/material/Menu";
|
||||||
import MenuItem from "@mui/material/MenuItem";
|
import MenuItem from "@mui/material/MenuItem";
|
||||||
import { MoreVertical, LogOut } from "lucide-react";
|
|
||||||
|
|
||||||
import { useTheme } from "@mui/material";
|
import { useTheme } from "@mui/material";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
|
import { MoreVertical, LogOut } from "lucide-react";
|
||||||
|
import { Avatar, Icon } from "@/Components/v2/design-elements";
|
||||||
import { clearAuthState } from "@/Features/Auth/authSlice.js";
|
import { clearAuthState } from "@/Features/Auth/authSlice.js";
|
||||||
import { useDispatch } from "react-redux";
|
|
||||||
import type { RootState } from "@/Types/state.js";
|
import type { RootState } from "@/Types/state.js";
|
||||||
|
|
||||||
const getFilteredAccountMenuItems = (user: any, items: any[]) => {
|
interface AuthFooterProps {
|
||||||
if (!user) return [];
|
|
||||||
|
|
||||||
let filtered = [...items];
|
|
||||||
|
|
||||||
if (user.role?.includes("demo")) {
|
|
||||||
filtered = filtered.filter((item) => item.name !== "Password");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!user.role?.includes("superadmin")) {
|
|
||||||
filtered = filtered.filter((item) => item.name !== "Team");
|
|
||||||
}
|
|
||||||
|
|
||||||
return filtered;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getRoleDisplayText = (user: any, t: Function) => {
|
|
||||||
if (!user?.role) return "";
|
|
||||||
|
|
||||||
if (user.role.includes("superadmin"))
|
|
||||||
return t("components.sidebar.authFooter.roles.superAdmin");
|
|
||||||
if (user.role.includes("admin")) return t("components.sidebar.authFooter.roles.admin");
|
|
||||||
if (user.role.includes("user"))
|
|
||||||
return t("components.sidebar.authFooter.roles.teamMember");
|
|
||||||
if (user.role.includes("demo"))
|
|
||||||
return t("components.sidebar.authFooter.roles.demoUser");
|
|
||||||
|
|
||||||
return user.role;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const AuthFooter = ({
|
|
||||||
collapsed,
|
|
||||||
accountMenuItems,
|
|
||||||
}: {
|
|
||||||
collapsed: boolean;
|
collapsed: boolean;
|
||||||
accountMenuItems: any[];
|
accountMenuItems: Array<{
|
||||||
}) => {
|
name: string;
|
||||||
|
path: string;
|
||||||
|
icon: React.ReactNode;
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const AuthFooter = ({ collapsed, accountMenuItems }: AuthFooterProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const authState = useSelector((state: RootState) => state.auth);
|
const user = useSelector((state: RootState) => state.auth.user);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
||||||
|
|
||||||
const openPopup = (event: React.MouseEvent<HTMLElement>) => {
|
const menuOpen = Boolean(anchorEl);
|
||||||
setAnchorEl(event.currentTarget);
|
const handleMenuOpen = (e: React.MouseEvent<HTMLElement>) =>
|
||||||
|
setAnchorEl(e.currentTarget);
|
||||||
|
const handleMenuClose = () => setAnchorEl(null);
|
||||||
|
|
||||||
|
const handleNavigate = (path: string) => {
|
||||||
|
handleMenuClose();
|
||||||
|
navigate(path);
|
||||||
};
|
};
|
||||||
|
|
||||||
const closePopup = () => {
|
const handleLogout = () => {
|
||||||
setAnchorEl(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
const logout = async () => {
|
|
||||||
dispatch(clearAuthState());
|
dispatch(clearAuthState());
|
||||||
navigate("/login");
|
navigate("/login");
|
||||||
};
|
};
|
||||||
const renderAccountMenuItems = (user: any, items: any[]) => {
|
|
||||||
const filteredItems = getFilteredAccountMenuItems(user, items);
|
|
||||||
|
|
||||||
return filteredItems.map((item) => (
|
const getRoleText = () => {
|
||||||
<MenuItem
|
const role = user?.role ?? "";
|
||||||
key={item.name}
|
if (role.includes("superadmin"))
|
||||||
onClick={() => {
|
return t("components.sidebar.authFooter.roles.superAdmin");
|
||||||
closePopup();
|
if (role.includes("admin")) return t("components.sidebar.authFooter.roles.admin");
|
||||||
navigate(item.path);
|
if (role.includes("user")) return t("components.sidebar.authFooter.roles.teamMember");
|
||||||
}}
|
if (role.includes("demo")) return t("components.sidebar.authFooter.roles.demoUser");
|
||||||
sx={{
|
return role;
|
||||||
gap: theme.spacing(2),
|
|
||||||
borderRadius: theme.shape.borderRadius,
|
|
||||||
pl: theme.spacing(4),
|
|
||||||
"& svg": {
|
|
||||||
stroke: theme.palette.text.secondary,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{item.icon}
|
|
||||||
{item.name}
|
|
||||||
</MenuItem>
|
|
||||||
));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const filteredMenuItems = accountMenuItems.filter((item) => {
|
||||||
|
if (!user) return false;
|
||||||
|
if (item.name === "Password" && user.role?.includes("demo")) return false;
|
||||||
|
if (item.name === "Team" && !user.role?.includes("superadmin")) return false;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
const menuItemSx = {
|
||||||
|
gap: theme.spacing(2),
|
||||||
|
borderRadius: theme.shape.borderRadius,
|
||||||
|
pl: theme.spacing(4),
|
||||||
|
"& svg": { stroke: theme.palette.text.secondary },
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
@@ -105,164 +77,99 @@ export const AuthFooter = ({
|
|||||||
py={theme.spacing(4)}
|
py={theme.spacing(4)}
|
||||||
px={theme.spacing(8)}
|
px={theme.spacing(8)}
|
||||||
gap={theme.spacing(2)}
|
gap={theme.spacing(2)}
|
||||||
borderRadius={theme.shape.borderRadius}
|
|
||||||
boxSizing={"border-box"}
|
|
||||||
>
|
>
|
||||||
<Avatar
|
<Avatar
|
||||||
small={true}
|
small
|
||||||
onClick={(e: any) => {
|
onClick={collapsed ? handleMenuOpen : undefined}
|
||||||
openPopup(e);
|
sx={{ cursor: collapsed ? "pointer" : "default" }}
|
||||||
}}
|
|
||||||
sx={{
|
|
||||||
cursor: collapsed ? "pointer" : "default",
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Stack
|
{!collapsed && (
|
||||||
direction={"row"}
|
|
||||||
alignItems={"center"}
|
|
||||||
gap={theme.spacing(2)}
|
|
||||||
minWidth={0}
|
|
||||||
maxWidth={collapsed ? 0 : "100%"}
|
|
||||||
sx={{
|
|
||||||
opacity: collapsed ? 0 : 1,
|
|
||||||
transition: "opacity 300ms ease, max-width 300ms ease",
|
|
||||||
transitionDelay: collapsed ? "0ms" : "300ms",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Stack
|
<Stack
|
||||||
ml={theme.spacing(2)}
|
direction="row"
|
||||||
sx={{
|
alignItems="center"
|
||||||
maxWidth: "50%",
|
gap={theme.spacing(2)}
|
||||||
overflow: "hidden",
|
minWidth={0}
|
||||||
}}
|
flex={1}
|
||||||
>
|
>
|
||||||
<Typography
|
<Stack
|
||||||
fontWeight={500}
|
minWidth={0}
|
||||||
lineHeight={1}
|
flex={1}
|
||||||
sx={{
|
|
||||||
display: "block",
|
|
||||||
whiteSpace: "nowrap",
|
|
||||||
overflow: "hidden",
|
|
||||||
textOverflow: "ellipsis",
|
|
||||||
color: theme.palette.text.primary,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{authState.user?.firstName} {authState.user?.lastName}
|
<Typography
|
||||||
</Typography>
|
fontWeight={500}
|
||||||
<Typography
|
noWrap
|
||||||
textOverflow="ellipsis"
|
sx={{ color: theme.palette.text.primary }}
|
||||||
overflow="hidden"
|
>
|
||||||
whiteSpace="nowrap"
|
{user?.firstName} {user?.lastName}
|
||||||
sx={{
|
</Typography>
|
||||||
textTransform: "capitalize",
|
<Typography
|
||||||
color: theme.palette.text.secondary,
|
noWrap
|
||||||
}}
|
sx={{ textTransform: "capitalize", color: theme.palette.text.secondary }}
|
||||||
>
|
>
|
||||||
{getRoleDisplayText(authState.user, t)}
|
{getRoleText()}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Tooltip
|
|
||||||
title={t("components.sidebar.authFooter.navControls")}
|
|
||||||
disableInteractive
|
|
||||||
>
|
|
||||||
<IconButton
|
<IconButton
|
||||||
|
onClick={handleMenuOpen}
|
||||||
sx={{
|
sx={{
|
||||||
ml: "50px",
|
|
||||||
"&:focus": { outline: "none" },
|
"&:focus": { outline: "none" },
|
||||||
alignSelf: "center",
|
"& svg": { stroke: theme.palette.text.secondary },
|
||||||
"& svg": {
|
|
||||||
stroke: theme.palette.text.secondary,
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
onClick={(event) => openPopup(event)}
|
|
||||||
>
|
>
|
||||||
<Icon
|
<Icon
|
||||||
icon={MoreVertical}
|
icon={MoreVertical}
|
||||||
size={22}
|
size={22}
|
||||||
/>
|
/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Stack>
|
||||||
</Stack>
|
)}
|
||||||
|
|
||||||
<Menu
|
<Menu
|
||||||
className="sidebar-popup"
|
|
||||||
anchorEl={anchorEl}
|
anchorEl={anchorEl}
|
||||||
open={Boolean(anchorEl)}
|
open={menuOpen}
|
||||||
onClose={closePopup}
|
onClose={handleMenuClose}
|
||||||
disableScrollLock
|
disableScrollLock
|
||||||
anchorOrigin={{
|
anchorOrigin={{ vertical: "top", horizontal: "right" }}
|
||||||
vertical: "top",
|
|
||||||
horizontal: "right",
|
|
||||||
}}
|
|
||||||
slotProps={{
|
slotProps={{
|
||||||
paper: {
|
paper: { sx: { mt: theme.spacing(-4), ml: collapsed ? theme.spacing(2) : 0 } },
|
||||||
sx: {
|
|
||||||
marginTop: theme.spacing(-4),
|
|
||||||
marginLeft: collapsed ? theme.spacing(2) : 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
MenuListProps={{
|
|
||||||
sx: {
|
|
||||||
p: 2,
|
|
||||||
"& li": { m: 0 },
|
|
||||||
"& li:has(.MuiBox-root):hover": {
|
|
||||||
backgroundColor: "transparent",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
sx={{
|
|
||||||
ml: theme.spacing(4),
|
|
||||||
}}
|
}}
|
||||||
|
MenuListProps={{ sx: { p: 2, "& li": { m: 0 } } }}
|
||||||
|
sx={{ ml: theme.spacing(4) }}
|
||||||
>
|
>
|
||||||
{collapsed && (
|
{collapsed && (
|
||||||
<MenuItem sx={{ cursor: "default", minWidth: "50%" }}>
|
<Box
|
||||||
<Box
|
px={2}
|
||||||
mb={theme.spacing(2)}
|
pb={2}
|
||||||
sx={{
|
sx={{ pointerEvents: "none" }}
|
||||||
minWidth: "50%",
|
>
|
||||||
maxWidth: "max-content",
|
<Typography
|
||||||
overflow: "visible",
|
fontWeight={500}
|
||||||
whiteSpace: "nowrap",
|
fontSize={13}
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Typography
|
{user?.firstName} {user?.lastName}
|
||||||
component="span"
|
</Typography>
|
||||||
fontWeight={500}
|
<Typography
|
||||||
fontSize={13}
|
fontSize={12}
|
||||||
sx={{
|
sx={{ textTransform: "capitalize" }}
|
||||||
display: "block",
|
>
|
||||||
whiteSpace: "nowrap",
|
{getRoleText()}
|
||||||
overflow: "visible",
|
</Typography>
|
||||||
textOverflow: "clip",
|
</Box>
|
||||||
}}
|
|
||||||
>
|
|
||||||
{authState.user?.firstName} {authState.user?.lastName}
|
|
||||||
</Typography>
|
|
||||||
<Typography
|
|
||||||
sx={{
|
|
||||||
textTransform: "capitalize",
|
|
||||||
fontSize: 12,
|
|
||||||
whiteSpace: "nowrap",
|
|
||||||
overflow: "visible",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{authState.user?.role}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
</MenuItem>
|
|
||||||
)}
|
)}
|
||||||
{renderAccountMenuItems(authState.user, accountMenuItems)}
|
{filteredMenuItems.map((item) => (
|
||||||
|
<MenuItem
|
||||||
|
key={item.name}
|
||||||
|
onClick={() => handleNavigate(item.path)}
|
||||||
|
sx={menuItemSx}
|
||||||
|
>
|
||||||
|
{item.icon}
|
||||||
|
{item.name}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
<MenuItem
|
<MenuItem
|
||||||
onClick={logout}
|
onClick={handleLogout}
|
||||||
sx={{
|
sx={menuItemSx}
|
||||||
gap: theme.spacing(2),
|
|
||||||
borderRadius: theme.shape.borderRadius,
|
|
||||||
pl: theme.spacing(4),
|
|
||||||
"& svg": {
|
|
||||||
stroke: theme.palette.text.secondary,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Icon
|
<Icon
|
||||||
icon={LogOut}
|
icon={LogOut}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { BasePage, Tabs, Tab } from "@/Components/v2/design-elements";
|
import { BasePage, Tabs, Tab } from "@/Components/v2/design-elements";
|
||||||
import { useState } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { TabProfile } from "./TabProfile";
|
import { TabProfile } from "./TabProfile";
|
||||||
import { TabPassword } from "./TabPassword";
|
import { TabPassword } from "./TabPassword";
|
||||||
@@ -19,6 +19,11 @@ const Account = ({ open = "profile" }: AccountProps) => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [activeTab, setActiveTab] = useState<number>(TAB_MAP[open]);
|
const [activeTab, setActiveTab] = useState<number>(TAB_MAP[open]);
|
||||||
|
|
||||||
|
// Sync activeTab when open prop changes (e.g., navigating from sidebar)
|
||||||
|
useEffect(() => {
|
||||||
|
setActiveTab(TAB_MAP[open]);
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BasePage>
|
<BasePage>
|
||||||
<Tabs
|
<Tabs
|
||||||
|
|||||||
Reference in new issue
Block a user