|
@@ -1,29 +1,31 @@
|
1
|
1
|
import * as React from 'react';
|
2
|
|
-import Avatar from '@mui/material/Avatar';
|
3
|
|
-import Button from '@mui/material/Button';
|
4
|
|
-import CssBaseline from '@mui/material/CssBaseline';
|
5
|
|
-import TextField from '@mui/material/TextField';
|
6
|
2
|
|
7
|
|
-import PersonIcon from '@mui/icons-material/Person';
|
8
|
|
-import Typography from '@mui/material/Typography';
|
|
3
|
+import {
|
|
4
|
+ Paper, Box, Grid,Link, Checkbox, FormControlLabel, Typography,
|
|
5
|
+ TextField, CssBaseline, Button, Avatar
|
|
6
|
+} from '@mui/material'
|
|
7
|
+
|
9
|
8
|
import { createTheme, ThemeProvider } from '@mui/material/styles';
|
10
|
|
-import {Paper, Box, Grid,Link, Checkbox, FormControlLabel } from '@mui/material'
|
11
|
9
|
|
|
10
|
+import PersonIcon from '@mui/icons-material/Person';
|
12
|
11
|
import { useNavigate } from 'react-router-dom'
|
|
12
|
+import { Copyright } from '../Components/Footer.js'
|
13
|
13
|
import useAuth from '../Auth/useAuth';
|
14
|
14
|
|
15
|
|
-function Copyright(props){
|
16
|
|
- return (
|
17
|
|
- <Typography variant="body2" color="text.secondary" align="center" {...props}>
|
18
|
|
- {'Copyright © '}
|
19
|
|
- <Link color="inherit" href="https://mui.com/">
|
20
|
|
- GrupoDIT
|
21
|
|
- </Link>{' '}
|
22
|
|
- {new Date().getFullYear()}
|
23
|
|
- {'.'}
|
24
|
|
- </Typography>
|
25
|
|
- );
|
26
|
|
-}
|
|
15
|
+import { useFormik } from 'formik';
|
|
16
|
+import * as Yup from 'yup';
|
|
17
|
+
|
|
18
|
+const LoginSchema = Yup.object().shape({
|
|
19
|
+ email : Yup
|
|
20
|
+ .string()
|
|
21
|
+ .email('El correo debe ser válido')
|
|
22
|
+ .required('El correo es requerido'),
|
|
23
|
+
|
|
24
|
+ password : Yup
|
|
25
|
+ .string()
|
|
26
|
+ .required('El campo contraseña es requerido')
|
|
27
|
+ .min(6, 'La contraseña debe contener mínimo 6 caracteres')
|
|
28
|
+})
|
27
|
29
|
|
28
|
30
|
const theme = createTheme();
|
29
|
31
|
|
|
@@ -32,22 +34,21 @@ export function Login() {
|
32
|
34
|
let auth = useAuth();
|
33
|
35
|
let navigate = useNavigate()
|
34
|
36
|
|
35
|
|
- const handleSubmit = (event) => {
|
36
|
|
-
|
37
|
|
- event.preventDefault();
|
38
|
|
- const data = new FormData(event.currentTarget);
|
|
37
|
+ const formik = useFormik({
|
|
38
|
+ initialValues: {
|
|
39
|
+ email: '',
|
|
40
|
+ password: '',
|
|
41
|
+ },
|
|
42
|
+ validationSchema: LoginSchema,
|
|
43
|
+ onSubmit: (values) => {
|
|
44
|
+ // alert(JSON.stringify(values, null, 2));
|
|
45
|
+ // return navigate('/dashboard/home')
|
|
46
|
+ auth.login(values)
|
|
47
|
+ },
|
|
48
|
+ });
|
39
|
49
|
|
40
|
|
- let user = {
|
41
|
|
- email: data.get('email'),
|
42
|
|
- password: data.get('password'),
|
43
|
|
- }
|
44
|
|
-
|
45
|
|
- auth.login(user)
|
46
|
|
- return navigate('/dashboard/home')
|
47
|
|
- };
|
48
|
50
|
|
49
|
51
|
React.useEffect(() => {
|
50
|
|
- console.log(auth)
|
51
|
52
|
if(auth.isLogged()){
|
52
|
53
|
return navigate('/dashboard/home')
|
53
|
54
|
}
|
|
@@ -88,23 +89,32 @@ export function Login() {
|
88
|
89
|
<Typography component="h1" variant="h5">
|
89
|
90
|
Ingresar
|
90
|
91
|
</Typography>
|
91
|
|
- <Box component="form" noValidate onSubmit={handleSubmit} sx={{ mt: 1 }}>
|
|
92
|
+
|
|
93
|
+ <Box component="form" noValidate onSubmit={formik.handleSubmit} sx={{ mt: 1 }}>
|
92
|
94
|
<TextField
|
|
95
|
+ value={formik.values.email}
|
|
96
|
+ onChange={formik.handleChange}
|
|
97
|
+ error={formik.touched.email && Boolean(formik.errors.email)}
|
|
98
|
+ helperText={formik.touched.email && formik.errors.email}
|
93
|
99
|
margin="normal"
|
94
|
100
|
required
|
95
|
101
|
fullWidth
|
96
|
102
|
id="email"
|
97
|
|
- label="Email Address"
|
98
|
103
|
name="email"
|
|
104
|
+ label="Correo Electrónico"
|
99
|
105
|
autoComplete="email"
|
100
|
106
|
autoFocus
|
101
|
107
|
/>
|
102
|
108
|
<TextField
|
|
109
|
+ value={formik.values.password}
|
|
110
|
+ onChange={formik.handleChange}
|
|
111
|
+ error={formik.touched.password && Boolean(formik.errors.password)}
|
|
112
|
+ helperText={formik.touched.password && formik.errors.password}
|
103
|
113
|
margin="normal"
|
104
|
114
|
required
|
105
|
115
|
fullWidth
|
|
116
|
+ label="Contraseña"
|
106
|
117
|
name="password"
|
107
|
|
- label="Password"
|
108
|
118
|
type="password"
|
109
|
119
|
id="password"
|
110
|
120
|
autoComplete="current-password"
|