Browse Source

fix in service consum

amenpunk 2 years ago
parent
commit
491318b980
3 changed files with 90 additions and 47 deletions
  1. 77 31
      src/Components/Modal/AgregarManual.js
  2. 2 1
      src/Components/Register/PersonalInfo.js
  3. 11 15
      src/Utils/HTTP.js

+ 77 - 31
src/Components/Modal/AgregarManual.js

@@ -3,36 +3,56 @@ import * as Yup from 'yup';
3 3
 import { useFormik, Form, FormikProvider } from 'formik';
4 4
 import { Modal } from 'react-bootstrap'
5 5
 
6
-import {  
7
-    Box, Button,
8
-    Stack, TextField, 
9
-    InputLabel,MenuItem,FormControl,Select
10
-} from '@mui/material';
6
+import DateFnsUtils from '@date-io/date-fns';
7
+import { DesktopDatePicker,LocalizationProvider } from '@mui/lab';
8
+import {  Button, Stack, TextField, } from '@mui/material';
11 9
 
10
+import { Service } from '../../Utils/HTTP';
11
+import  useAuth from '../../Auth/useAuth';
12 12
 
13 13
 
14 14
 export default function Manual ( props ) {
15 15
 
16 16
     const NewPlazaSchema = Yup.object().shape({
17 17
         nombrepuesto : Yup.string().required('El nombre es requerido').min(5).max(100),
18
-        puestosuperior : Yup.number("El puesto superior debe ser un numero"),
19
-        areadepto : Yup.number().required('Escoge alguna area'),
20
-        fecha : Yup.date("Ingresa una fecha válida").required('Ingresa una fecha válida'),
21
-        notas : Yup.string().required('Ingresa una fecha válida'),
18
+        puestosuperior : Yup.number("El puesto superior debe ser un número"),
19
+        aredepto : Yup.number().required('Escoge alguna área'),
20
+        fecha : Yup.date("Ingresa una fecha válida"),
21
+        notas : Yup.string("Ingresa una nota válida").min(5).max(150),
22 22
     })
23 23
 
24
+    const [date, setDate] = React.useState(new Date());
25
+    const auth = useAuth();
26
+    const token = auth.getToken();
27
+
24 28
     let { visible, onClose, success } = props
25 29
 
26 30
     const formik = useFormik({
27 31
         initialValues: {
28
-            nombrepuesto: "",
29
-            puestosuperior: "",
30
-            areadepto: "",
31
-            fecha: "",
32
-            notas: "",
32
+            nombrepuesto: "QA ENGINIER",
33
+            puestosuperior: 3,
34
+            aredepto: 1,
35
+            fecha: date,
36
+            notas: "alguna nota ",
33 37
         },
34 38
         onSubmit: (fields) => {
35
-            console.log(fields)
39
+            fields['fecha'] = "2023-06-11T00:22:15.211"//new Date(fields.fecha).toString() //getDate(fields.fecha);
40
+            fields['areadeptoplz_id'] = 1;
41
+            fields['id'] = -1;
42
+
43
+            console.log(fields);
44
+
45
+            let Rest = new Service('/plaza/save');
46
+
47
+            Rest
48
+            .post( fields, token )
49
+            .then(data => {
50
+                console.log('data ', data)
51
+            })
52
+            .catch(err => {
53
+                console.error(err)
54
+            })
55
+
36 56
         },
37 57
         validationSchema: NewPlazaSchema,
38 58
     });
@@ -54,7 +74,7 @@ export default function Manual ( props ) {
54 74
                             <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
55 75
 
56 76
                                 <TextField
57
-                                    label="Nombre: "
77
+                                    label="Nombre"
58 78
                                     fullWidth
59 79
                                     {...getFieldProps('nombrepuesto')}
60 80
                                     error={Boolean(touched.nombrepuesto && errors.nombrepuesto)}
@@ -62,7 +82,7 @@ export default function Manual ( props ) {
62 82
                                 />
63 83
 
64 84
                                 <TextField
65
-                                    label="Puesto Superior: "
85
+                                    label="Puesto Superior"
66 86
                                     fullWidth
67 87
                                     {...getFieldProps('puestosuperior')}
68 88
                                     error={Boolean(touched.puestosuperior && errors.puestosuperior)}
@@ -75,19 +95,32 @@ export default function Manual ( props ) {
75 95
                                     label="Departamento"
76 96
                                     fullWidth
77 97
                                     type="text"
78
-                                    {...getFieldProps('puestosuperior')}
79
-                                    error={Boolean(touched.areadepto && errors.areadepto)}
80
-                                    helperText={touched.areadepto && errors.areadepto}
81
-                                />
82
-                                <TextField
83
-                                    label="Fecha Creacion"
84
-                                    fullWidth
85
-                                    type="text"
86
-                                    {...getFieldProps('fecha')}
87
-                                    error={Boolean(touched.fecha && errors.fecha)}
88
-                                    helperText={touched.fecha && errors.fecha}
98
+                                    {...getFieldProps('aredepto')}
99
+                                    error={Boolean(touched.aredepto && errors.aredepto)}
100
+                                    helperText={touched.aredepto && errors.aredepto}
89 101
                                 />
102
+                                
103
+                                <LocalizationProvider 
104
+                                    dateAdapter={DateFnsUtils}>
105
+                                    <DesktopDatePicker
106
+                                        label="Fecha Creación"
107
+                                        fullWidth
108
+                                        inputFormat="dd/MM/yyyy"
109
+                                        {...getFieldProps('fecha')}
110
+                                        value={date}
111
+                                        onChange={setDate}
112
+                                        renderInput={(params) => 
113
+                                            <TextField 
114
+                                                disabled={true}
115
+                                                label="Fecha Creación"
116
+                                                fullWidth
117
+                                                {...params} 
118
+                                            />}
119
+                                    />
120
+                                </LocalizationProvider>
121
+
90 122
                             </Stack>
123
+
91 124
                             <Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>
92 125
                                 <TextField
93 126
                                     id="filled-multiline-static"
@@ -95,19 +128,32 @@ export default function Manual ( props ) {
95 128
                                     rows={4}
96 129
                                     defaultValue="Default Value"
97 130
                                     variant="filled"
98
-                                    label="notas"
131
+                                    label="Notas"
99 132
                                     fullWidth
100 133
                                     type="text"
101 134
                                     {...getFieldProps('notas')}
102 135
                                     error={Boolean(touched.notas && errors.notas)}
103 136
                                     helperText={touched.notas && errors.notas}
104
-                                />
137
+                                    />
105 138
                             </Stack>
106 139
                         </Stack>
140
+
141
+
142
+                        <Modal.Footer>
143
+                            <Button
144
+                                type="submit"
145
+                                className="registerBtn" 
146
+                                variant="contained"
147
+                                sx={{ mt: 1, mr: 1 }}
148
+                            >
149
+                                {'Guardar'}
150
+                            </Button>
151
+                        </Modal.Footer>
152
+
107 153
                     </Form>
108 154
                 </FormikProvider>
109 155
 
110
-                <Modal.Footer>OK</Modal.Footer>
156
+
111 157
 
112 158
             </Modal.Body>
113 159
         </Modal>

+ 2 - 1
src/Components/Register/PersonalInfo.js

@@ -60,7 +60,8 @@ export function PersonalInfo(props) {
60 60
 
61 61
             let req =  new Service('/registro');
62 62
 
63
-            req.post(body)
63
+            req
64
+            .post(body)
64 65
             .then( data => {
65 66
 
66 67
                 setTimeout(() => {

+ 11 - 15
src/Utils/HTTP.js

@@ -44,35 +44,31 @@ export class Service {
44 44
     async post(body, token){
45 45
 
46 46
         if(!token){
47
-            let response = await fetch(this.url, {
47
+            let response = await axios({
48 48
                 method: "POST",
49
+                url: this.url,
49 50
                 headers:{
50 51
                     'Content-Type': 'application/json',
51 52
                 },
52
-                body : JSON.stringify(body)
53
+                data :body
53 54
             })
54
-            return await response.json(); 
55
+            return await response.data; 
55 56
         }
56 57
 
57 58
 
58 59
         const MyHeaders ={
59
-            'Content-Type': 'application/json',
60
-            'Authorization': 'Bearer '+ token
60
+            'Authorization': 'Bearer '+ token,
61 61
         }
62 62
         
63
-        console.log('MY TOKEN ::', token)
64
-        console.log('MY URL ::', this.url)
65
-        console.log('MY HEADER ::', MyHeaders)
66
-
67
-        let response = await fetch(this.url, {
68
-            credentials: 'include',
63
+        let response = await axios({
69 64
             method: "POST",
70
-            mode: 'cors',
71
-            cache: 'default',
65
+            url : this.url,
72 66
             headers: MyHeaders,
73
-            body : JSON.stringify(body)
67
+            data: body
74 68
         })
75
-        return await response.json(); 
69
+        console.log('response', response)
70
+
71
+        return await response.data; 
76 72
 
77 73
     }
78 74