|
@@ -1,29 +1,31 @@
|
|
|
import * as React from 'react';
|
|
import * as React from 'react';
|
|
|
-import Avatar from '@mui/material/Avatar';
|
|
|
|
|
-import Button from '@mui/material/Button';
|
|
|
|
|
-import CssBaseline from '@mui/material/CssBaseline';
|
|
|
|
|
-import TextField from '@mui/material/TextField';
|
|
|
|
|
|
|
|
|
|
-import PersonIcon from '@mui/icons-material/Person';
|
|
|
|
|
-import Typography from '@mui/material/Typography';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ Paper, Box, Grid,Link, Checkbox, FormControlLabel, Typography,
|
|
|
|
|
+ TextField, CssBaseline, Button, Avatar
|
|
|
|
|
+} from '@mui/material'
|
|
|
|
|
+
|
|
|
import { createTheme, ThemeProvider } from '@mui/material/styles';
|
|
import { createTheme, ThemeProvider } from '@mui/material/styles';
|
|
|
-import {Paper, Box, Grid,Link, Checkbox, FormControlLabel } from '@mui/material'
|
|
|
|
|
|
|
|
|
|
|
|
+import PersonIcon from '@mui/icons-material/Person';
|
|
|
import { useNavigate } from 'react-router-dom'
|
|
import { useNavigate } from 'react-router-dom'
|
|
|
|
|
+import { Copyright } from '../Components/Footer.js'
|
|
|
import useAuth from '../Auth/useAuth';
|
|
import useAuth from '../Auth/useAuth';
|
|
|
|
|
|
|
|
-function Copyright(props){
|
|
|
|
|
- return (
|
|
|
|
|
- <Typography variant="body2" color="text.secondary" align="center" {...props}>
|
|
|
|
|
- {'Copyright © '}
|
|
|
|
|
- <Link color="inherit" href="https://mui.com/">
|
|
|
|
|
- GrupoDIT
|
|
|
|
|
- </Link>{' '}
|
|
|
|
|
- {new Date().getFullYear()}
|
|
|
|
|
- {'.'}
|
|
|
|
|
- </Typography>
|
|
|
|
|
- );
|
|
|
|
|
-}
|
|
|
|
|
|
|
+import { useFormik } from 'formik';
|
|
|
|
|
+import * as Yup from 'yup';
|
|
|
|
|
+
|
|
|
|
|
+const LoginSchema = Yup.object().shape({
|
|
|
|
|
+ email : Yup
|
|
|
|
|
+ .string()
|
|
|
|
|
+ .email('El correo debe ser válido')
|
|
|
|
|
+ .required('El correo es requerido'),
|
|
|
|
|
+
|
|
|
|
|
+ password : Yup
|
|
|
|
|
+ .string()
|
|
|
|
|
+ .required('El campo contraseña es requerido')
|
|
|
|
|
+ .min(6, 'La contraseña debe contener mínimo 6 caracteres')
|
|
|
|
|
+})
|
|
|
|
|
|
|
|
const theme = createTheme();
|
|
const theme = createTheme();
|
|
|
|
|
|
|
@@ -32,22 +34,21 @@ export function Login() {
|
|
|
let auth = useAuth();
|
|
let auth = useAuth();
|
|
|
let navigate = useNavigate()
|
|
let navigate = useNavigate()
|
|
|
|
|
|
|
|
- const handleSubmit = (event) => {
|
|
|
|
|
-
|
|
|
|
|
- event.preventDefault();
|
|
|
|
|
- const data = new FormData(event.currentTarget);
|
|
|
|
|
|
|
+ const formik = useFormik({
|
|
|
|
|
+ initialValues: {
|
|
|
|
|
+ email: '',
|
|
|
|
|
+ password: '',
|
|
|
|
|
+ },
|
|
|
|
|
+ validationSchema: LoginSchema,
|
|
|
|
|
+ onSubmit: (values) => {
|
|
|
|
|
+ // alert(JSON.stringify(values, null, 2));
|
|
|
|
|
+ // return navigate('/dashboard/home')
|
|
|
|
|
+ auth.login(values)
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- let user = {
|
|
|
|
|
- email: data.get('email'),
|
|
|
|
|
- password: data.get('password'),
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- auth.login(user)
|
|
|
|
|
- return navigate('/dashboard/home')
|
|
|
|
|
- };
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
React.useEffect(() => {
|
|
|
- console.log(auth)
|
|
|
|
|
if(auth.isLogged()){
|
|
if(auth.isLogged()){
|
|
|
return navigate('/dashboard/home')
|
|
return navigate('/dashboard/home')
|
|
|
}
|
|
}
|
|
@@ -88,23 +89,32 @@ export function Login() {
|
|
|
<Typography component="h1" variant="h5">
|
|
<Typography component="h1" variant="h5">
|
|
|
Ingresar
|
|
Ingresar
|
|
|
</Typography>
|
|
</Typography>
|
|
|
- <Box component="form" noValidate onSubmit={handleSubmit} sx={{ mt: 1 }}>
|
|
|
|
|
|
|
+
|
|
|
|
|
+ <Box component="form" noValidate onSubmit={formik.handleSubmit} sx={{ mt: 1 }}>
|
|
|
<TextField
|
|
<TextField
|
|
|
|
|
+ value={formik.values.email}
|
|
|
|
|
+ onChange={formik.handleChange}
|
|
|
|
|
+ error={formik.touched.email && Boolean(formik.errors.email)}
|
|
|
|
|
+ helperText={formik.touched.email && formik.errors.email}
|
|
|
margin="normal"
|
|
margin="normal"
|
|
|
required
|
|
required
|
|
|
fullWidth
|
|
fullWidth
|
|
|
id="email"
|
|
id="email"
|
|
|
- label="Email Address"
|
|
|
|
|
name="email"
|
|
name="email"
|
|
|
|
|
+ label="Correo Electrónico"
|
|
|
autoComplete="email"
|
|
autoComplete="email"
|
|
|
autoFocus
|
|
autoFocus
|
|
|
/>
|
|
/>
|
|
|
<TextField
|
|
<TextField
|
|
|
|
|
+ value={formik.values.password}
|
|
|
|
|
+ onChange={formik.handleChange}
|
|
|
|
|
+ error={formik.touched.password && Boolean(formik.errors.password)}
|
|
|
|
|
+ helperText={formik.touched.password && formik.errors.password}
|
|
|
margin="normal"
|
|
margin="normal"
|
|
|
required
|
|
required
|
|
|
fullWidth
|
|
fullWidth
|
|
|
|
|
+ label="Contraseña"
|
|
|
name="password"
|
|
name="password"
|
|
|
- label="Password"
|
|
|
|
|
type="password"
|
|
type="password"
|
|
|
id="password"
|
|
id="password"
|
|
|
autoComplete="current-password"
|
|
autoComplete="current-password"
|