fix: merge conflicts
This commit is contained in:
100
src/components/layout/Header.tsx
Normal file
100
src/components/layout/Header.tsx
Normal file
@@ -0,0 +1,100 @@
|
||||
import {
|
||||
Box,
|
||||
IconButton,
|
||||
ListItemIcon,
|
||||
ListItemText,
|
||||
Menu,
|
||||
MenuItem,
|
||||
Typography,
|
||||
} from '@mui/material';
|
||||
import { Icon } from '@rkheftan/harmony-ui';
|
||||
import { Logout, More } from 'iconsax-react';
|
||||
import type { UserInfo } from '@/contexts/AuthContext';
|
||||
import { LTRTypography } from '../common/LTRTypography';
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
|
||||
interface HeaderProps {
|
||||
user: UserInfo;
|
||||
}
|
||||
|
||||
export const Header: React.FC<HeaderProps> = ({ user }) => {
|
||||
const { t, i18n } = useTranslation('sideNav');
|
||||
|
||||
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
||||
const open = Boolean(anchorEl);
|
||||
|
||||
const { logout } = useAuth();
|
||||
|
||||
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
|
||||
event.stopPropagation();
|
||||
setAnchorEl(event.currentTarget);
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setAnchorEl(null);
|
||||
};
|
||||
|
||||
const handleLogout = () => {
|
||||
handleClose();
|
||||
logout();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Box
|
||||
sx={{
|
||||
p: 2,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
height: (t) => t.spacing(10.5),
|
||||
}}
|
||||
>
|
||||
<Box>
|
||||
<Typography variant="body1" color="textSecondary">
|
||||
{user.fullName}
|
||||
</Typography>
|
||||
{/* TODO: add ternary text color to palette */}
|
||||
<LTRTypography variant="body2" color="#757575">
|
||||
{user.phoneNumber ?? user.email}
|
||||
</LTRTypography>
|
||||
</Box>
|
||||
|
||||
<IconButton onClick={handleClick} color="primary">
|
||||
<Icon Component={More} />
|
||||
</IconButton>
|
||||
</Box>
|
||||
<Menu
|
||||
id="account-menu"
|
||||
anchorEl={anchorEl}
|
||||
open={open}
|
||||
onClose={handleClose}
|
||||
anchorOrigin={{
|
||||
vertical: 'bottom',
|
||||
horizontal: 'center',
|
||||
}}
|
||||
transformOrigin={{
|
||||
vertical: 'top',
|
||||
horizontal: i18n.dir() === 'rtl' ? 'right' : 'left',
|
||||
}}
|
||||
>
|
||||
<MenuItem
|
||||
sx={{
|
||||
color: 'error.main',
|
||||
'& .MuiListItemIcon-root': {
|
||||
color: 'error.main',
|
||||
},
|
||||
}}
|
||||
onClick={handleLogout}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<Icon Component={Logout} />
|
||||
</ListItemIcon>
|
||||
<ListItemText>{t('header.logout')}</ListItemText>
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
</>
|
||||
);
|
||||
};
|
||||
75
src/components/layout/Layout.tsx
Normal file
75
src/components/layout/Layout.tsx
Normal file
@@ -0,0 +1,75 @@
|
||||
import { SideNav } from '@rkheftan/harmony-ui';
|
||||
import { buildNavItems } from './buildNavItems';
|
||||
import { appRoutes } from '@/routes/config';
|
||||
import { Outlet, useLocation } from 'react-router-dom';
|
||||
import { Box, useMediaQuery, useTheme } from '@mui/material';
|
||||
import { Header } from './Header';
|
||||
import { useState } from 'react';
|
||||
import { Toolbar } from './Toolbar';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
|
||||
export const Layout = () => {
|
||||
const navItemConfigs = buildNavItems(appRoutes);
|
||||
const location = useLocation();
|
||||
const theme = useTheme();
|
||||
const isMobile = useMediaQuery(theme.breakpoints.down('md'));
|
||||
const [sideNavOpen, setSideNavOpen] = useState(false);
|
||||
const { userInfo } = useAuth();
|
||||
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
height: '100vh',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
// TODO: Check for better approach
|
||||
width: isMobile ? '100%' : 1070,
|
||||
height: isMobile ? '100vh' : '80%',
|
||||
display: 'flex',
|
||||
flexDirection: 'row-reverse',
|
||||
borderRadius: isMobile ? 0 : 4,
|
||||
backgroundColor: 'background.paper',
|
||||
overflow: 'hidden',
|
||||
}}
|
||||
>
|
||||
<Box sx={{ flex: 1 }}>
|
||||
<Toolbar
|
||||
isMobile={isMobile}
|
||||
sideNavOpen={sideNavOpen}
|
||||
setSideNavOpen={setSideNavOpen}
|
||||
user={userInfo}
|
||||
/>
|
||||
<Box
|
||||
sx={{
|
||||
flex: 1,
|
||||
overflowY: 'auto',
|
||||
p: 2,
|
||||
maxHeight: 'calc(100% - 85px)',
|
||||
overflowInline: 'auto',
|
||||
}}
|
||||
>
|
||||
<Outlet />
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<SideNav
|
||||
open={sideNavOpen}
|
||||
onClose={() => setSideNavOpen(false)}
|
||||
header={isMobile ? undefined : <Header user={userInfo} />}
|
||||
footer={isMobile ? <Header user={userInfo} /> : undefined}
|
||||
navConfig={navItemConfigs}
|
||||
activePath={location.pathname + location.hash}
|
||||
selectedVariant="textOnly"
|
||||
positioning="absolute"
|
||||
sideNavVariant={isMobile ? 'temporary' : 'full'}
|
||||
top={8.125}
|
||||
/>
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
96
src/components/layout/ProductsMenu.tsx
Normal file
96
src/components/layout/ProductsMenu.tsx
Normal file
@@ -0,0 +1,96 @@
|
||||
import { Menu, Stack, Typography, Box, Button } from '@mui/material';
|
||||
import { blue } from '@mui/material/colors';
|
||||
import { Icon } from '@rkheftan/harmony-ui';
|
||||
import { ArrowLeft, ArrowRight } from 'iconsax-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { productsData } from '@/data/products';
|
||||
|
||||
// --- Props Interface ---
|
||||
interface ProductsMenuProps {
|
||||
anchorEl: Element | null;
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export default function ProductsMenu({
|
||||
anchorEl,
|
||||
open,
|
||||
onClose,
|
||||
}: ProductsMenuProps) {
|
||||
const { t, i18n } = useTranslation('setting');
|
||||
|
||||
return (
|
||||
<Menu
|
||||
id="products-menu"
|
||||
anchorEl={anchorEl}
|
||||
open={open}
|
||||
onClose={onClose}
|
||||
anchorOrigin={{
|
||||
vertical: 'bottom',
|
||||
horizontal: 'center',
|
||||
}}
|
||||
transformOrigin={{
|
||||
vertical: 'top',
|
||||
horizontal: i18n.dir() === 'rtl' ? 'left' : 'right',
|
||||
}}
|
||||
sx={{
|
||||
'& .MuiMenu-list': {
|
||||
py: 0,
|
||||
},
|
||||
'& .MuiPaper-root': {
|
||||
borderRadius: 2,
|
||||
width: 376,
|
||||
},
|
||||
}}
|
||||
>
|
||||
{/* 1. Header Link */}
|
||||
<Box sx={{ px: 2, py: 1, bgcolor: blue[50] }}>
|
||||
<Typography variant="body2" color="primary.main">
|
||||
{t('products.menu.title')}
|
||||
</Typography>
|
||||
</Box>
|
||||
|
||||
<Box sx={{ px: 2, py: 1 }}>
|
||||
{/* 2. Map through products to create MenuItems */}
|
||||
{productsData.map((product) => (
|
||||
<Stack
|
||||
key={product.id}
|
||||
direction="row-reverse"
|
||||
spacing={2}
|
||||
alignItems="center"
|
||||
width="100%"
|
||||
>
|
||||
{/* Text Content */}
|
||||
<Stack minWidth={0} direction="column" spacing={0.5} flexGrow={1}>
|
||||
<Typography variant="h6">{t(product.titleKey)}</Typography>
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
{t(product.descriptionKey)}
|
||||
</Typography>
|
||||
<Button
|
||||
type="link"
|
||||
href={product.demoLink}
|
||||
variant="text"
|
||||
color="club"
|
||||
endIcon={
|
||||
<Icon
|
||||
Component={i18n.dir() === 'ltr' ? ArrowRight : ArrowLeft}
|
||||
/>
|
||||
}
|
||||
sx={{
|
||||
alignSelf: 'flex-start',
|
||||
width: 'unset',
|
||||
}}
|
||||
>
|
||||
{t('products.menu.getDemo')}
|
||||
</Button>
|
||||
</Stack>
|
||||
|
||||
<Box sx={{ width: 69 }}>
|
||||
<product.LogoComponent />
|
||||
</Box>
|
||||
</Stack>
|
||||
))}
|
||||
</Box>
|
||||
</Menu>
|
||||
);
|
||||
}
|
||||
84
src/components/layout/Toolbar.tsx
Normal file
84
src/components/layout/Toolbar.tsx
Normal file
@@ -0,0 +1,84 @@
|
||||
import { Avatar, Box, IconButton, Toolbar as MuiToolbar } from '@mui/material';
|
||||
import { Icon } from '@rkheftan/harmony-ui';
|
||||
import { HambergerMenu, Menu } from 'iconsax-react';
|
||||
import { useState, type Dispatch, type SetStateAction } from 'react';
|
||||
import type { UserInfo } from '@/contexts/AuthContext';
|
||||
import Logo from '../Logo';
|
||||
import ProductsMenu from './ProductsMenu';
|
||||
|
||||
interface ToolbarProps {
|
||||
sideNavOpen: boolean;
|
||||
setSideNavOpen: Dispatch<SetStateAction<boolean>>;
|
||||
isMobile: boolean;
|
||||
user: UserInfo;
|
||||
}
|
||||
|
||||
export const Toolbar: React.FC<ToolbarProps> = ({
|
||||
sideNavOpen,
|
||||
setSideNavOpen,
|
||||
isMobile,
|
||||
user,
|
||||
}) => {
|
||||
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
||||
const open = Boolean(anchorEl);
|
||||
|
||||
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
|
||||
event.stopPropagation();
|
||||
setAnchorEl(event.currentTarget);
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setAnchorEl(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<MuiToolbar
|
||||
sx={{
|
||||
height: (t) => t.spacing(isMobile ? 8 : 10.5),
|
||||
bgcolor: 'background.paper',
|
||||
px: isMobile ? 3 : 2,
|
||||
borderBottom: `1px solid var(--mui-palette-divider)`,
|
||||
boxSizing: 'content-box',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{ display: 'flex', height: '100%', alignItems: 'center', gap: 2 }}
|
||||
>
|
||||
{isMobile && (
|
||||
<IconButton
|
||||
sx={{
|
||||
backgroundColor: sideNavOpen ? 'primary.light' : undefined,
|
||||
color: sideNavOpen ? 'primary.main' : undefined,
|
||||
'&:hover': {
|
||||
backgroundColor: sideNavOpen ? 'primary.light' : undefined,
|
||||
},
|
||||
}}
|
||||
onClick={() => setSideNavOpen(!sideNavOpen)}
|
||||
>
|
||||
<Icon Component={HambergerMenu} />
|
||||
</IconButton>
|
||||
)}
|
||||
<Logo />
|
||||
</Box>
|
||||
<Box
|
||||
sx={{ display: 'flex', height: '100%', alignItems: 'center', gap: 1 }}
|
||||
>
|
||||
{isMobile && (
|
||||
<Avatar
|
||||
sx={{ width: 32, height: 32, fontSize: '14px' }}
|
||||
src={user.picture}
|
||||
>
|
||||
{user.firstName.charAt(0) + ' ' + user.lastName.charAt(0)}
|
||||
</Avatar>
|
||||
)}
|
||||
<IconButton color="primary" onClick={handleClick}>
|
||||
<Icon Component={Menu} variant="Bold" />
|
||||
</IconButton>
|
||||
</Box>
|
||||
<ProductsMenu anchorEl={anchorEl} onClose={handleClose} open={open} />
|
||||
</MuiToolbar>
|
||||
);
|
||||
};
|
||||
35
src/components/layout/buildNavItems.tsx
Normal file
35
src/components/layout/buildNavItems.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
// src/components/SideNav.tsx (Conceptual Example)
|
||||
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { type RouteConfig } from '@/routes/config';
|
||||
import { Icon, type NavItemConfig } from '@rkheftan/harmony-ui';
|
||||
import type { Icon as Iconsax } from 'iconsax-react';
|
||||
|
||||
const getIcon = (icon?: Iconsax) => (isSelected: boolean) =>
|
||||
icon ? (
|
||||
<Icon Component={icon} variant={isSelected ? 'Bold' : 'Broken'} />
|
||||
) : undefined;
|
||||
|
||||
// TODO: make this a hook
|
||||
export function buildNavItems(routes: RouteConfig[]): NavItemConfig[] {
|
||||
const { t } = useTranslation('sideNav');
|
||||
|
||||
return routes.flatMap((route) => {
|
||||
// Check if route itself does not have a navItem but its child has
|
||||
if (!route.navConfig && route.children) {
|
||||
return buildNavItems(route.children);
|
||||
}
|
||||
|
||||
// Check if route.navConfig is defined before destructuring
|
||||
if (!route.navConfig) {
|
||||
return []; // Return an empty array to be flattened
|
||||
}
|
||||
const { title, icon } = route.navConfig;
|
||||
return {
|
||||
text: t(title),
|
||||
getIcon: getIcon(icon),
|
||||
path: route.path,
|
||||
children: route.children ? buildNavItems(route.children) : undefined,
|
||||
};
|
||||
});
|
||||
}
|
||||
0
src/components/layout/type.ts
Normal file
0
src/components/layout/type.ts
Normal file
Reference in New Issue
Block a user