Browse Source

user options components

amenpunk 2 years ago
parent
commit
12b1806c3e
4 changed files with 180 additions and 75 deletions
  1. 57 59
      src/Components/Dashboard.js
  2. 69 0
      src/Components/Navigation/UserOptions.jsx
  3. 53 15
      src/Components/User.jsx
  4. 1 1
      src/Utils/theme.js

+ 57 - 59
src/Components/Dashboard.js

@@ -1,41 +1,82 @@
1 1
 import React from 'react';
2
-import { ThemeProvider } from '@mui/material/styles';
2
+import { ThemeProvider, styled } from '@mui/material/styles';
3 3
 
4 4
 import {
5
-    Menu, MenuItem, Container, Avatar, Badge, IconButton, Divider,
5
+    Container, IconButton, Divider,
6 6
     Typography, List, Toolbar, Box, CssBaseline, useMediaQuery as Size,
7 7
 } from '@mui/material'
8 8
 
9 9
 import {
10
-    Mail as MailIcon, Notifications as NotificationsIcon, Fullscreen as FullscreenIcon,
10
+    Fullscreen as FullscreenIcon,
11 11
     Menu as MenuIcon,
12 12
 } from '@mui/icons-material'
13 13
 
14
-import useAuth from '../Auth/useAuth';
15 14
 import Logo from '../Images/logo.png';
16
-import ProfilePicture from '../Images/man.png';
17 15
 
18
-import { Outlet, useNavigate } from "react-router-dom";
16
+import { Outlet } from "react-router-dom";
19 17
 import { MenuMovil } from '../Components/Navigation/MenuMovil';
20 18
 import Footer from "../Components/Footer";
21 19
 
22
-import { mdTheme } from '../Utils/theme'
23
-import { Drawer, AppBar } from "../Components/Navigation/AppBar"
20
+import { psicotheme } from '../Utils/theme'
21
+import { Drawer as MuiDrawer, AppBar as MuiAppBar } from "../Components/Navigation/AppBar"
24 22
 import { MainListItems, SecondaryListItems } from '../Components/Navigation/listItems';
23
+import { UserOptions } from '../Components/Navigation/UserOptions'
24
+
25
+const drawerWidth = 240;
26
+
27
+const AppBar = styled(MuiAppBar, {
28
+    shouldForwardProp: (prop) => prop !== 'open',
29
+})(({ theme, open }) => ({
30
+    zIndex: theme.zIndex.drawer + 1,
31
+    transition: theme.transitions.create(['width', 'margin'], {
32
+        easing: theme.transitions.easing.sharp,
33
+        duration: theme.transitions.duration.leavingScreen,
34
+    }),
35
+    ...(open && {
36
+        marginLeft: drawerWidth,
37
+        width: `calc(100% - ${drawerWidth}px)`,
38
+        transition: theme.transitions.create(['width', 'margin'], {
39
+            easing: theme.transitions.easing.sharp,
40
+            duration: theme.transitions.duration.enteringScreen,
41
+        }),
42
+    }),
43
+}));
44
+
45
+
46
+const Drawer = styled(MuiDrawer, { shouldForwardProp: (prop) => prop !== 'open' })(
47
+    ({ theme, open }) => ({
48
+        '& .MuiDrawer-paper': {
49
+            position: 'relative',
50
+            whiteSpace: 'nowrap',
51
+            width: drawerWidth,
52
+            transition: theme.transitions.create('width', {
53
+                easing: theme.transitions.easing.sharp,
54
+                duration: theme.transitions.duration.enteringScreen,
55
+            }),
56
+            boxSizing: 'border-box',
57
+            ...(!open && {
58
+                overflowX: 'hidden',
59
+                transition: theme.transitions.create('width', {
60
+                    easing: theme.transitions.easing.sharp,
61
+                    duration: theme.transitions.duration.leavingScreen,
62
+                }),
63
+                width: theme.spacing(7),
64
+                [theme.breakpoints.up('sm')]: {
65
+                    width: theme.spacing(9),
66
+                },
67
+            }),
68
+        },
69
+    }),
70
+);
71
+
25 72
 
26 73
 function DashboardContent() {
27 74
 
28 75
     const [open, setOpen] = React.useState(false);
29 76
 
30 77
     const isMovil = Size('(min-width:770px)');
31
-    const auth = useAuth();
32
-    const navigate = useNavigate()
33 78
 
34 79
     const toggleDrawer = () => setOpen(!open);
35
-    const [anchorEl, setAnchorEl] = React.useState(null);
36
-    const open_profile = Boolean(anchorEl);
37
-    const handleClick = (event) => setAnchorEl(event.currentTarget);
38
-    const handleClose = () => setAnchorEl(null)
39 80
 
40 81
     const [anchorElMovil, setAnchorElMov] = React.useState(false);
41 82
     const MenuResponsive = () => {
@@ -43,14 +84,9 @@ function DashboardContent() {
43 84
         setAnchorElMov(!anchorElMovil);
44 85
     }
45 86
 
46
-    const CerrarSession = () => {
47
-        console.log('cerrando session')
48
-        auth.logout();
49
-        navigate('/')
50
-    }
51 87
 
52 88
     return (
53
-        <ThemeProvider theme={mdTheme}>
89
+        <ThemeProvider theme={psicotheme}>
54 90
 
55 91
             <MenuMovil
56 92
                 anchor={anchorElMovil}
@@ -91,45 +127,7 @@ function DashboardContent() {
91 127
                                 ) : undefined
92 128
                             }
93 129
                         </Typography>
94
-
95
-
96
-                        <Box sx={{ display: { xs: 'none', md: 'flex' } }}>
97
-                            <IconButton size="large" aria-label="show 4 new mails" color="inherit">
98
-                                <Badge badgeContent={4} color="error">
99
-                                    <MailIcon style={{ color: '#212529' }} />
100
-                                </Badge>
101
-                            </IconButton>
102
-                            <IconButton
103
-                                size="large"
104
-                                aria-label="show 17 new notifications"
105
-                                color="inherit">
106
-                                <Badge badgeContent={17} color="error">
107
-                                    <NotificationsIcon style={{ color: '#212529' }} />
108
-                                </Badge>
109
-                            </IconButton>
110
-
111
-
112
-                            <IconButton
113
-                                size="small"
114
-                                edge="end"
115
-                                aria-label="account of current user"
116
-                                aria-haspopup="true"
117
-                                aria-expanded={open_profile ? 'true' : undefined}
118
-                                onClick={handleClick}
119
-                                color="inherit" >
120
-                                <Avatar alt="profile picture" src={ProfilePicture} />
121
-                            </IconButton>
122
-                            <Menu
123
-                                id="basic-menu"
124
-                                anchorEl={anchorEl}
125
-                                open={open_profile}
126
-                                onClose={handleClose}
127
-                                MenuListProps={{ 'aria-labelledby': 'basic-button', }}>
128
-                                <MenuItem onClick={() => navigate('dashboard/perfil')}>Mi Cuenta</MenuItem>
129
-                                <MenuItem onClick={() => console.log('dashboard/perfil')}>Configuraciones</MenuItem>
130
-                                <MenuItem onClick={CerrarSession}>Cerrar Sesión</MenuItem>
131
-                            </Menu>
132
-                        </Box>
130
+                        <UserOptions/>
133 131
                     </Toolbar>
134 132
                 </AppBar>
135 133
                 <Drawer variant="permanent" open={open}>

+ 69 - 0
src/Components/Navigation/UserOptions.jsx

@@ -0,0 +1,69 @@
1
+import React from 'react';
2
+import {
3
+    Box, Badge, IconButton, Menu, Avatar, MenuItem
4
+} from '@mui/material'
5
+
6
+import {
7
+    Mail as MailIcon, Notifications as NotificationsIcon,
8
+} from '@mui/icons-material'
9
+
10
+import useAuth from '../../Auth/useAuth.js';
11
+import { useNavigate } from "react-router-dom";
12
+import ProfilePicture from '../../Images/man.png';
13
+
14
+export function UserOptions(){
15
+
16
+    const auth = useAuth();
17
+    const navigate = useNavigate()
18
+
19
+    const CerrarSession = () => {
20
+        auth.logout();
21
+        navigate('/')
22
+    }
23
+
24
+
25
+    const [anchorEl, setAnchorEl] = React.useState(null);
26
+    const open_profile = Boolean(anchorEl);
27
+    const handleClick = (event) => setAnchorEl(event.currentTarget);
28
+    const handleClose = () => setAnchorEl(null)
29
+
30
+    return(
31
+        <Box sx={{ display: { xs: 'none', md: 'flex' } }}>
32
+            <IconButton size="large" aria-label="show 4 new mails" color="inherit">
33
+                <Badge badgeContent={4} color="error">
34
+                    <MailIcon style={{ color: '#212529' }} />
35
+                </Badge>
36
+            </IconButton>
37
+            <IconButton
38
+                size="large"
39
+                aria-label="show 17 new notifications"
40
+                color="inherit">
41
+                <Badge badgeContent={17} color="error">
42
+                    <NotificationsIcon style={{ color: '#212529' }} />
43
+                </Badge>
44
+            </IconButton>
45
+
46
+
47
+            <IconButton
48
+                size="small"
49
+                edge="end"
50
+                aria-label="account of current user"
51
+                aria-haspopup="true"
52
+                aria-expanded={open_profile ? 'true' : undefined}
53
+                onClick={handleClick}
54
+                color="inherit" >
55
+                <Avatar alt="profile picture" src={ProfilePicture} />
56
+            </IconButton>
57
+            <Menu
58
+                id="basic-menu"
59
+                anchorEl={anchorEl}
60
+                pen={open_profile}
61
+                onClose={handleClose}
62
+                MenuListProps={{ 'aria-labelledby': 'basic-button', }}>
63
+                <MenuItem onClick={() => navigate('dashboard/perfil')}>Mi Cuenta</MenuItem>
64
+                <MenuItem onClick={() => console.log('dashboard/perfil')}>Configuraciones</MenuItem>
65
+                <MenuItem onClick={CerrarSession}>Cerrar Sesión</MenuItem>
66
+            </Menu>
67
+        </Box>
68
+    )
69
+}

+ 53 - 15
src/Components/User.jsx

@@ -1,23 +1,25 @@
1 1
 import * as React from 'react';
2 2
 
3
-import { 
4
-    Mail as MailIcon, Menu as MenuIcon,
5
-    MoveToInbox as InboxIcon
6
-} from '@mui/icons-material'
7
-
8
-import { 
9
-    Outlet, 
3
+import {
4
+    Outlet,
10 5
     // useNavigate 
11 6
 } from "react-router-dom";
12 7
 
13
-import { 
8
+import {
14 9
     AppBar, Box, CssBaseline, Divider, Drawer,
15
-    IconButton,List, ListItem, ListItemButton, ListItemIcon, ListItemText,
16
-    Toolbar, Typography, Container
10
+    IconButton, List, ListItem, ListItemButton, ListItemIcon, ListItemText,
11
+    Toolbar, Typography, Container, Badge,
12
+    MenuItem, Avatar,Menu
17 13
 } from '@mui/material'
18 14
 
19
-import Footer from "../Components/Footer.js";
15
+import {
16
+    Mail as MailIcon, Notifications as NotificationsIcon,
17
+    Menu as MenuIcon,
18
+} from '@mui/icons-material'
20 19
 
20
+
21
+import Footer from "../Components/Footer.js";
22
+import ProfilePicture from '../Images/man.png';
21 23
 // import useAuth from '../Auth/useAuth';
22 24
 
23 25
 
@@ -39,11 +41,11 @@ export function User(props) {
39 41
             <Toolbar />
40 42
             <Divider />
41 43
             <List>
42
-                {['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => (
44
+                {['Mi perfil', 'Pruebas', 'Configuracion', 'Ayuda'].map((text, index) => (
43 45
                     <ListItem key={text} disablePadding>
44 46
                         <ListItemButton>
45 47
                             <ListItemIcon>
46
-                                {index % 2 === 0 ? <InboxIcon /> : <MailIcon />}
48
+                                {index % 2 === 0 ? <MailIcon /> : <NotificationsIcon />}
47 49
                             </ListItemIcon>
48 50
                             <ListItemText primary={text} />
49 51
                         </ListItemButton>
@@ -56,7 +58,7 @@ export function User(props) {
56 58
                     <ListItem key={text} disablePadding>
57 59
                         <ListItemButton>
58 60
                             <ListItemIcon>
59
-                                {index % 2 === 0 ? <InboxIcon /> : <MailIcon />}
61
+                                {index % 2 === 0 ? <MailIcon /> : <NotificationsIcon />}
60 62
                             </ListItemIcon>
61 63
                             <ListItemText primary={text} />
62 64
                         </ListItemButton>
@@ -89,9 +91,45 @@ export function User(props) {
89 91
                         <MenuIcon />
90 92
                     </IconButton>
91 93
                     <Typography variant="h6" noWrap component="div">
92
-                        Pruebas Psicometricas
94
+                        Pruebas Asignadas
93 95
                     </Typography>
94 96
                 </Toolbar>
97
+
98
+                <Box sx={{ display: { xs: 'none', md: 'flex' } }}>
99
+                    <IconButton size="large" aria-label="show 4 new mails" color="inherit">
100
+                        <Badge badgeContent={4} color="error">
101
+                            <MailIcon style={{ color: '#212529' }} />
102
+                        </Badge>
103
+                    </IconButton>
104
+                    <IconButton
105
+                        size="large"
106
+                        aria-label="show 17 new notifications"
107
+                        color="inherit">
108
+                        <Badge badgeContent={17} color="error">
109
+                            <NotificationsIcon style={{ color: '#212529' }} />
110
+                        </Badge>
111
+                    </IconButton>
112
+
113
+
114
+                    <IconButton
115
+                        size="small"
116
+                        edge="end"
117
+                        aria-label="account of current user"
118
+                        aria-haspopup="true"
119
+                        aria-expanded={'true'}
120
+                        color="inherit" >
121
+                        <Avatar alt="profile picture" src={ProfilePicture} />
122
+                    </IconButton>
123
+                    <Menu
124
+                        id="basic-menu"
125
+                        MenuListProps={{ 'aria-labelledby': 'basic-button', }}>
126
+                        <MenuItem >Mi Cuenta</MenuItem>
127
+                        <MenuItem >Configuraciones</MenuItem>
128
+                        <MenuItem >Cerrar Sesión</MenuItem>
129
+                    </Menu>
130
+                </Box>
131
+
132
+
95 133
             </AppBar>
96 134
             <Box
97 135
                 component="nav"

+ 1 - 1
src/Utils/theme.js

@@ -1,7 +1,7 @@
1 1
 import { createTheme } from '@mui/material/styles';
2 2
 import { colors } from '@mui/material'
3 3
 
4
-export const mdTheme = createTheme({
4
+export const psicotheme = createTheme({
5 5
     palette: {
6 6
         primary: {
7 7
             main: colors.red[500],