浏览代码

fixes esteticos

amenpunk 2 年之前
父节点
当前提交
1f0e3655b9
共有 4 个文件被更改,包括 210 次插入210 次删除
  1. 2 31
      src/Components/Dashboard.js
  2. 3 0
      src/Components/Routes.js
  3. 178 179
      src/Components/User.jsx
  4. 27 0
      src/Utils/avatar.jsx

+ 2 - 31
src/Components/Dashboard.js

@@ -15,6 +15,7 @@ import {
15 15
 } from '@mui/icons-material'
16 16
 
17 17
 import Logo from '../Images/evaluacion.jpeg';
18
+import { stringAvatar } from '../Utils/avatar'
18 19
 
19 20
 import { Outlet, useNavigate } from "react-router-dom";
20 21
 import { MenuMovil } from '../Components/Navigation/MenuMovil';
@@ -29,34 +30,6 @@ import { removeToken } from '../Slices/tokenSlice';
29 30
 const drawerWidth = 240;
30 31
 const mdTheme = createTheme();
31 32
 
32
-function stringToColor(string) {
33
-  let hash = 0;
34
-  let i;
35
-  /* eslint-disable no-bitwise */
36
-  for (i = 0; i < string.length; i += 1) {
37
-    hash = string.charCodeAt(i) + ((hash << 5) - hash);
38
-  }
39
-
40
-  let color = '#';
41
-
42
-  for (i = 0; i < 3; i += 1) {
43
-    const value = (hash >> (i * 8)) & 0xff;
44
-    color += `00${value.toString(16)}`.slice(-2);
45
-  }
46
-  /* eslint-enable no-bitwise */
47
-  return color;
48
-}
49
-
50
-
51
-function stringAvatar(name) {
52
-  console.log("NAME: ", name)
53
-  return {
54
-    sx: {
55
-      bgcolor: stringToColor(name),
56
-    },
57
-    children: `${name.split(' ')[0][0]}${name.split(' ')[1][0]}`,
58
-  };
59
-}
60 33
 
61 34
 const AppBar = styled(MuiAppBar, {
62 35
   shouldForwardProp: (prop) => prop !== 'open',
@@ -76,7 +49,6 @@ const AppBar = styled(MuiAppBar, {
76 49
   }),
77 50
 }));
78 51
 
79
-
80 52
 const Drawer = styled(MuiDrawer,
81 53
   { shouldForwardProp: (prop) => prop !== 'open' })(
82 54
     ({ theme, open }) => ({
@@ -104,7 +76,6 @@ const Drawer = styled(MuiDrawer,
104 76
     }),
105 77
   );
106 78
 
107
-
108 79
 function DashboardContent() {
109 80
 
110 81
   const [open, setOpen] = React.useState(false);
@@ -193,7 +164,7 @@ function DashboardContent() {
193 164
                 onClick={handleClick}
194 165
                 color="inherit"
195 166
               >
196
-                {/* <Avatar alt="Cindy Baker" src={ProfilePicture} /> */ }
167
+                {/* <Avatar alt="Cindy Baker" src={ProfilePicture} /> */}
197 168
                 <Avatar {...stringAvatar(`${profile.nombre} ${profile.apelidos}`)} />
198 169
 
199 170
               </IconButton>

+ 3 - 0
src/Components/Routes.js

@@ -43,7 +43,10 @@ export default function MyRoutes() {
43 43
             <User />
44 44
           </RequireUserToken>
45 45
         } >
46
+        <Route path="default" element={<Default />} />
47
+        <Route path="default2" element={<Default />} />
46 48
         <Route path="home" element={<HomeUser />} />
49
+        <Route path="pruebas" element={<HomeUser />} />
47 50
         <Route path="prueba">
48 51
           <Route path=":id" element={<Prueba />} />
49 52
           <Route path="" element={<Prueba />} />

+ 178 - 179
src/Components/User.jsx

@@ -2,21 +2,23 @@ import React from 'react';
2 2
 import { ThemeProvider, styled, createTheme } from '@mui/material/styles';
3 3
 import '../Css/user.css'
4 4
 import { removeToken } from '../Slices/tokenSlice'
5
-import { useDispatch } from 'react-redux'
5
+import { useDispatch, useSelector } from 'react-redux'
6 6
 
7 7
 import {
8
-    Container, IconButton, Divider,
9
-    Typography, List, Toolbar,useMediaQuery as Size,
10
-    Box, Badge, Menu, Avatar, MenuItem
8
+  Container, IconButton, Divider,
9
+  Typography, List, Toolbar, useMediaQuery as Size,
10
+  Box, Badge, Menu, Avatar, MenuItem
11 11
 } from '@mui/material'
12 12
 
13 13
 import {
14
-    Fullscreen as FullscreenIcon,
15
-    Menu as MenuIcon,
16
-    KeyboardDoubleArrowLeft as LeftKey,
17
-    Mail as MailIcon, Notifications as NotificationsIcon,
14
+  Fullscreen as FullscreenIcon,
15
+  Menu as MenuIcon,
16
+  KeyboardDoubleArrowLeft as LeftKey,
17
+  Notifications as NotificationsIcon,
18 18
 } from '@mui/icons-material'
19 19
 
20
+import { stringAvatar } from '../Utils/avatar'
21
+
20 22
 import Logo from '../Images/evaluacion.jpeg';
21 23
 
22 24
 import { Outlet, useNavigate } from "react-router-dom";
@@ -25,195 +27,192 @@ import Footer from "../Components/Footer";
25 27
 
26 28
 import { Drawer as MuiDrawer, AppBar as MuiAppBar } from "../Components/Navigation/AppBar"
27 29
 import { UserListItems, SecondaryListItems } from '../Components/Navigation/listItems';
28
-import ProfilePicture from '../Images/man.png';
30
+// import ProfilePicture from '../Images/man.png';
29 31
 
30 32
 const drawerWidth = 240;
31 33
 const mdTheme = createTheme();
32 34
 
33 35
 const AppBar = styled(MuiAppBar, {
34
-    shouldForwardProp: (prop) => prop !== 'open',
36
+  shouldForwardProp: (prop) => prop !== 'open',
35 37
 })(({ theme, open }) => ({
36
-    zIndex: theme.zIndex.drawer + 1,
38
+  zIndex: theme.zIndex.drawer + 1,
39
+  transition: theme.transitions.create(['width', 'margin'], {
40
+    easing: theme.transitions.easing.sharp,
41
+    duration: theme.transitions.duration.leavingScreen,
42
+  }),
43
+  ...(open && {
44
+    marginLeft: drawerWidth,
45
+    width: `calc(100% - ${drawerWidth}px)`,
37 46
     transition: theme.transitions.create(['width', 'margin'], {
38
-        easing: theme.transitions.easing.sharp,
39
-        duration: theme.transitions.duration.leavingScreen,
40
-    }),
41
-    ...(open && {
42
-        marginLeft: drawerWidth,
43
-        width: `calc(100% - ${drawerWidth}px)`,
44
-        transition: theme.transitions.create(['width', 'margin'], {
45
-            easing: theme.transitions.easing.sharp,
46
-            duration: theme.transitions.duration.enteringScreen,
47
-        }),
47
+      easing: theme.transitions.easing.sharp,
48
+      duration: theme.transitions.duration.enteringScreen,
48 49
     }),
50
+  }),
49 51
 }));
50 52
 
51 53
 
52
-const Drawer = styled(MuiDrawer, 
53
-    { shouldForwardProp: (prop) => prop !== 'open' })(
54
+const Drawer = styled(MuiDrawer,
55
+  { shouldForwardProp: (prop) => prop !== 'open' })(
54 56
     ({ theme, open }) => ({
55
-        '& .MuiDrawer-paper': {
56
-            position: 'relative',
57
-            whiteSpace: 'nowrap',
58
-            width: drawerWidth,
59
-            transition: theme.transitions.create('width', {
60
-                easing: theme.transitions.easing.sharp,
61
-                duration: theme.transitions.duration.enteringScreen,
62
-            }),
63
-            boxSizing: 'border-box',
64
-            ...(!open && {
65
-                overflowX: 'hidden',
66
-                transition: theme.transitions.create('width', {
67
-                    easing: theme.transitions.easing.sharp,
68
-                    duration: theme.transitions.duration.leavingScreen,
69
-                }),
70
-                width: theme.spacing(7),
71
-                [theme.breakpoints.up('sm')]: {
72
-                    width: theme.spacing(9),
73
-                },
74
-            }),
75
-        },
57
+      '& .MuiDrawer-paper': {
58
+        position: 'relative',
59
+        whiteSpace: 'nowrap',
60
+        width: drawerWidth,
61
+        transition: theme.transitions.create('width', {
62
+          easing: theme.transitions.easing.sharp,
63
+          duration: theme.transitions.duration.enteringScreen,
64
+        }),
65
+        boxSizing: 'border-box',
66
+        ...(!open && {
67
+          overflowX: 'hidden',
68
+          transition: theme.transitions.create('width', {
69
+            easing: theme.transitions.easing.sharp,
70
+            duration: theme.transitions.duration.leavingScreen,
71
+          }),
72
+          width: theme.spacing(7),
73
+          [theme.breakpoints.up('sm')]: {
74
+            width: theme.spacing(9),
75
+          },
76
+        }),
77
+      },
76 78
     }),
77
-);
79
+  );
78 80
 
79 81
 export function User() {
80 82
 
81
-    const [open, setOpen] = React.useState(true);
82
-
83
-    const isMovil = Size('(max-width:1000px)');
84
-    const navigate = useNavigate()
85
-    let dispatch = useDispatch()
86
-
87
-    const CerrarSession = () => {
88
-      dispatch(removeToken({ candi:true}))
89
-      navigate('/logincd')
90
-    }
91
-
92
-    const [anchorEl, setAnchorEl] = React.useState(null);
93
-    const open_profile = Boolean(anchorEl);
94
-    const handleClick = (event) =>  setAnchorEl(event.currentTarget);
95
-    const handleClose = () => setAnchorEl(null)
96
-    const toggleDrawer = () => {
97
-        if(isMovil){
98
-            setAnchorElMov(!anchorElMovil)
99
-        }else{
100
-            setOpen(!open);
101
-        }
83
+  const [open, setOpen] = React.useState(true);
84
+
85
+  const isMovil = Size('(max-width:1000px)');
86
+  const navigate = useNavigate()
87
+  let dispatch = useDispatch()
88
+  let profile = useSelector((state) => state.user.profile)
89
+  let name = `${(profile?.email.substring(0, 1))} ${profile?.email.substring(1, 2)}`
90
+
91
+  const CerrarSession = () => {
92
+    dispatch(removeToken({ candi: true }))
93
+    navigate('/logincd')
94
+  }
95
+
96
+  const [anchorEl, setAnchorEl] = React.useState(null);
97
+  const open_profile = Boolean(anchorEl);
98
+  const handleClick = (event) => setAnchorEl(event.currentTarget);
99
+  const handleClose = () => setAnchorEl(null)
100
+  const toggleDrawer = () => {
101
+    if (isMovil) {
102
+      setAnchorElMov(!anchorElMovil)
103
+    } else {
104
+      setOpen(!open);
102 105
     }
103
-    const [anchorElMovil, setAnchorElMov] = React.useState(false);
104
-    React.useEffect(() => isMovil ? setOpen(false) : null , [isMovil])
105
-
106
-    return (
107
-        <ThemeProvider theme={mdTheme}>
108
-
109
-            <MenuMovil anchor={anchorElMovil} control={setAnchorElMov} />
110
-
111
-            <Box sx={{ display: 'flex' }}>
112
-                <AppBar style={{ backgroundColor: '#fff', boxShadow: 'None' }} position="absolute" open={open}>
113
-                    <Toolbar sx={{ pr: '24px', borderBottom: "1px solid var(--main)" }} >
114
-                        <IconButton
115
-                            name="navigation_icon_button"
116
-                            edge="start"
117
-                            color="inherit"
118
-                            aria-label="open drawer"
119
-                            onClick={toggleDrawer}
120
-                            sx={{ marginRight: '36px', ...( open  && { display: 'none' }), }} >
121
-                            <MenuIcon style={{
122
-                                background: 'var(--main)',
123
-                                fontSize: "40",
124
-                                color: "#fff"
125
-                            }} />
126
-                        </IconButton>
127
-                        <Typography component="h1" variant="h6" color="inherit" noWrap sx={{ flexGrow: 1 }} >
128
-                            {
129
-                                open ? (
130
-                                    <React.Fragment>
131
-
132
-                                        <IconButton onClick={toggleDrawer}>
133
-                                            <LeftKey/>
134
-                                        </IconButton>
135
-
136
-                                        <IconButton onClick={(event) => event.target.requestFullscreen()}>
137
-                                            <FullscreenIcon style={{ paddinLeft: 15 }} />
138
-                                        </IconButton>
139
-                                    </React.Fragment>
140
-                                ) : undefined
141
-                            }
142
-                        </Typography>
143
-
144
-                        <Box sx={{ display: { xs: 'none', md: 'flex' } }}>
145
-                            <IconButton size="large" aria-label="show 4 new mails" color="inherit">
146
-                                <Badge badgeContent={4} color="error">
147
-                                    <MailIcon style={{ color : '#212529' }} />
148
-                                </Badge>
149
-                            </IconButton>
150
-                            <IconButton
151
-                                size="large"
152
-                                aria-label="show 17 new notifications"
153
-                                color="inherit">
154
-                                <Badge badgeContent={17} color="error">
155
-                                    <NotificationsIcon style={{ color : '#212529' }}/>
156
-                                </Badge>
157
-                            </IconButton>
158
-
159
-
160
-                            <IconButton
161
-                                size="small"
162
-                                edge="end"
163
-                                aria-label="account of current user"
164
-                                aria-haspopup="true"
165
-                                aria-expanded={open_profile ? 'true' : undefined}
166
-                                onClick={handleClick}
167
-                                color="inherit"
168
-                            >
169
-                                <Avatar alt="Cindy Baker" src={ProfilePicture} />
170
-
171
-                            </IconButton>
172
-                            <Menu
173
-                                id="basic-menu"
174
-                                anchorEl={anchorEl}
175
-                                open={open_profile}
176
-                                onClose={handleClose}
177
-                                MenuListProps={{ 'aria-labelledby': 'basic-button', }}>
178
-                                <MenuItem onClick={() => navigate('dashboard/perfil') }>Profile</MenuItem>
179
-                                <MenuItem onClick={() => console.log('opcion 2')}>My account</MenuItem>
180
-                                <MenuItem onClick={CerrarSession}>Logout</MenuItem>
181
-                            </Menu>
182
-                        </Box>
183
-
184
-
185
-                    </Toolbar>
186
-                </AppBar>
187
-                <Drawer variant="permanent" open={open} >
188
-                    <Toolbar
189
-                        sx={{
190
-                            display: 'flex',
191
-                            alignItems: 'center',
192
-                            justifyContent: 'flex-start',
193
-                            px: [1]
194
-                        }} >
195
-                        <div style={{ flat: 'righ' }} className="sidebar-header">
196
-                            <div className="width_img">
197
-                                <img src={Logo} alt="pruebas psicometricas" />
198
-                            </div>
199
-                        </div>
200
-                    </Toolbar>
201
-                    <Divider />
202
-                    <List>
203
-                        <UserListItems AppBarVisible={open} setAppBarVisible={setOpen} />
204
-                    </List>
205
-                    <Divider />
206
-                    <List>
207
-                        {SecondaryListItems}
208
-                    </List>
209
-                </Drawer>
210
-                <Container maxWidth="lg" sx={{ mt: 2, mb: 2 }}>
211
-                    <Outlet />
212
-                    <Footer />
213
-                </Container>
106
+  }
107
+  const [anchorElMovil, setAnchorElMov] = React.useState(false);
108
+  React.useEffect(() => isMovil ? setOpen(false) : null, [isMovil])
109
+
110
+  return (
111
+    <ThemeProvider theme={mdTheme}>
112
+
113
+      <MenuMovil anchor={anchorElMovil} control={setAnchorElMov} />
114
+
115
+      <Box sx={{ display: 'flex' }}>
116
+        <AppBar style={{ backgroundColor: '#fff', boxShadow: 'None' }} position="absolute" open={open}>
117
+          <Toolbar sx={{ pr: '24px', borderBottom: "1px solid var(--main)" }} >
118
+            <IconButton
119
+              name="navigation_icon_button"
120
+              edge="start"
121
+              color="inherit"
122
+              aria-label="open drawer"
123
+              onClick={toggleDrawer}
124
+              sx={{ marginRight: '36px', ...(open && { display: 'none' }), }} >
125
+              <MenuIcon style={{
126
+                background: 'var(--main)',
127
+                fontSize: "40",
128
+                color: "#fff"
129
+              }} />
130
+            </IconButton>
131
+            <Typography component="h1" variant="h6" color="inherit" noWrap sx={{ flexGrow: 1 }} >
132
+              {
133
+                open ? (
134
+                  <React.Fragment>
135
+
136
+                    <IconButton onClick={toggleDrawer}>
137
+                      <LeftKey />
138
+                    </IconButton>
139
+
140
+                    <IconButton onClick={(event) => event.target.requestFullscreen()}>
141
+                      <FullscreenIcon style={{ paddinLeft: 15 }} />
142
+                    </IconButton>
143
+                  </React.Fragment>
144
+                ) : undefined
145
+              }
146
+            </Typography>
147
+
148
+            <Box sx={{ display: { xs: 'none', md: 'flex' } }}>
149
+              <IconButton
150
+                size="large"
151
+                aria-label="show 17 new notifications"
152
+                color="inherit">
153
+                <Badge badgeContent={1} color="error">
154
+                  <NotificationsIcon style={{ color: '#212529' }} />
155
+                </Badge>
156
+              </IconButton>
157
+
158
+
159
+              <IconButton
160
+                size="small"
161
+                edge="end"
162
+                aria-label="account of current user"
163
+                aria-haspopup="true"
164
+                aria-expanded={open_profile ? 'true' : undefined}
165
+                onClick={handleClick}
166
+                color="inherit"
167
+              >
168
+                <Avatar {...stringAvatar(name)} />
169
+
170
+              </IconButton>
171
+              <Menu
172
+                id="basic-menu"
173
+                anchorEl={anchorEl}
174
+                open={open_profile}
175
+                onClose={handleClose}
176
+                MenuListProps={{ 'aria-labelledby': 'basic-button', }}>
177
+                <MenuItem onClick={() => navigate('dashboard/perfil')}>Profile</MenuItem>
178
+                <MenuItem onClick={() => console.log('opcion 2')}>My account</MenuItem>
179
+                <MenuItem onClick={CerrarSession}>Logout</MenuItem>
180
+              </Menu>
214 181
             </Box>
215
-        </ThemeProvider>
216
-    );
182
+
183
+
184
+          </Toolbar>
185
+        </AppBar>
186
+        <Drawer variant="permanent" open={open} >
187
+          <Toolbar
188
+            sx={{
189
+              display: 'flex',
190
+              alignItems: 'center',
191
+              justifyContent: 'flex-start',
192
+              px: [1]
193
+            }} >
194
+            <div style={{ flat: 'righ' }} className="sidebar-header">
195
+              <div className="width_img">
196
+                <img src={Logo} alt="pruebas psicometricas" />
197
+              </div>
198
+            </div>
199
+          </Toolbar>
200
+          <Divider />
201
+          <List>
202
+            <UserListItems AppBarVisible={open} setAppBarVisible={setOpen} />
203
+          </List>
204
+          <Divider />
205
+          <List>
206
+            {SecondaryListItems}
207
+          </List>
208
+        </Drawer>
209
+        <Container maxWidth="lg" sx={{ mt: 2, mb: 2 }}>
210
+          <Outlet />
211
+          <Footer />
212
+        </Container>
213
+      </Box>
214
+    </ThemeProvider>
215
+  );
217 216
 
218 217
 }
219 218
 

+ 27 - 0
src/Utils/avatar.jsx

@@ -0,0 +1,27 @@
1
+function stringToColor(string) {
2
+  let hash = 0;
3
+  let i;
4
+  /* eslint-disable no-bitwise */
5
+  for (i = 0; i < string.length; i += 1) {
6
+    hash = string.charCodeAt(i) + ((hash << 5) - hash);
7
+  }
8
+
9
+  let color = '#';
10
+
11
+  for (i = 0; i < 3; i += 1) {
12
+    const value = (hash >> (i * 8)) & 0xff;
13
+    color += `00${value.toString(16)}`.slice(-2);
14
+  }
15
+  /* eslint-enable no-bitwise */
16
+  return color;
17
+}
18
+
19
+
20
+export function stringAvatar(name) {
21
+  return {
22
+    sx: {
23
+      bgcolor: stringToColor(name),
24
+    },
25
+    children: `${name.split(' ')[0][0]}${name.split(' ')[1][0]}`,
26
+  };
27
+}