amenpunk 1 год назад
Родитель
Сommit
9c57628a31
2 измененных файлов с 107 добавлено и 62 удалено
  1. 2 23
      src/Components/Modal/AgregarManual.js
  2. 105 39
      src/Components/Modal/EditPlaza.js

+ 2 - 23
src/Components/Modal/AgregarManual.js

@@ -28,7 +28,6 @@ async function getPuestoSuperior(puesto, auth) {
28 28
   if (puesto.length < 2) return []
29 29
   let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
30 30
   let result = await rest.get(auth.token)
31
-  // console.log(result)
32 31
   if (result?.data?.length > 0) {
33 32
     result = result.data.map((item) => ({ 'title': item.nombre, id: item.id }))
34 33
     return result;
@@ -96,9 +95,8 @@ function Manual(props) {
96 95
   });
97 96
 
98 97
   let setDialogValue = (value) => {
99
-  console.log("DIALGO RECE:", value)
100
-    if(value?.id !== undefined && isNaN(value?.id) === false ){
101
-      setValues({...values, puestosuperior: value?.id })
98
+    if (value?.id !== undefined && isNaN(value?.id) === false) {
99
+      setValues({ ...values, puestosuperior: value?.id })
102 100
     }
103 101
     setDialogValueHook(value)
104 102
   }
@@ -134,45 +132,29 @@ function Manual(props) {
134 132
   };
135 133
 
136 134
   const handleCloseDialog = () => {
137
-    // setDialogValue({
138
-    //   title: '',
139
-    //   id: '',
140
-    // });
141 135
     toggleOpenDialog(false);
142 136
   };
143 137
 
144 138
 
145 139
   const handleSubmitDialog = async (event) => {
146 140
     event.preventDefault();
147
-    console.log('to save: ', dialogValue)
148 141
     let { id, nombre } = await savePuestoSuperior(dialogValue, auth)
149
-    console.log('nuevo puesto superior: ', id, nombre)
150 142
     if (id) {
151 143
       let to_set = {
152 144
         title: nombre,
153 145
         id: id,
154 146
       }
155
-      console.log('have id and set', to_set)
156
-      console.table(to_set)
157 147
       if (to_set.id) {
158 148
         setDialogValue(to_set);
159 149
       }
160 150
     }
161
-
162
-    // setDialogValue({
163
-    //   title: dialogValue.title,
164
-    //   id: dialogValue.id
165
-    // });
166
-console.log(values)
167 151
     handleCloseDialog();
168 152
   };
169 153
 
170 154
   const AutoCompleteChange = (event, newValue) => {
171
-    console.log('newValue', newValue)
172 155
     setValues({ ...values, puestosuperior: newValue?.id })
173 156
 
174 157
     if (typeof newValue === 'string') {
175
-      console.log('if')
176 158
       setTimeout(() => {
177 159
         toggleOpenDialog(true);
178 160
         setDialogValue({
@@ -181,14 +163,12 @@ console.log(values)
181 163
         });
182 164
       });
183 165
     } else if (newValue && newValue.inputValue) {
184
-      console.log('else if')
185 166
       toggleOpenDialog(true);
186 167
       setDialogValue({
187 168
         title: newValue.inputValue,
188 169
         id: '',
189 170
       });
190 171
     } else {
191
-      console.log('only else')
192 172
       setDialogValue(newValue);
193 173
     }
194 174
   }
@@ -419,7 +399,6 @@ console.log(values)
419 399
                             ...params.InputProps,
420 400
                             onChange: (event) => {
421 401
                               // let title = event.target.value;
422
-                              // console.log('titulo',title)
423 402
                               setOptions([]);
424 403
                               setDialogValue({
425 404
                                 title: event.target.value,

+ 105 - 39
src/Components/Modal/EditPlaza.js

@@ -13,7 +13,9 @@ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
13 13
 import {
14 14
   Button, Stack, TextField, MenuItem, FormControl, InputLabel, Select,
15 15
   Backdrop, CircularProgress,
16
-  Tabs, Tab, Box, Divider, FormGroup, FormControlLabel, Checkbox
16
+  Tabs, Tab, Box, Divider, FormGroup, FormControlLabel, Checkbox,
17
+  Dialog, DialogContent, DialogTitle, DialogActions,
18
+  DialogContentText,
17 19
 } from '@mui/material';
18 20
 
19 21
 import toast, { Toaster } from 'react-hot-toast';
@@ -28,7 +30,6 @@ async function getPuestoSuperior(puesto, auth) {
28 30
   if (puesto.length < 2) return []
29 31
   let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
30 32
   let result = await rest.get(auth.token)
31
-  // console.log(result)
32 33
   if (result?.data?.length > 0) {
33 34
     result = result.data.map((item) => ({ 'title': item.nombre, id: item.id }))
34 35
     return result;
@@ -36,6 +37,23 @@ async function getPuestoSuperior(puesto, auth) {
36 37
   return [];
37 38
 }
38 39
 
40
+async function savePuestoSuperior(input, auth) {
41
+  let rest = new Service("/plaza/puestosuperior")
42
+  let body = {
43
+    "active": 1,
44
+    "nombre": input.title,
45
+    "decription": input.id,
46
+    "modifyday": "2023-02-12T23:55:26.007",
47
+    "createday": "2023-02-12T23:55:26.007",
48
+    "id": null,
49
+    "descripction": input.id,
50
+    "modify_day": "2023-02-12T23:55:26.007",
51
+  }
52
+  let result = await rest.post(body, auth.token);
53
+  let { id, nombre } = result;
54
+  return { id, nombre }
55
+}
56
+
39 57
 
40 58
 const plazeSchema = Yup.object({
41 59
   id: Yup.number(),
@@ -104,9 +122,31 @@ function Edit(props) {
104 122
     id: '',
105 123
   });
106 124
 
125
+
126
+  const handleCloseDialog = () => {
127
+    toggleOpenDialog(false);
128
+  };
129
+
130
+  const handleSubmitDialog = async (event) => {
131
+    event.preventDefault();
132
+    let { id, nombre } = await savePuestoSuperior(dialogValue, auth)
133
+    if (id) {
134
+      let to_set = {
135
+        title: nombre,
136
+        id: id,
137
+      }
138
+      if (to_set.id) {
139
+        setDialogValue(to_set);
140
+      }
141
+    }
142
+    handleCloseDialog();
143
+  };
144
+
107 145
   let setDialogValue = (value) => {
108
-    // console.log('llamada', value)
109
-    // setValues({...values, puestosuperior: value?.title })
146
+    if (value?.id !== undefined && isNaN(value?.id) === false) {
147
+      // setValues({ ...values, puestosuperior: value?.id })
148
+      setValue('puestosuperior', value?.id)
149
+    }
110 150
     setDialogValueHook(value)
111 151
   }
112 152
 
@@ -179,12 +219,18 @@ function Edit(props) {
179 219
         let { areadeptoplz_id, fecha, tests, puestosuperior } = response.data;
180 220
         let temp_test = tests.map(t => ({ id: t.id }))
181 221
         setChecklist(temp_test.map(t => t.id))
182
-        console.log('puesto sup',puestosuperior)
183
-        reset({ 
184
-          ...response.data, 
185
-          aredepto: areadeptoplz_id, 
186
-          fecha: new Date(fecha), 
187
-          tests: temp_test, 
222
+        console.log('puesto sup', puestosuperior)
223
+
224
+        let temp_puesto = {
225
+          title: puestosuperior.nombre,
226
+          id: puestosuperior.id
227
+        }
228
+        // setDialogValue(temp_puesto)
229
+        reset({
230
+          ...response.data,
231
+          aredepto: areadeptoplz_id,
232
+          fecha: new Date(fecha),
233
+          tests: temp_test,
188 234
           puestosuperior: puestosuperior.id
189 235
         })
190 236
         // setDialogValue({ title: puestosuperior.nombre, id: puestosuperior.id })
@@ -228,6 +274,55 @@ function Edit(props) {
228 274
           <Tab label="Pruebas" />
229 275
         </Tabs>
230 276
 
277
+        <Dialog open={openDialog} onClose={handleCloseDialog}>
278
+          <form onSubmit={handleSubmitDialog}>
279
+            <DialogTitle>Agrega un nuevo Puesto</DialogTitle>
280
+            <DialogContent>
281
+              <DialogContentText>
282
+                Agrega la descripcion del puesto
283
+              </DialogContentText>
284
+
285
+              <TextField
286
+                autoFocus
287
+                margin="dense"
288
+                id="name"
289
+                value={dialogValue?.title}
290
+                onChange={(event) =>
291
+                  setDialogValue({
292
+                    ...dialogValue,
293
+                    title: event.target.value,
294
+                  })
295
+                }
296
+                label="Puesto"
297
+                type="text"
298
+                variant="standard"
299
+              />
300
+
301
+              <TextField
302
+                margin="dense"
303
+                id="name"
304
+                value={dialogValue?.id}
305
+                onChange={(event) =>
306
+                  setDialogValue({
307
+                    ...dialogValue,
308
+                    id: event.target.value,
309
+                  })
310
+                }
311
+                label="Descripción"
312
+                type="text"
313
+                variant="standard"
314
+              />
315
+            </DialogContent>
316
+            <DialogActions>
317
+              <Button onClick={handleCloseDialog}>Cancelar</Button>
318
+              <Button type="submit">Agregar</Button>
319
+            </DialogActions>
320
+          </form>
321
+        </Dialog>
322
+
323
+
324
+
325
+
231 326
         <form onSubmit={handleSubmit(onSubmit)}>
232 327
           <TabPanel value={tab} index={1}>
233 328
             <Stack spacing={1}>
@@ -350,35 +445,6 @@ function Edit(props) {
350 445
                   </Controller>
351 446
                 </FormControl>
352 447
 
353
-
354
-                {
355
-                  /* <FormControl fullWidth>
356
-                  <InputLabel id="demo-simple-select-label">Puesto Superior</InputLabel>
357
-                  <Controller
358
-                    helperText={errors.puestosuperior?.message}
359
-                    error={Boolean(errors?.puestosuperior)}
360
-                    name="puestosuperior"
361
-                    control={control}
362
-                  render={({field}) => 
363
-                    <Select {...field}>
364
-                      {
365
-                        categories ?
366
-                          categories.data.map(cate => {
367
-                            return (
368
-                              <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
369
-                            )
370
-                      })
371
-                      : <MenuItem>Null</MenuItem>
372
-                      }
373
-                        </Select>
374
-                    }
375
-                  >
376
-
377
-                    </Controller>
378
-                  </FormControl> */
379
-                }
380
-
381
-
382 448
               </Stack>
383 449
 
384 450
               <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>