|
@@ -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}>
|