Browse Source

fix puestos getall

amenpunk 2 years ago
parent
commit
6fce1f3829
3 changed files with 32 additions and 22 deletions
  1. 8 9
      src/Components/Modal/AgregarManual.js
  2. 9 11
      src/Components/Modal/EditPlaza.js
  3. 15 2
      src/Pages/Puestos.jsx

+ 8 - 9
src/Components/Modal/AgregarManual.js

@@ -14,8 +14,6 @@ import {
14 14
 import { Service } from '../../Utils/HTTP';
15 15
 import  useAuth from '../../Auth/useAuth';
16 16
 
17
-import { departamentos } from '../Password/Rows'
18
-
19 17
 
20 18
 export default function Manual ( props ) {
21 19
 
@@ -40,7 +38,7 @@ export default function Manual ( props ) {
40 38
     const auth = useAuth();
41 39
     const token = auth.getToken();
42 40
 
43
-    let { visible, onClose, Complete } = props
41
+    let { visible, onClose, Complete, categorias  } = props
44 42
 
45 43
     const formik = useFormik({
46 44
         initialValues: {
@@ -122,12 +120,13 @@ export default function Manual ( props ) {
122 120
                                         {...getFieldProps('aredepto')}
123 121
                                         error={Boolean(touched.aredepto && errors.aredepto)} >
124 122
                                         {
125
-                                        departamentos.map( ( nivel, index ) => {
126
-                                            index = index + 1;
127
-                                            return (
128
-                                                <MenuItem key={nivel} value={index}>{nivel}</MenuItem>
129
-                                            )
130
-                                        })
123
+                                        categorias ?
124
+                                            categorias.map( cate => {
125
+                                                return (
126
+                                                    <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
127
+                                                )
128
+                                            })
129
+                                            : <MenuItem>Null</MenuItem>
131 130
                                     }
132 131
                                     </Select>
133 132
                                 </FormControl>

+ 9 - 11
src/Components/Modal/EditPlaza.js

@@ -14,8 +14,6 @@ import {
14 14
 import { Service } from '../../Utils/HTTP';
15 15
 import  useAuth from '../../Auth/useAuth';
16 16
 
17
-import { departamentos } from '../Password/Rows'
18
-
19 17
 export default function Edit(props) {
20 18
 
21 19
     const NewPlazaSchema = Yup.object().shape({
@@ -43,7 +41,7 @@ export default function Edit(props) {
43 41
     const auth = useAuth();
44 42
     const token = auth.getToken();
45 43
 
46
-    let {onClose, puesto : { data }, Complete, visible  } = props
44
+    let {onClose, puesto : { data }, Complete, visible, categorias  } = props
47 45
     
48 46
     const formik = useFormik({
49 47
         initialValues: {
@@ -55,7 +53,6 @@ export default function Edit(props) {
55 53
             notas:data? data.notas :"",
56 54
         },
57 55
         onSubmit: ( fields, { resetForm } ) => {
58
-            console.log('pre update',fields)
59 56
             setOpen(true)
60 57
             fields['fecha'] =  new Date(fields.fecha).toISOString();
61 58
 
@@ -81,7 +78,6 @@ export default function Edit(props) {
81 78
     const { errors, touched, handleSubmit, getFieldProps, setValues} = formik;
82 79
     
83 80
     useEffect(() => {
84
-        console.log(data); 
85 81
         setValues({
86 82
             id: data? data.id:"",
87 83
             nombrepuesto: data? data.nombrepuesto:"",
@@ -137,12 +133,14 @@ export default function Edit(props) {
137 133
                                         {...getFieldProps('aredepto')}
138 134
                                         error={Boolean(touched.aredepto && errors.aredepto)} >
139 135
                                         {
140
-                                        departamentos.map( ( nivel, index ) => {
141
-                                            return (
142
-                                                <MenuItem key={index} value={index}>{nivel}</MenuItem>
143
-                                            )
144
-                                        })
145
-                                    }
136
+                                        categorias ?
137
+                                            categorias.map( cate => {
138
+                                                return (
139
+                                                    <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
140
+                                                )
141
+                                            })
142
+                                            : <MenuItem>Null</MenuItem>
143
+                                        }
146 144
                                     </Select>
147 145
                                 </FormControl>
148 146
 

+ 15 - 2
src/Pages/Puestos.jsx

@@ -58,8 +58,11 @@ export function Puestos() {
58 58
     } 
59 59
 
60 60
     const auth = useAuth();
61
+
61 62
     const [data, setData] = useState([]);
62 63
     const [page, setPage] = useState(1);
64
+    const [categorias, setCategorias] = useState([]);
65
+
63 66
     const token = auth.getToken();
64 67
 
65 68
     const changePage = ( _ , value) => setPage(value);
@@ -84,6 +87,16 @@ export function Puestos() {
84 87
             .catch((error) => {
85 88
                 console.log('error fetching data  ', error );
86 89
             })
90
+    
91
+        rest = new Service("/categoria/getAll")
92
+        rest
93
+            .get(token)
94
+            .then(({data}) => {
95
+                setCategorias(data)
96
+            })
97
+            .catch((error) => {
98
+                console.log('error fetching data  ', error );
99
+            })
87 100
 
88 101
 
89 102
     },[token])
@@ -194,9 +207,9 @@ export function Puestos() {
194 207
             </div>
195 208
 
196 209
             <Express setExpress={setExpress} visible={expres} onClose={() => setExpress(false) } />
197
-            <Manual Complete={Complete} visible={manual} onClose={() => setManual(false)}/>
210
+            <Manual categorias={categorias} Complete={Complete} visible={manual} onClose={() => setManual(false)}/>
198 211
 
199
-            <Editar  Complete={Complete} puesto={puesto} visible={edit} onClose={() => setEdit(false)} />
212
+            <Editar categorias={categorias} Complete={Complete} puesto={puesto} visible={edit} onClose={() => setEdit(false)} />
200 213
             <Eliminar puesto={puesto} visible={del} onClose={() => setDelete(false)} />
201 214
             <Mostrar  puesto={puesto} visible={show} onClose={() => setShow(false)} />
202 215