Procházet zdrojové kódy

consum register service

amenpunk před 4 roky
rodič
revize
e7fbcffe49
3 změnil soubory, kde provedl 53 přidání a 16 odebrání
  1. 45 11
      src/Components/Register/PersonalInfo.js
  2. 5 5
      src/Pages/Home.jsx
  3. 3 0
      src/Utils/HTTP.js

+ 45 - 11
src/Components/Register/PersonalInfo.js

@@ -1,15 +1,22 @@
 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,
 } from '@mui/material';
 import toast, { Toaster } from 'react-hot-toast';
 import * as Yup from 'yup';
 
+import { Service } from '../../Utils/HTTP';
+// import useAuth from '../../Auth/useAuth';;
+
 export function PersonalInfo(props) {
 
     let { handleBack, setClient, client } = props
 
+    let navigate = useNavigate()
+
     const RegisterSchema = Yup.object().shape({
         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'),
@@ -31,20 +38,47 @@ export function PersonalInfo(props) {
         validationSchema: RegisterSchema,
         onSubmit: (values) => {
             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
                 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);
+            })
 
         }
     });

+ 5 - 5
src/Pages/Home.jsx

@@ -1,5 +1,5 @@
 import { Col, Row } from 'react-bootstrap'
-import React, { useEffect } from 'react'
+import React, { } from 'react'
 
 import { PersonOutline, VerifiedUser, ListAlt  } from '@mui/icons-material/'
 
@@ -7,14 +7,13 @@ import Actividades from '../Components/Home/Actividades'
 import Candidatos from '../Components/Home/Candidatos'
 import { Card } from '../Components/Card';
 
-import useAuth from '../Auth/useAuth';
-import { Service } from '../Utils/HTTP.js';
+// import useAuth from '../Auth/useAuth';
+// import { Service } from '../Utils/HTTP.js';
 
 export function Home() {
 
+    /*
     let auth = useAuth();
-    
-
     useEffect(() => {
         let token = auth.getToken();
         let myService = new Service("/persona/view");
@@ -25,6 +24,7 @@ export function Home() {
             console.log('Error Response :: ', e)
         })
     } ,[])
+*/
 
     return (
         <section >

+ 3 - 0
src/Utils/HTTP.js

@@ -46,6 +46,9 @@ export class Service {
         if(!token){
             let response = await fetch(this.url, {
                 method: "POST",
+                headers:{
+                    'Content-Type': 'application/json',
+                },
                 body : JSON.stringify(body)
             })
             return await response.json();