ソースを参照

consum register service

amenpunk 3 年 前
コミット
e7fbcffe49
共有3 個のファイルを変更した53 個の追加16 個の削除を含む
  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 @@
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
     });

+ 5 - 5
src/Pages/Home.jsx

@@ -1,5 +1,5 @@
1 1
 import { Col, Row } from 'react-bootstrap'
2
-import React, { useEffect } from 'react'
2
+import React, { } from 'react'
3 3
 
4 4
 import { PersonOutline, VerifiedUser, ListAlt  } from '@mui/icons-material/'
5 5
 
@@ -7,14 +7,13 @@ import Actividades from '../Components/Home/Actividades'
7 7
 import Candidatos from '../Components/Home/Candidatos'
8 8
 import { Card } from '../Components/Card';
9 9
 
10
-import useAuth from '../Auth/useAuth';
11
-import { Service } from '../Utils/HTTP.js';
10
+// import useAuth from '../Auth/useAuth';
11
+// import { Service } from '../Utils/HTTP.js';
12 12
 
13 13
 export function Home() {
14 14
 
15
+    /*
15 16
     let auth = useAuth();
16
-    
17
-
18 17
     useEffect(() => {
19 18
         let token = auth.getToken();
20 19
         let myService = new Service("/persona/view");
@@ -25,6 +24,7 @@ export function Home() {
25 24
             console.log('Error Response :: ', e)
26 25
         })
27 26
     } ,[])
27
+*/
28 28
 
29 29
     return (
30 30
         <section >

+ 3 - 0
src/Utils/HTTP.js

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