2 Achegas e4d95d798a ... 9c57628a31

Autor SHA1 Mensaxe Data
  amenpunk 9c57628a31 edit plz hai 1 ano
  amenpunk d292aafe56 fix puesto superior search hai 1 ano

+ 8 - 18
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,8 +95,9 @@ function Manual(props) {
96 95
   });
97 96
 
98 97
   let setDialogValue = (value) => {
99
-    // console.log('llamada', value)
100
-    // setValues({...values, puestosuperior: value?.title })
98
+    if (value?.id !== undefined && isNaN(value?.id) === false) {
99
+      setValues({ ...values, puestosuperior: value?.id })
100
+    }
101 101
     setDialogValueHook(value)
102 102
   }
103 103
 
@@ -132,34 +132,26 @@ function Manual(props) {
132 132
   };
133 133
 
134 134
   const handleCloseDialog = () => {
135
-    setDialogValue({
136
-      title: '',
137
-      id: '',
138
-    });
139 135
     toggleOpenDialog(false);
140 136
   };
141 137
 
142 138
 
143 139
   const handleSubmitDialog = async (event) => {
144 140
     event.preventDefault();
145
-    console.log('to save: ', dialogValue)
146 141
     let { id, nombre } = await savePuestoSuperior(dialogValue, auth)
147 142
     if (id) {
148
-      setDialogValue({
143
+      let to_set = {
149 144
         title: nombre,
150 145
         id: id,
151
-      });
146
+      }
147
+      if (to_set.id) {
148
+        setDialogValue(to_set);
149
+      }
152 150
     }
153
-
154
-    setDialogValue({
155
-      title: dialogValue.title,
156
-      id: dialogValue.id
157
-    });
158 151
     handleCloseDialog();
159 152
   };
160 153
 
161 154
   const AutoCompleteChange = (event, newValue) => {
162
-    console.log('newValue', newValue)
163 155
     setValues({ ...values, puestosuperior: newValue?.id })
164 156
 
165 157
     if (typeof newValue === 'string') {
@@ -229,7 +221,6 @@ function Manual(props) {
229 221
   const changeTab = (_event, newValue) => setTab(newValue);
230 222
 
231 223
   const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
232
-  // console.log({ values })
233 224
 
234 225
   const addPrueba = (check, id) => {
235 226
     let { tests } = values
@@ -408,7 +399,6 @@ function Manual(props) {
408 399
                             ...params.InputProps,
409 400
                             onChange: (event) => {
410 401
                               // let title = event.target.value;
411
-                              // console.log('titulo',title)
412 402
                               setOptions([]);
413 403
                               setDialogValue({
414 404
                                 title: event.target.value,

+ 256 - 28
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';
@@ -21,6 +23,37 @@ import toast, { Toaster } from 'react-hot-toast';
21 23
 import { Service } from '../../Utils/HTTP';
22 24
 import { useSelector } from 'react-redux'
23 25
 import { useQuery, useMutation, useQueryClient } from 'react-query'
26
+import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
27
+const filter = createFilterOptions();
28
+
29
+async function getPuestoSuperior(puesto, auth) {
30
+  if (puesto.length < 2) return []
31
+  let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
32
+  let result = await rest.get(auth.token)
33
+  if (result?.data?.length > 0) {
34
+    result = result.data.map((item) => ({ 'title': item.nombre, id: item.id }))
35
+    return result;
36
+  }
37
+  return [];
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
+
24 57
 
25 58
 const plazeSchema = Yup.object({
26 59
   id: Yup.number(),
@@ -42,7 +75,7 @@ function Edit(props) {
42 75
     resolver: yupResolver(plazeSchema),
43 76
     defaultValues: {
44 77
       nombrepuesto: 'mingtest',
45
-      puestosuperior: 0,
78
+      puestosuperior: null,
46 79
       fecha: '01/01/2019',
47 80
       notas: 'esto es un ejemplod e una nota',
48 81
       aredepto: 1,
@@ -81,10 +114,66 @@ function Edit(props) {
81 114
   const [open, setOpen] = React.useState(false);
82 115
   const [tab, setTab] = React.useState(0);
83 116
   const [checklist, setChecklist] = React.useState([]);
117
+  const [openSugg, setOpenSugg] = React.useState(false);
118
+  const [options, setOptions] = React.useState([]);
119
+  const [openDialog, toggleOpenDialog] = React.useState(false);
120
+  const [dialogValue, setDialogValueHook] = React.useState({
121
+    title: '',
122
+    id: '',
123
+  });
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
+  };
84 144
 
85
-  // const changePuestoSup = (event) => {
86
-  //   setPuestoSup(event.target.value);
87
-  // };
145
+  let setDialogValue = (value) => {
146
+    if (value?.id !== undefined && isNaN(value?.id) === false) {
147
+      // setValues({ ...values, puestosuperior: value?.id })
148
+      setValue('puestosuperior', value?.id)
149
+    }
150
+    setDialogValueHook(value)
151
+  }
152
+
153
+  const loading = openSugg && options.length === 0;
154
+
155
+  const AutoCompleteChange = (event, newValue) => {
156
+    console.log('newValue', newValue)
157
+    setValue('puestosuperior', newValue?.id)
158
+
159
+    if (typeof newValue === 'string') {
160
+      setTimeout(() => {
161
+        toggleOpenDialog(true);
162
+        setDialogValue({
163
+          title: newValue,
164
+          id: '',
165
+        });
166
+      });
167
+    } else if (newValue && newValue.inputValue) {
168
+      toggleOpenDialog(true);
169
+      setDialogValue({
170
+        title: newValue.inputValue,
171
+        id: '',
172
+      });
173
+    } else {
174
+      setDialogValue(newValue);
175
+    }
176
+  }
88 177
 
89 178
   const addPrueba = (check, id) => {
90 179
     let tests = getValues("tests")
@@ -115,28 +204,59 @@ function Edit(props) {
115 204
   }
116 205
 
117 206
   const puestoMutation = useMutation(updatePuesto)
118
-
119 207
   const close = () => toggle("EDIT", { id: null });
120 208
 
121 209
   const { data: categories } = useQuery('categories', getCategories);
122 210
   const { data: testsCatalog } = useQuery('tests', getTest);
123 211
 
124 212
   useEffect(() => {
213
+
125 214
     if (visible == null) return;
126 215
     let rest = new Service(`/plaza/getthis/${visible}`)
127 216
     rest
128 217
       .getQuery(auth.token)
129 218
       .then(response => {
130
-        console.log('puesto edit: ',response.data)
131
-        let { areadeptoplz_id, fecha, tests } = response.data;
219
+        let { areadeptoplz_id, fecha, tests, puestosuperior } = response.data;
132 220
         let temp_test = tests.map(t => ({ id: t.id }))
133 221
         setChecklist(temp_test.map(t => t.id))
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,
234
+          puestosuperior: puestosuperior.id
235
+        })
236
+        // setDialogValue({ title: puestosuperior.nombre, id: puestosuperior.id })
237
+      })
238
+      .catch(e => console.log(e))
134 239
 
135 240
 
136
-        reset({ ...response.data, aredepto: areadeptoplz_id, fecha: new Date(fecha), tests: temp_test })
137
-      })
138
-      .catch(console.log)
139
-  }, [visible, auth, reset])
241
+    let active = true;
242
+    if (!loading) {
243
+      return undefined;
244
+    }
245
+
246
+    (async () => {
247
+      let puestos = await getPuestoSuperior(dialogValue.title, auth)
248
+      if (active) {
249
+        setOptions(puestos);
250
+      }
251
+    })();
252
+
253
+    return () => {
254
+      active = false;
255
+    };
256
+
257
+
258
+
259
+  }, [visible, auth, reset, loading, dialogValue])
140 260
 
141 261
   const changeTab = (_event, newValue) => setTab(newValue);
142 262
 
@@ -154,6 +274,55 @@ function Edit(props) {
154 274
           <Tab label="Pruebas" />
155 275
         </Tabs>
156 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
+
157 326
         <form onSubmit={handleSubmit(onSubmit)}>
158 327
           <TabPanel value={tab} index={1}>
159 328
             <Stack spacing={1}>
@@ -193,30 +362,89 @@ function Edit(props) {
193 362
                   error={Boolean(errors?.nombrepuesto)}
194 363
                   {...register("nombrepuesto")} />
195 364
 
365
+
196 366
                 <FormControl fullWidth>
197
-                  <InputLabel id="demo-simple-select-label">Puesto Superior</InputLabel>
198 367
                   <Controller
199 368
                     helperText={errors.puestosuperior?.message}
200
-                    error={Boolean(errors?.puestosuperior)}
369
+                    error={errors?.puestosuperior}
201 370
                     name="puestosuperior"
202 371
                     control={control}
203
-                    render={({field}) => 
204
-                      <Select {...field}>
205
-                        {
206
-                          categories ?
207
-                            categories.data.map(cate => {
208
-                              return (
209
-                                <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
210
-                              )
211
-                            })
212
-                            : <MenuItem>Null</MenuItem>
213
-                        }
214
-                      </Select>
372
+                    render={({ field }) =>
373
+                      <Autocomplete
374
+                        fullWidth
375
+                        value={dialogValue}
376
+                        onChange={AutoCompleteChange}
377
+                        open={openSugg}
378
+                        onOpen={() => {
379
+                          setOpenSugg(true);
380
+                        }}
381
+                        onClose={() => {
382
+                          setOpenSugg(false);
383
+                        }}
384
+                        isOptionEqualToValue={(option, value) => option.title === value.title}
385
+                        filterOptions={(options, params) => {
386
+                          const filtered = filter(options, params);
387
+
388
+                          if (params.inputValue !== '') {
389
+                            filtered.push({
390
+                              inputValue: params.inputValue,
391
+                              title: `Add "${params.inputValue}"`,
392
+                            });
393
+                          }
394
+
395
+                          return filtered;
396
+                        }}
397
+                        id="puesto_superior_autocomplete"
398
+                        options={options}
399
+                        loading={loading}
400
+                        getOptionLabel={(option) => {
401
+                          if (typeof option === 'string') {
402
+                            return option;
403
+                          }
404
+                          if (option.inputValue) {
405
+                            return option.inputValue;
406
+                          }
407
+                          return option.title;
408
+                        }}
409
+                        selectOnFocus
410
+                        clearOnBlur
411
+                        handleHomeEndKeys
412
+                        renderOption={(props, option) => <li {...props}>{option.title}</li>}
413
+                        freeSolo
414
+                        renderInput={(params) => (
415
+                          <TextField
416
+                            {...params}
417
+                            {...register('puestosuperior')}
418
+                            error={Boolean(errors.puestosuperior)}
419
+                            label="Puesto Superior"
420
+                            InputProps={{
421
+                              ...params.InputProps,
422
+                              onChange: (event) => {
423
+                                // let title = event.target.value;
424
+                                // console.log('titulo',title)
425
+                                setOptions([]);
426
+                                setDialogValue({
427
+                                  title: event.target.value,
428
+                                  id: '',
429
+                                });
430
+                              },
431
+                              endAdornment: (
432
+                                <React.Fragment>
433
+                                  {loading ? <CircularProgress color="inherit" size={20} /> : null}
434
+                                  {params.InputProps.endAdornment}
435
+                                </React.Fragment>
436
+                              ),
437
+                            }}
438
+                          />
439
+                        )}
440
+
441
+                      />
442
+
215 443
                     }
216
-                    >
217
-                    
444
+                  >
218 445
                   </Controller>
219 446
                 </FormControl>
447
+
220 448
               </Stack>
221 449
 
222 450
               <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>

+ 1 - 1
src/Pages/Login.jsx

@@ -116,7 +116,7 @@ export function Login() {
116 116
           sm={4}
117 117
           md={7}
118 118
           sx={{
119
-            backgroundImage: 'url(https://source.unsplash.com/random)',
119
+            backgroundImage: 'url(https://images.squarespace-cdn.com/content/v1/5c0ec3e30dbda3392d9c9d2d/1548101170354-A2I9LZIEE5CLJ1V5ZGAG/Psychometrictesting.jpg?format=2500w)',
120 120
             backgroundRepeat: 'no-repeat',
121 121
             backgroundColor: (t) => t.palette.mode === 'light' ? t.palette.grey[50] : t.palette.grey[900],
122 122
             backgroundSize: 'cover',

+ 2 - 5
src/Pages/Puestos.jsx

@@ -47,9 +47,6 @@ export function Puestos() {
47 47
     cacheTime: 0,
48 48
   });
49 49
 
50
-
51
-console.log(isLoading,result, error)
52
-
53 50
   const changePage = useCallback((_, value) => setPage(value), []);
54 51
   const [alignment, setAlignment] = React.useState('grid');
55 52
   const handleChange = useCallback((_event, newAlignment) => setAlignment(newAlignment), [])
@@ -139,7 +136,7 @@ console.log(isLoading,result, error)
139 136
                       index={page - 1}
140 137
                     /> : undefined
141 138
                   }
142
-                  {!result && !isLoading && <center><h1>No tienes nigun puesto</h1></center>}
139
+                  {!result && !isLoading && <center><h1>No tienes ningún puesto</h1></center>}
143 140
                 </Row>
144 141
               </div>
145 142
               <div className={`main_list_products ${alignment === 'list' ? 'activar_vista' : 'desactivar_vista'}`} id="list_view_products">
@@ -153,7 +150,7 @@ console.log(isLoading,result, error)
153 150
                       index={page - 1}
154 151
                     /> : undefined
155 152
                   }
156
-                  {!result && !isLoading && <center><h1>No tienes nigun puesto</h1></center>}
153
+                  {!result && !isLoading && <center><h1>No tienes nigún puesto</h1></center>}
157 154
                 </Row>
158 155
               </div>
159 156