|
@@ -1,29 +1,38 @@
|
|
1
|
+import React from 'react'
|
1
|
2
|
import * as Yup from 'yup';
|
2
|
3
|
import { useState } from 'react';
|
3
|
4
|
import { useFormik, Form, FormikProvider } from 'formik';
|
|
5
|
+import { Service } from '../../Utils/HTTP'
|
4
|
6
|
import { useNavigate } from 'react-router-dom';
|
5
|
7
|
import { Icon } from '@iconify/react';
|
6
|
|
-// material
|
7
|
|
-import { Stack, TextField, IconButton, InputAdornment } from '@mui/material';
|
|
8
|
+
|
|
9
|
+import { Stack, TextField, IconButton, InputAdornment, Button, Backdrop, CircularProgress } from '@mui/material';
|
8
|
10
|
import eyeFill from '@iconify/icons-eva/eye-fill';
|
9
|
11
|
import eyeOffFill from '@iconify/icons-eva/eye-off-fill';
|
10
|
|
-import Button from '@mui/material/Button';
|
|
12
|
+import toast, { Toaster } from 'react-hot-toast';
|
11
|
13
|
|
12
|
14
|
// import { Visibility as eyeFill ,VisibilityOff as eyeOffFill } from '@mui/icons-material/';
|
13
|
15
|
// ----------------------------------------------------------------------
|
14
|
|
-
|
15
|
16
|
export function RegisterForm() {
|
16
|
|
- const navigate = useNavigate();
|
|
17
|
+
|
|
18
|
+ // const navigate = useNavigate();
|
17
|
19
|
const [showPassword, setShowPassword] = useState(false);
|
|
20
|
+ const [open, setOpen] = React.useState(false);
|
|
21
|
+ const handleClose = () => {
|
|
22
|
+ setOpen(false);
|
|
23
|
+ };
|
|
24
|
+
|
|
25
|
+ let navigate = useNavigate()
|
18
|
26
|
|
19
|
27
|
const RegisterSchema = Yup.object().shape({
|
20
|
28
|
firstName: Yup.string()
|
21
|
|
- .min(2, 'Too Short!')
|
22
|
|
- .max(50, 'Too Long!')
|
23
|
|
- .required('First name required'),
|
24
|
|
- lastName: Yup.string().min(2, 'Too Short!').max(50, 'Too Long!').required('Last name required'),
|
25
|
|
- email: Yup.string().email('Email must be a valid email address').required('Email is required'),
|
26
|
|
- password: Yup.string().required('Password is required')
|
|
29
|
+ .min(2, 'Demasiado corto!')
|
|
30
|
+ .max(50, 'Demasiado largo!')
|
|
31
|
+ .required('Tu nombre es requerido'),
|
|
32
|
+ lastName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('El apellido es requerido'),
|
|
33
|
+ email: Yup.string().email('El correo no es valido').required('Email es requerido'),
|
|
34
|
+ password: Yup.string().min(5, 'La contraseña debe contener mínimo 5 caracteres').required('la contraseña es requerida'),
|
|
35
|
+ password_confirm: Yup.string().required('Las contraseñas no coincidien').oneOf([Yup.ref('password'), null], 'Las contraseñas no coincidien')
|
27
|
36
|
});
|
28
|
37
|
|
29
|
38
|
const formik = useFormik({
|
|
@@ -31,11 +40,50 @@ export function RegisterForm() {
|
31
|
40
|
firstName: '',
|
32
|
41
|
lastName: '',
|
33
|
42
|
email: '',
|
34
|
|
- password: ''
|
|
43
|
+ password: '',
|
|
44
|
+ password_confirm: ''
|
35
|
45
|
},
|
36
|
46
|
validationSchema: RegisterSchema,
|
37
|
|
- onSubmit: () => {
|
38
|
|
- navigate('/dashboard', { replace: true });
|
|
47
|
+ onSubmit: (values) => {
|
|
48
|
+ console.log("values > " ,values)
|
|
49
|
+ setOpen(true);
|
|
50
|
+ let body = {
|
|
51
|
+ nombre : values.firstName,
|
|
52
|
+ apelidos : values.lastName,
|
|
53
|
+ email : values.email,
|
|
54
|
+ username : values.email,
|
|
55
|
+ pwd : values.password,
|
|
56
|
+ "nit": "5345435",
|
|
57
|
+ "cui": "555555",
|
|
58
|
+ "direccio": "4 calle zona 1",
|
|
59
|
+ "fechacumple": "2021-01-01",
|
|
60
|
+ "telefono" : "45435345",
|
|
61
|
+ }
|
|
62
|
+ // navigate('/dashboard', { replace: true });
|
|
63
|
+ let request = new Service('/registro');
|
|
64
|
+ request
|
|
65
|
+ .post(body)
|
|
66
|
+ .then( response => {
|
|
67
|
+ console.log(response);
|
|
68
|
+ let { status } = response;
|
|
69
|
+ if(status !== 200){
|
|
70
|
+ setOpen(false)
|
|
71
|
+ return toast.error("Ups! verifica tus datos")
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+ toast.success(`Bienvenido, ingresa tus credenciales`)
|
|
75
|
+ setTimeout( () => {
|
|
76
|
+ setOpen(false)
|
|
77
|
+ navigate('/login')
|
|
78
|
+ // auth.login(token)
|
|
79
|
+ }, 5000)
|
|
80
|
+ })
|
|
81
|
+ .catch( err => {
|
|
82
|
+ setOpen(false)
|
|
83
|
+ toast.error("Solicitud incorrecta")
|
|
84
|
+ console.log("ERROR ", err)
|
|
85
|
+ })
|
|
86
|
+
|
39
|
87
|
}
|
40
|
88
|
});
|
41
|
89
|
|
|
@@ -47,16 +95,16 @@ export function RegisterForm() {
|
47
|
95
|
<Stack spacing={3}>
|
48
|
96
|
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
|
49
|
97
|
<TextField
|
|
98
|
+ label="Nombre"
|
50
|
99
|
fullWidth
|
51
|
|
- label="First name"
|
52
|
100
|
{...getFieldProps('firstName')}
|
53
|
101
|
error={Boolean(touched.firstName && errors.firstName)}
|
54
|
102
|
helperText={touched.firstName && errors.firstName}
|
55
|
103
|
/>
|
56
|
104
|
|
57
|
105
|
<TextField
|
|
106
|
+ label="Apellidos"
|
58
|
107
|
fullWidth
|
59
|
|
- label="Last name"
|
60
|
108
|
{...getFieldProps('lastName')}
|
61
|
109
|
error={Boolean(touched.lastName && errors.lastName)}
|
62
|
110
|
helperText={touched.lastName && errors.lastName}
|
|
@@ -67,19 +115,17 @@ export function RegisterForm() {
|
67
|
115
|
fullWidth
|
68
|
116
|
autoComplete="username"
|
69
|
117
|
type="email"
|
70
|
|
- label="Email address"
|
|
118
|
+ label="Correo Electrónico"
|
71
|
119
|
{...getFieldProps('email')}
|
72
|
120
|
error={Boolean(touched.email && errors.email)}
|
73
|
121
|
helperText={touched.email && errors.email}
|
74
|
122
|
/>
|
75
|
123
|
|
76
|
|
-
|
77
|
|
-
|
78
|
124
|
<TextField
|
79
|
125
|
fullWidth
|
80
|
126
|
autoComplete="current-password"
|
81
|
127
|
type={showPassword ? 'text' : 'password'}
|
82
|
|
- label="Password"
|
|
128
|
+ label="Contraseña"
|
83
|
129
|
{...getFieldProps('password')}
|
84
|
130
|
InputProps={{
|
85
|
131
|
endAdornment: (
|
|
@@ -96,10 +142,9 @@ export function RegisterForm() {
|
96
|
142
|
|
97
|
143
|
<TextField
|
98
|
144
|
fullWidth
|
99
|
|
- autoComplete="current-password"
|
100
|
145
|
type={showPassword ? 'text' : 'password'}
|
101
|
|
- label="Password"
|
102
|
|
- {...getFieldProps('password')}
|
|
146
|
+ label="Confirma contraseña"
|
|
147
|
+ {...getFieldProps('password_confirm')}
|
103
|
148
|
InputProps={{
|
104
|
149
|
endAdornment: (
|
105
|
150
|
<InputAdornment position="end">
|
|
@@ -109,11 +154,12 @@ export function RegisterForm() {
|
109
|
154
|
</InputAdornment>
|
110
|
155
|
)
|
111
|
156
|
}}
|
112
|
|
- error={Boolean(touched.password && errors.password)}
|
113
|
|
- helperText={touched.password && errors.password}
|
|
157
|
+ error={Boolean(touched.password_confirm && errors.password_confirm)}
|
|
158
|
+ helperText={touched.password_confirm && errors.password_confirm}
|
114
|
159
|
/>
|
115
|
160
|
|
116
|
161
|
<Button
|
|
162
|
+ type="submit"
|
117
|
163
|
size="large"
|
118
|
164
|
style={{ backgroundColor : '#d32f2f'}}
|
119
|
165
|
variant="contained" >
|
|
@@ -122,6 +168,17 @@ export function RegisterForm() {
|
122
|
168
|
|
123
|
169
|
</Stack>
|
124
|
170
|
</Form>
|
|
171
|
+ <Toaster
|
|
172
|
+ position="top-left"
|
|
173
|
+ reverseOrder={false}
|
|
174
|
+ />
|
|
175
|
+ <Backdrop
|
|
176
|
+ sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
|
|
177
|
+ open={open}
|
|
178
|
+ onClick={handleClose}
|
|
179
|
+ >
|
|
180
|
+ <CircularProgress color="inherit" />
|
|
181
|
+ </Backdrop>
|
125
|
182
|
</FormikProvider>
|
126
|
183
|
);
|
127
|
184
|
}
|