|
@@ -1,15 +1,22 @@
|
1
|
1
|
import { useState } from 'react'
|
2
|
|
-import { useFormik, Form, FormikProvider } from 'formik'; // import { useNavigate } from 'react-router-dom';
|
3
|
|
-import { Stack, TextField,Box, Button,
|
|
2
|
+import { useFormik, Form, FormikProvider } from 'formik';
|
|
3
|
+import { useNavigate } from 'react-router-dom';
|
|
4
|
+import {
|
|
5
|
+ Stack, TextField,Box, Button,
|
4
|
6
|
Backdrop, CircularProgress,
|
5
|
7
|
} from '@mui/material';
|
6
|
8
|
import toast, { Toaster } from 'react-hot-toast';
|
7
|
9
|
import * as Yup from 'yup';
|
8
|
10
|
|
|
11
|
+import { Service } from '../../Utils/HTTP';
|
|
12
|
+// import useAuth from '../../Auth/useAuth';;
|
|
13
|
+
|
9
|
14
|
export function PersonalInfo(props) {
|
10
|
15
|
|
11
|
16
|
let { handleBack, setClient, client } = props
|
12
|
17
|
|
|
18
|
+ let navigate = useNavigate()
|
|
19
|
+
|
13
|
20
|
const RegisterSchema = Yup.object().shape({
|
14
|
21
|
nit: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('El nit es requerido'),
|
15
|
22
|
cui: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('Tu CUI/DPI es requerido'),
|
|
@@ -31,20 +38,47 @@ export function PersonalInfo(props) {
|
31
|
38
|
validationSchema: RegisterSchema,
|
32
|
39
|
onSubmit: (values) => {
|
33
|
40
|
setOpen(true);
|
34
|
|
- // let url = 'http://204.48.25.93:8081/registro'
|
35
|
|
- // let url = 'http://psicoadmin.ditca.org:8081/registro'
|
36
|
|
- console.log(client)
|
37
|
|
- setClient({
|
38
|
|
- ...client, ...values
|
39
|
|
- })
|
40
|
41
|
|
41
|
|
- setTimeout(() => {
|
|
42
|
+ let new_client = {
|
|
43
|
+ ...client, ...values
|
|
44
|
+ }
|
|
45
|
+ setClient(new_client)
|
|
46
|
+
|
|
47
|
+ let body = {
|
|
48
|
+ "nombre" : new_client.firstName,
|
|
49
|
+ "apelidos" : new_client.lastName,
|
|
50
|
+ "telefono" : new_client.telefono,
|
|
51
|
+ "direccio": new_client.direccion,
|
|
52
|
+ "fechacumple": new_client.nacimiento,
|
|
53
|
+ "nit": new_client.nit,
|
|
54
|
+ "cui": new_client.cui,
|
|
55
|
+ "email": new_client.email,
|
|
56
|
+ "username": new_client.email,
|
|
57
|
+ "pwd": new_client.password
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+ let req = new Service('/registro');
|
|
62
|
+
|
|
63
|
+ req.post(body)
|
|
64
|
+ .then( data => {
|
|
65
|
+
|
|
66
|
+ setTimeout(() => {
|
|
67
|
+ setOpen(false);
|
|
68
|
+ return navigate('/')
|
|
69
|
+ }, 2000)
|
|
70
|
+
|
|
71
|
+ console.log("DATA ::", data)
|
42
|
72
|
let nombre = client.firstName + " " + client.lastName
|
43
|
73
|
toast.success(`Bienvenido ${nombre} !!`)
|
44
|
|
- setOpen(false);
|
45
|
|
- }, 5000)
|
46
|
74
|
|
47
|
75
|
|
|
76
|
+ })
|
|
77
|
+ .catch(error => {
|
|
78
|
+ console.log("ERROR ::", error)
|
|
79
|
+ toast.error(`Ups ocurrió un error puede que tu usuario yo exista o sea un error interno, intenta nuevamente más tarde o ponte en contacto con nosotros`)
|
|
80
|
+ return setOpen(false);
|
|
81
|
+ })
|
48
|
82
|
|
49
|
83
|
}
|
50
|
84
|
});
|