fet: show avatar, user name and logout

This commit is contained in:
Rodolfo Ruiz
2025-08-04 21:20:14 -06:00
parent c3a3ea1d84
commit ff2dd6b095
2 changed files with 14 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import SearchIcon from '@mui/icons-material/Search';
import MenuDrawer from './MenuDrawer'; import MenuDrawer from './MenuDrawer';
import MenuIcon from '@mui/icons-material/Menu'; import MenuIcon from '@mui/icons-material/Menu';
import { useAuth } from '../context/AuthContext'; import { useAuth } from '../context/AuthContext';
import { useNavigate } from 'react-router-dom';
export default function AppHeader({ zone = 'public', onSelectMenuItem }) { export default function AppHeader({ zone = 'public', onSelectMenuItem }) {
@@ -21,6 +22,8 @@ export default function AppHeader({ zone = 'public', onSelectMenuItem }) {
const isRestricted = zone === 'restricted'; const isRestricted = zone === 'restricted';
const isPublic = zone === 'public'; const isPublic = zone === 'public';
const navigate = useNavigate();
return ( return (
<AppBar position="static" <AppBar position="static"
sx={{ sx={{
@@ -57,7 +60,7 @@ export default function AppHeader({ zone = 'public', onSelectMenuItem }) {
{/* Login button only visible for public zone */} {/* Login button only visible for public zone */}
{isPublic && !user && ( {isPublic && !user && (
<Box> <Box>
<IconButton color="inherit"> <IconButton color="inherit" onClick={() => navigate('/login')}>
<Typography variant="button" color="#A68A72FF"> <Typography variant="button" color="#A68A72FF">
Login Login
</Typography> </Typography>

View File

@@ -5,6 +5,7 @@ import InventoryIcon from '@mui/icons-material/Inventory';
import LocalShippingIcon from '@mui/icons-material/LocalShipping'; import LocalShippingIcon from '@mui/icons-material/LocalShipping';
import ExitToAppIcon from '@mui/icons-material/ExitToApp'; import ExitToAppIcon from '@mui/icons-material/ExitToApp';
import AdminPanelSettingsIcon from '@mui/icons-material/AdminPanelSettings'; import AdminPanelSettingsIcon from '@mui/icons-material/AdminPanelSettings';
import { useAuth } from '../context/AuthContext';
import { useState } from 'react'; import { useState } from 'react';
@@ -32,6 +33,8 @@ export default function MenuDrawer({ zone = 'public', open, onClose, onSelect })
const isMobile = useMediaQuery('(max-width:900px)'); const isMobile = useMediaQuery('(max-width:900px)');
const items = menuOptions[zone]; const items = menuOptions[zone];
const { logout } = useAuth();
return ( return (
<Drawer anchor="left" open={open} onClose={onClose} slotProps={{ <Drawer anchor="left" open={open} onClose={onClose} slotProps={{
paper: { paper: {
@@ -56,6 +59,12 @@ export default function MenuDrawer({ zone = 'public', open, onClose, onSelect })
<ListItem key={index} onClick={() => { <ListItem key={index} onClick={() => {
onClose(); // Close drawer onClose(); // Close drawer
onSelect?.(text); // Notify parent of selected item onSelect?.(text); // Notify parent of selected item
if (text === 'Logout') {
logout(); // cerrar sesión y redirigir
} else {
onSelect?.(text); // navegar al resto de vistas
}
}}> }}>
<ListItemIcon sx={{ color: '#DFCCBCFF' }}>{icon}</ListItemIcon> <ListItemIcon sx={{ color: '#DFCCBCFF' }}>{icon}</ListItemIcon>