2 Commits e4d95d798a ... 9c57628a31

Author SHA1 Message Date
  amenpunk 9c57628a31 edit plz 1 year ago
  amenpunk d292aafe56 fix puesto superior search 1 year ago

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

+ 256 - 28
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';
21
 import { Service } from '../../Utils/HTTP';
23
 import { Service } from '../../Utils/HTTP';
22
 import { useSelector } from 'react-redux'
24
 import { useSelector } from 'react-redux'
23
 import { useQuery, useMutation, useQueryClient } from 'react-query'
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
 const plazeSchema = Yup.object({
58
 const plazeSchema = Yup.object({
26
   id: Yup.number(),
59
   id: Yup.number(),
42
     resolver: yupResolver(plazeSchema),
75
     resolver: yupResolver(plazeSchema),
43
     defaultValues: {
76
     defaultValues: {
44
       nombrepuesto: 'mingtest',
77
       nombrepuesto: 'mingtest',
45
-      puestosuperior: 0,
78
+      puestosuperior: null,
46
       fecha: '01/01/2019',
79
       fecha: '01/01/2019',
47
       notas: 'esto es un ejemplod e una nota',
80
       notas: 'esto es un ejemplod e una nota',
48
       aredepto: 1,
81
       aredepto: 1,
81
   const [open, setOpen] = React.useState(false);
114
   const [open, setOpen] = React.useState(false);
82
   const [tab, setTab] = React.useState(0);
115
   const [tab, setTab] = React.useState(0);
83
   const [checklist, setChecklist] = React.useState([]);
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
   const addPrueba = (check, id) => {
178
   const addPrueba = (check, id) => {
90
     let tests = getValues("tests")
179
     let tests = getValues("tests")
115
   }
204
   }
116
 
205
 
117
   const puestoMutation = useMutation(updatePuesto)
206
   const puestoMutation = useMutation(updatePuesto)
118
-
119
   const close = () => toggle("EDIT", { id: null });
207
   const close = () => toggle("EDIT", { id: null });
120
 
208
 
121
   const { data: categories } = useQuery('categories', getCategories);
209
   const { data: categories } = useQuery('categories', getCategories);
122
   const { data: testsCatalog } = useQuery('tests', getTest);
210
   const { data: testsCatalog } = useQuery('tests', getTest);
123
 
211
 
124
   useEffect(() => {
212
   useEffect(() => {
213
+
125
     if (visible == null) return;
214
     if (visible == null) return;
126
     let rest = new Service(`/plaza/getthis/${visible}`)
215
     let rest = new Service(`/plaza/getthis/${visible}`)
127
     rest
216
     rest
128
       .getQuery(auth.token)
217
       .getQuery(auth.token)
129
       .then(response => {
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
         let temp_test = tests.map(t => ({ id: t.id }))
220
         let temp_test = tests.map(t => ({ id: t.id }))
133
         setChecklist(temp_test.map(t => t.id))
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
   const changeTab = (_event, newValue) => setTab(newValue);
261
   const changeTab = (_event, newValue) => setTab(newValue);
142
 
262
 
154
           <Tab label="Pruebas" />
274
           <Tab label="Pruebas" />
155
         </Tabs>
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
         <form onSubmit={handleSubmit(onSubmit)}>
326
         <form onSubmit={handleSubmit(onSubmit)}>
158
           <TabPanel value={tab} index={1}>
327
           <TabPanel value={tab} index={1}>
159
             <Stack spacing={1}>
328
             <Stack spacing={1}>
193
                   error={Boolean(errors?.nombrepuesto)}
362
                   error={Boolean(errors?.nombrepuesto)}
194
                   {...register("nombrepuesto")} />
363
                   {...register("nombrepuesto")} />
195
 
364
 
365
+
196
                 <FormControl fullWidth>
366
                 <FormControl fullWidth>
197
-                  <InputLabel id="demo-simple-select-label">Puesto Superior</InputLabel>
198
                   <Controller
367
                   <Controller
199
                     helperText={errors.puestosuperior?.message}
368
                     helperText={errors.puestosuperior?.message}
200
-                    error={Boolean(errors?.puestosuperior)}
369
+                    error={errors?.puestosuperior}
201
                     name="puestosuperior"
370
                     name="puestosuperior"
202
                     control={control}
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
                   </Controller>
445
                   </Controller>
219
                 </FormControl>
446
                 </FormControl>
447
+
220
               </Stack>
448
               </Stack>
221
 
449
 
222
               <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
450
               <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>

+ 1 - 1
src/Pages/Login.jsx

116
           sm={4}
116
           sm={4}
117
           md={7}
117
           md={7}
118
           sx={{
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
             backgroundRepeat: 'no-repeat',
120
             backgroundRepeat: 'no-repeat',
121
             backgroundColor: (t) => t.palette.mode === 'light' ? t.palette.grey[50] : t.palette.grey[900],
121
             backgroundColor: (t) => t.palette.mode === 'light' ? t.palette.grey[50] : t.palette.grey[900],
122
             backgroundSize: 'cover',
122
             backgroundSize: 'cover',

+ 2 - 5
src/Pages/Puestos.jsx

47
     cacheTime: 0,
47
     cacheTime: 0,
48
   });
48
   });
49
 
49
 
50
-
51
-console.log(isLoading,result, error)
52
-
53
   const changePage = useCallback((_, value) => setPage(value), []);
50
   const changePage = useCallback((_, value) => setPage(value), []);
54
   const [alignment, setAlignment] = React.useState('grid');
51
   const [alignment, setAlignment] = React.useState('grid');
55
   const handleChange = useCallback((_event, newAlignment) => setAlignment(newAlignment), [])
52
   const handleChange = useCallback((_event, newAlignment) => setAlignment(newAlignment), [])
139
                       index={page - 1}
136
                       index={page - 1}
140
                     /> : undefined
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
                 </Row>
140
                 </Row>
144
               </div>
141
               </div>
145
               <div className={`main_list_products ${alignment === 'list' ? 'activar_vista' : 'desactivar_vista'}`} id="list_view_products">
142
               <div className={`main_list_products ${alignment === 'list' ? 'activar_vista' : 'desactivar_vista'}`} id="list_view_products">
153
                       index={page - 1}
150
                       index={page - 1}
154
                     /> : undefined
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
                 </Row>
154
                 </Row>
158
               </div>
155
               </div>
159
 
156