|
@@ -1,10 +1,10 @@
|
|
|
import * as React from 'react';
|
|
import * as React from 'react';
|
|
|
-// import toast, { Toaster } from 'react-hot-toast';
|
|
|
|
|
-import { Toaster } from 'react-hot-toast';
|
|
|
|
|
|
|
+import toast, { Toaster } from 'react-hot-toast';
|
|
|
|
|
|
|
|
import {
|
|
import {
|
|
|
Paper, Box, Grid, Checkbox, FormControlLabel, Typography,
|
|
Paper, Box, Grid, Checkbox, FormControlLabel, Typography,
|
|
|
- TextField, CssBaseline, Button, Avatar
|
|
|
|
|
|
|
+ TextField, CssBaseline, Button, Avatar,
|
|
|
|
|
+ Backdrop, CircularProgress
|
|
|
} from '@mui/material'
|
|
} from '@mui/material'
|
|
|
|
|
|
|
|
import { createTheme, ThemeProvider } from '@mui/material/styles';
|
|
import { createTheme, ThemeProvider } from '@mui/material/styles';
|
|
@@ -18,18 +18,18 @@ import useAuth from '../Auth/useAuth';
|
|
|
import { useFormik } from 'formik';
|
|
import { useFormik } from 'formik';
|
|
|
import * as Yup from 'yup';
|
|
import * as Yup from 'yup';
|
|
|
|
|
|
|
|
-import { HTTP_ } from '../Utils/HTTP.js'
|
|
|
|
|
|
|
+import { Service } from '../Utils/HTTP.js'
|
|
|
|
|
|
|
|
const LoginSchema = Yup.object().shape({
|
|
const LoginSchema = Yup.object().shape({
|
|
|
email : Yup
|
|
email : Yup
|
|
|
.string()
|
|
.string()
|
|
|
- .email('El correo debe ser válido')
|
|
|
|
|
- .required('El correo es requerido'),
|
|
|
|
|
|
|
+ // .email('El correo debe ser válido')
|
|
|
|
|
+ .required('El correo o usuario es requerido'),
|
|
|
|
|
|
|
|
password : Yup
|
|
password : Yup
|
|
|
.string()
|
|
.string()
|
|
|
.required('El campo contraseña es requerido')
|
|
.required('El campo contraseña es requerido')
|
|
|
- .min(6, 'La contraseña debe contener mínimo 6 caracteres')
|
|
|
|
|
|
|
+ .min(5, 'La contraseña debe contener mínimo 5 caracteres')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
const theme = createTheme();
|
|
const theme = createTheme();
|
|
@@ -39,22 +39,40 @@ export function Login() {
|
|
|
let auth = useAuth();
|
|
let auth = useAuth();
|
|
|
let navigate = useNavigate()
|
|
let navigate = useNavigate()
|
|
|
|
|
|
|
|
|
|
+ const [open, setOpen] = React.useState(false);
|
|
|
|
|
+ const handleClose = () => {
|
|
|
|
|
+ setOpen(false);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
const formik = useFormik({
|
|
const formik = useFormik({
|
|
|
initialValues: {
|
|
initialValues: {
|
|
|
email: '',
|
|
email: '',
|
|
|
password: '',
|
|
password: '',
|
|
|
},
|
|
},
|
|
|
validationSchema: LoginSchema,
|
|
validationSchema: LoginSchema,
|
|
|
- onSubmit: (values) => {
|
|
|
|
|
|
|
+ onSubmit: async (values) => {
|
|
|
let { email, password } = values
|
|
let { email, password } = values
|
|
|
- console.log(email,password);
|
|
|
|
|
- // let request = new HTTP('/user?' + `user=${email}&password=${password}`)
|
|
|
|
|
- let request = new HTTP_()
|
|
|
|
|
- request.get_()
|
|
|
|
|
|
|
+ setOpen(true)
|
|
|
|
|
+
|
|
|
|
|
+ let request = new Service(`/user?user=${email}&password=${password}`)
|
|
|
|
|
+ request
|
|
|
|
|
+ .post({})
|
|
|
|
|
+ .then( () => {
|
|
|
|
|
+ toast.success('Bienvenido!!')
|
|
|
|
|
+
|
|
|
|
|
+ setTimeout( () => {
|
|
|
|
|
+ setOpen(false)
|
|
|
|
|
+ auth.login(values)
|
|
|
|
|
+ }, 2000)
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch( err => {
|
|
|
|
|
+ setOpen(false)
|
|
|
|
|
+ toast.error("Ups! usuario o contraseña incorrectos")
|
|
|
|
|
+ console.log("ERROR ", err)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
// toast.success('Bienvenido!!')
|
|
// toast.success('Bienvenido!!')
|
|
|
- // toast.error("This didn't work.")
|
|
|
|
|
// return navigate('/dashboard/home')
|
|
// return navigate('/dashboard/home')
|
|
|
- auth.login(values)
|
|
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -84,6 +102,7 @@ export function Login() {
|
|
|
}}
|
|
}}
|
|
|
/>
|
|
/>
|
|
|
<Grid item xs={12} sm={8} md={5} component={Paper} elevation={6} square>
|
|
<Grid item xs={12} sm={8} md={5} component={Paper} elevation={6} square>
|
|
|
|
|
+
|
|
|
<Box
|
|
<Box
|
|
|
sx={{
|
|
sx={{
|
|
|
my: 8,
|
|
my: 8,
|
|
@@ -168,6 +187,15 @@ export function Login() {
|
|
|
position="top-left"
|
|
position="top-left"
|
|
|
reverseOrder={false}
|
|
reverseOrder={false}
|
|
|
/>
|
|
/>
|
|
|
|
|
+ <Backdrop
|
|
|
|
|
+ sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
|
|
|
|
|
+ open={open}
|
|
|
|
|
+ onClick={handleClose}
|
|
|
|
|
+ >
|
|
|
|
|
+ <CircularProgress color="inherit" />
|
|
|
|
|
+ </Backdrop>
|
|
|
|
|
+
|
|
|
</ThemeProvider>
|
|
</ThemeProvider>
|
|
|
|
|
+
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|