|
@@ -0,0 +1,193 @@
|
|
1
|
+import React, { useEffect, useState, useRef } from 'react';
|
|
2
|
+import { styled, createTheme, ThemeProvider } from '@mui/material/styles';
|
|
3
|
+import useAuth from '../Auth/useAuth';
|
|
4
|
+import { Outlet, useNavigate} from "react-router-dom";
|
|
5
|
+
|
|
6
|
+import Typography from '@mui/material/Typography';
|
|
7
|
+import IconButton from '@mui/material/IconButton';
|
|
8
|
+import MenuIcon from '@mui/icons-material/Menu';
|
|
9
|
+import Menu from '@mui/material/Menu';
|
|
10
|
+// import Container from '@mui/material/Container';
|
|
11
|
+import Badge from '@mui/material/Badge';
|
|
12
|
+import Avatar from '@mui/material/Avatar';
|
|
13
|
+import FullscreenIcon from '@mui/icons-material/Fullscreen';
|
|
14
|
+
|
|
15
|
+import MenuItem from '@mui/material/MenuItem';
|
|
16
|
+import MailIcon from '@mui/icons-material/Mail';
|
|
17
|
+import ProfilePicture from '../Images/man.png';
|
|
18
|
+import MuiAppBar from '@mui/material/AppBar';
|
|
19
|
+import NotificationsIcon from '@mui/icons-material/Notifications';
|
|
20
|
+import Toolbar from '@mui/material/Toolbar';
|
|
21
|
+import Box from '@mui/material/Box';
|
|
22
|
+
|
|
23
|
+const drawerWidth = 240;
|
|
24
|
+
|
|
25
|
+const useCheckMobileScreen = () => {
|
|
26
|
+ const [width, setWidth] = useState(window.innerWidth);
|
|
27
|
+ const handleWindowSizeChange = () => {
|
|
28
|
+ let size = window.innerWidth;
|
|
29
|
+ setWidth(size);
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+ useEffect(() => {
|
|
33
|
+ window.addEventListener('resize', handleWindowSizeChange);
|
|
34
|
+ return () => {
|
|
35
|
+ window.removeEventListener('resize', handleWindowSizeChange);
|
|
36
|
+ }
|
|
37
|
+ }, []);
|
|
38
|
+
|
|
39
|
+ let isMobile = width <= 1000
|
|
40
|
+
|
|
41
|
+ return (isMobile);
|
|
42
|
+}
|
|
43
|
+
|
|
44
|
+const AppBar = styled(MuiAppBar, {
|
|
45
|
+ shouldForwardProp: (prop) => prop !== 'open',
|
|
46
|
+})(({ theme, open }) => ({
|
|
47
|
+ transition: theme.transitions.create(['margin', 'width'], {
|
|
48
|
+ easing: theme.transitions.easing.sharp,
|
|
49
|
+ duration: theme.transitions.duration.leavingScreen,
|
|
50
|
+ }),
|
|
51
|
+ ...(open && {
|
|
52
|
+ width: `calc(100% - ${drawerWidth}px)`,
|
|
53
|
+ marginLeft: `${drawerWidth}px`,
|
|
54
|
+ transition: theme.transitions.create(['margin', 'width'], {
|
|
55
|
+ easing: theme.transitions.easing.easeOut,
|
|
56
|
+ duration: theme.transitions.duration.enteringScreen,
|
|
57
|
+ }),
|
|
58
|
+ }),
|
|
59
|
+}));
|
|
60
|
+
|
|
61
|
+export default function AppBarComponent (){
|
|
62
|
+
|
|
63
|
+ const [open, setOpen] = React.useState(true);
|
|
64
|
+ const elRef = useRef();
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+ const auth = useAuth();
|
|
68
|
+ const navigate = useNavigate()
|
|
69
|
+ const [anchorEl, setAnchorEl] = React.useState(null);
|
|
70
|
+
|
|
71
|
+ const [anchorElMovil, setAnchorElMov] = React.useState(null);
|
|
72
|
+
|
|
73
|
+ const toggleDrawer = () => setOpen(!open);
|
|
74
|
+ const open_profile = Boolean(anchorEl);
|
|
75
|
+ const handleClick = (event) => setAnchorEl(event.currentTarget);
|
|
76
|
+ const handleClose = () => setAnchorEl(null)
|
|
77
|
+ const openMov = Boolean(anchorElMovil);
|
|
78
|
+ const handleCloseMov = () => {
|
|
79
|
+ setAnchorElMov(null);
|
|
80
|
+ };
|
|
81
|
+
|
|
82
|
+ const MenuResponsive = () => {
|
|
83
|
+ setAnchorElMov(elRef.current);
|
|
84
|
+ }
|
|
85
|
+
|
|
86
|
+ const CerrarSession = () => {
|
|
87
|
+ console.log('cerrando session')
|
|
88
|
+ // auth.logout();
|
|
89
|
+ // navigate('/')
|
|
90
|
+ }
|
|
91
|
+
|
|
92
|
+ return(
|
|
93
|
+ <AppBar
|
|
94
|
+ style={{ backgroundColor : '#fff', boxShadow : 'None' }}
|
|
95
|
+ position="fixed"
|
|
96
|
+ open={useCheckMobileScreen() ? false : open} >
|
|
97
|
+
|
|
98
|
+ <Toolbar sx={{ borderBottom : "1px solid #ec5e69"}} >
|
|
99
|
+
|
|
100
|
+ <div ref={elRef}>
|
|
101
|
+ <IconButton
|
|
102
|
+ edge="start"
|
|
103
|
+ color="inherit"
|
|
104
|
+ aria-label="open drawer"
|
|
105
|
+ onClick={ useCheckMobileScreen() ? MenuResponsive : toggleDrawer }
|
|
106
|
+ sx={{ marginRight: '36px', ...( !useCheckMobileScreen() && open && { display: 'none' }), }} >
|
|
107
|
+ <MenuIcon style={{
|
|
108
|
+ background: '#ec5e69',
|
|
109
|
+ fontSize: "40",
|
|
110
|
+ color: "#fff"
|
|
111
|
+ }}/>
|
|
112
|
+ </IconButton>
|
|
113
|
+
|
|
114
|
+ <Menu
|
|
115
|
+ id="basic-menu"
|
|
116
|
+ anchorEl={anchorElMovil}
|
|
117
|
+ open={openMov}
|
|
118
|
+ onClose={handleCloseMov}
|
|
119
|
+ MenuListProps={{
|
|
120
|
+ 'aria-labelledby': 'basic-button',
|
|
121
|
+ }}>
|
|
122
|
+ <MenuItem onClick={ () => navigate('/perfil') }>Perfil</MenuItem>
|
|
123
|
+ <MenuItem onClick={handleCloseMov}>My account</MenuItem>
|
|
124
|
+ <MenuItem onClick={handleCloseMov}>Logout</MenuItem>
|
|
125
|
+ </Menu>
|
|
126
|
+
|
|
127
|
+ </div>
|
|
128
|
+
|
|
129
|
+ <Typography component="h1" variant="h6" color="inherit" noWrap sx={{ flexGrow: 1 }} >
|
|
130
|
+ {
|
|
131
|
+ !useCheckMobileScreen() && open ? (
|
|
132
|
+ <React.Fragment>
|
|
133
|
+
|
|
134
|
+ <IconButton onClick={toggleDrawer}>
|
|
135
|
+ <MenuIcon />
|
|
136
|
+ </IconButton>
|
|
137
|
+
|
|
138
|
+ <IconButton onClick={ (event) => event.target.requestFullscreen() }>
|
|
139
|
+ <FullscreenIcon style={{ paddinLeft : 15 }}/>
|
|
140
|
+ </IconButton>
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+ </React.Fragment>
|
|
144
|
+ ) : undefined
|
|
145
|
+ }
|
|
146
|
+ </Typography>
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+ <Box sx={{ display: { xs: 'none', md: 'flex' } }}>
|
|
150
|
+ <IconButton size="large" aria-label="show 4 new mails" color="inherit">
|
|
151
|
+ <Badge badgeContent={4} color="error">
|
|
152
|
+ <MailIcon style={{ color : '#212529' }} />
|
|
153
|
+ </Badge>
|
|
154
|
+ </IconButton>
|
|
155
|
+ <IconButton
|
|
156
|
+ size="large"
|
|
157
|
+ aria-label="show 17 new notifications"
|
|
158
|
+ color="inherit">
|
|
159
|
+ <Badge badgeContent={17} color="error">
|
|
160
|
+ <NotificationsIcon style={{ color : '#212529' }}/>
|
|
161
|
+ </Badge>
|
|
162
|
+ </IconButton>
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+ <IconButton
|
|
166
|
+ size="small"
|
|
167
|
+ edge="end"
|
|
168
|
+ aria-label="account of current user"
|
|
169
|
+ aria-haspopup="true"
|
|
170
|
+ aria-expanded={open_profile ? 'true' : undefined}
|
|
171
|
+ onClick={handleClick}
|
|
172
|
+ color="inherit"
|
|
173
|
+ >
|
|
174
|
+ <Avatar alt="Cindy Baker" src={ProfilePicture} />
|
|
175
|
+
|
|
176
|
+ </IconButton>
|
|
177
|
+ <Menu
|
|
178
|
+ id="basic-menu"
|
|
179
|
+ anchorEl={anchorEl}
|
|
180
|
+ open={open_profile}
|
|
181
|
+ onClose={handleClose}
|
|
182
|
+ MenuListProps={{ 'aria-labelledby': 'basic-button', }}>
|
|
183
|
+ <MenuItem onClick={() => navigate('perfil') }>Profile</MenuItem>
|
|
184
|
+ <MenuItem onClick={() => console.log('opcion 2')}>My account</MenuItem>
|
|
185
|
+ <MenuItem onClick={CerrarSession}>Logout</MenuItem>
|
|
186
|
+ </Menu>
|
|
187
|
+
|
|
188
|
+ </Box>
|
|
189
|
+
|
|
190
|
+ </Toolbar>
|
|
191
|
+ </AppBar>
|
|
192
|
+ )
|
|
193
|
+}
|