|
@@ -1,15 +1,22 @@
|
|
|
import { useState } from 'react'
|
|
import { useState } from 'react'
|
|
|
-import { useFormik, Form, FormikProvider } from 'formik'; // import { useNavigate } from 'react-router-dom';
|
|
|
|
|
-import { Stack, TextField,Box, Button,
|
|
|
|
|
|
|
+import { useFormik, Form, FormikProvider } from 'formik';
|
|
|
|
|
+import { useNavigate } from 'react-router-dom';
|
|
|
|
|
+import {
|
|
|
|
|
+ Stack, TextField,Box, Button,
|
|
|
Backdrop, CircularProgress,
|
|
Backdrop, CircularProgress,
|
|
|
} from '@mui/material';
|
|
} from '@mui/material';
|
|
|
import toast, { Toaster } from 'react-hot-toast';
|
|
import toast, { Toaster } from 'react-hot-toast';
|
|
|
import * as Yup from 'yup';
|
|
import * as Yup from 'yup';
|
|
|
|
|
|
|
|
|
|
+import { Service } from '../../Utils/HTTP';
|
|
|
|
|
+// import useAuth from '../../Auth/useAuth';;
|
|
|
|
|
+
|
|
|
export function PersonalInfo(props) {
|
|
export function PersonalInfo(props) {
|
|
|
|
|
|
|
|
let { handleBack, setClient, client } = props
|
|
let { handleBack, setClient, client } = props
|
|
|
|
|
|
|
|
|
|
+ let navigate = useNavigate()
|
|
|
|
|
+
|
|
|
const RegisterSchema = Yup.object().shape({
|
|
const RegisterSchema = Yup.object().shape({
|
|
|
nit: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('El nit es requerido'),
|
|
nit: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('El nit es requerido'),
|
|
|
cui: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('Tu CUI/DPI es requerido'),
|
|
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) {
|
|
|
validationSchema: RegisterSchema,
|
|
validationSchema: RegisterSchema,
|
|
|
onSubmit: (values) => {
|
|
onSubmit: (values) => {
|
|
|
setOpen(true);
|
|
setOpen(true);
|
|
|
- // let url = 'http://204.48.25.93:8081/registro'
|
|
|
|
|
- // let url = 'http://psicoadmin.ditca.org:8081/registro'
|
|
|
|
|
- console.log(client)
|
|
|
|
|
- setClient({
|
|
|
|
|
- ...client, ...values
|
|
|
|
|
- })
|
|
|
|
|
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
|
|
+ let new_client = {
|
|
|
|
|
+ ...client, ...values
|
|
|
|
|
+ }
|
|
|
|
|
+ setClient(new_client)
|
|
|
|
|
+
|
|
|
|
|
+ let body = {
|
|
|
|
|
+ "nombre" : new_client.firstName,
|
|
|
|
|
+ "apelidos" : new_client.lastName,
|
|
|
|
|
+ "telefono" : new_client.telefono,
|
|
|
|
|
+ "direccio": new_client.direccion,
|
|
|
|
|
+ "fechacumple": new_client.nacimiento,
|
|
|
|
|
+ "nit": new_client.nit,
|
|
|
|
|
+ "cui": new_client.cui,
|
|
|
|
|
+ "email": new_client.email,
|
|
|
|
|
+ "username": new_client.email,
|
|
|
|
|
+ "pwd": new_client.password
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ let req = new Service('/registro');
|
|
|
|
|
+
|
|
|
|
|
+ req.post(body)
|
|
|
|
|
+ .then( data => {
|
|
|
|
|
+
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ setOpen(false);
|
|
|
|
|
+ return navigate('/')
|
|
|
|
|
+ }, 2000)
|
|
|
|
|
+
|
|
|
|
|
+ console.log("DATA ::", data)
|
|
|
let nombre = client.firstName + " " + client.lastName
|
|
let nombre = client.firstName + " " + client.lastName
|
|
|
toast.success(`Bienvenido ${nombre} !!`)
|
|
toast.success(`Bienvenido ${nombre} !!`)
|
|
|
- setOpen(false);
|
|
|
|
|
- }, 5000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(error => {
|
|
|
|
|
+ console.log("ERROR ::", error)
|
|
|
|
|
+ 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`)
|
|
|
|
|
+ return setOpen(false);
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|