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

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

13
 import {
13
 import {
14
   Button, Stack, TextField, MenuItem, FormControl, InputLabel, Select,
14
   Button, Stack, TextField, MenuItem, FormControl, InputLabel, Select,
15
   Backdrop, CircularProgress,
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
 } from '@mui/material';
19
 } from '@mui/material';
18
 
20
 
19
 import toast, { Toaster } from 'react-hot-toast';
21
 import toast, { Toaster } from 'react-hot-toast';
28
   if (puesto.length < 2) return []
30
   if (puesto.length < 2) return []
29
   let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
31
   let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
30
   let result = await rest.get(auth.token)
32
   let result = await rest.get(auth.token)
31
-  // console.log(result)
32
   if (result?.data?.length > 0) {
33
   if (result?.data?.length > 0) {
33
     result = result.data.map((item) => ({ 'title': item.nombre, id: item.id }))
34
     result = result.data.map((item) => ({ 'title': item.nombre, id: item.id }))
34
     return result;
35
     return result;
36
   return [];
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
 const plazeSchema = Yup.object({
58
 const plazeSchema = Yup.object({
41
   id: Yup.number(),
59
   id: Yup.number(),
104
     id: '',
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
   let setDialogValue = (value) => {
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
     setDialogValueHook(value)
150
     setDialogValueHook(value)
111
   }
151
   }
112
 
152
 
179
         let { areadeptoplz_id, fecha, tests, puestosuperior } = response.data;
219
         let { areadeptoplz_id, fecha, tests, puestosuperior } = response.data;
180
         let temp_test = tests.map(t => ({ id: t.id }))
220
         let temp_test = tests.map(t => ({ id: t.id }))
181
         setChecklist(temp_test.map(t => t.id))
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
           puestosuperior: puestosuperior.id
234
           puestosuperior: puestosuperior.id
189
         })
235
         })
190
         // setDialogValue({ title: puestosuperior.nombre, id: puestosuperior.id })
236
         // setDialogValue({ title: puestosuperior.nombre, id: puestosuperior.id })
228
           <Tab label="Pruebas" />
274
           <Tab label="Pruebas" />
229
         </Tabs>
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
         <form onSubmit={handleSubmit(onSubmit)}>
326
         <form onSubmit={handleSubmit(onSubmit)}>
232
           <TabPanel value={tab} index={1}>
327
           <TabPanel value={tab} index={1}>
233
             <Stack spacing={1}>
328
             <Stack spacing={1}>
350
                   </Controller>
445
                   </Controller>
351
                 </FormControl>
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
               </Stack>
448
               </Stack>
383
 
449
 
384
               <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
450
               <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>