|
@@ -1,7 +1,6 @@
|
1
|
1
|
import React, { memo } from 'react';
|
2
|
2
|
import * as Yup from 'yup';
|
3
|
3
|
import { useFormik, Form, FormikProvider } from 'formik';
|
4
|
|
-import { Dialog, DialogContent, DialogTitle, DialogActions } from '@mui/material'
|
5
|
4
|
import toast from 'react-hot-toast';
|
6
|
5
|
|
7
|
6
|
import { AdapterDateFns as DateFnsUtils } from '@mui/x-date-pickers/AdapterDateFns';
|
|
@@ -11,14 +10,50 @@ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
|
11
|
10
|
import {
|
12
|
11
|
Button, Stack, TextField, MenuItem, FormControl, InputLabel, Select,
|
13
|
12
|
Backdrop, CircularProgress, Box, Divider,
|
14
|
|
- Tabs, Tab, FormGroup, Checkbox, FormControlLabel
|
|
13
|
+ Tabs, Tab, FormGroup, Checkbox, FormControlLabel,
|
|
14
|
+ Dialog, DialogContent, DialogTitle, DialogActions,
|
|
15
|
+ DialogContentText,
|
15
|
16
|
} from '@mui/material';
|
16
|
17
|
|
|
18
|
+import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
|
|
19
|
+
|
17
|
20
|
import { Service } from '../../Utils/HTTP';
|
18
|
21
|
import { useQuery, useMutation, useQueryClient } from 'react-query';
|
19
|
22
|
import { TabPanel } from './TabPanel'
|
20
|
23
|
import { useSelector } from 'react-redux';
|
21
|
24
|
|
|
25
|
+const filter = createFilterOptions();
|
|
26
|
+
|
|
27
|
+async function getPuestoSuperior(puesto, auth) {
|
|
28
|
+ if (puesto.length < 2) return []
|
|
29
|
+ let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
|
|
30
|
+ let result = await rest.get(auth.token)
|
|
31
|
+ // console.log(result)
|
|
32
|
+ if (result?.data?.length > 0) {
|
|
33
|
+ result = result.data.map((item) => ({ 'title': item.nombre, id: item.id }))
|
|
34
|
+ return result;
|
|
35
|
+ }
|
|
36
|
+ return [];
|
|
37
|
+}
|
|
38
|
+
|
|
39
|
+async function savePuestoSuperior(input, auth) {
|
|
40
|
+ let rest = new Service("/plaza/puestosuperior")
|
|
41
|
+ let body = {
|
|
42
|
+ "active": 1,
|
|
43
|
+ "nombre": input.title,
|
|
44
|
+ "decription": input.id,
|
|
45
|
+ "modifyday": "2023-02-12T23:55:26.007",
|
|
46
|
+ "createday": "2023-02-12T23:55:26.007",
|
|
47
|
+ "id": null,
|
|
48
|
+ "descripction": input.id,
|
|
49
|
+ "modify_day": "2023-02-12T23:55:26.007",
|
|
50
|
+ }
|
|
51
|
+ let result = await rest.post(body, auth.token);
|
|
52
|
+ let { id, nombre } = result;
|
|
53
|
+ return { id, nombre }
|
|
54
|
+}
|
|
55
|
+
|
|
56
|
+
|
22
|
57
|
function Manual(props) {
|
23
|
58
|
|
24
|
59
|
const auth = useSelector((state) => state.token)
|
|
@@ -33,13 +68,14 @@ function Manual(props) {
|
33
|
68
|
return await rest.getQuery(auth.token)
|
34
|
69
|
}
|
35
|
70
|
|
|
71
|
+
|
36
|
72
|
const { data } = useQuery('categories', getCategories);
|
37
|
73
|
const { data: testsCatalog } = useQuery('tests', getTest);
|
38
|
74
|
const queryClient = useQueryClient();
|
39
|
75
|
|
40
|
76
|
const NewPlazaSchema = Yup.object().shape({
|
41
|
77
|
nombrepuesto: Yup.string().required('El nombre es requerido').min(5, "El nombre del puesto debe ser mayor a 5 caracteres").max(100),
|
42
|
|
- puestosuperior: Yup.number("El puesto superior debe ser un número").required("El puesto es requerido"),
|
|
78
|
+ puestosuperior: Yup.number().required("El puesto superior es requerido"),
|
43
|
79
|
aredepto: Yup.number().required('Escoge alguna área'),
|
44
|
80
|
fecha: Yup.date("Ingresa una fecha válida"),
|
45
|
81
|
notas: Yup.string("Ingresa una nota válida").min(5, "Ingresa una nota válida").max(150),
|
|
@@ -47,11 +83,47 @@ function Manual(props) {
|
47
|
83
|
})
|
48
|
84
|
|
49
|
85
|
const [departamento, setDepartamento] = React.useState('');
|
50
|
|
- const [puestoSup, setPuestoSup] = React.useState('');
|
51
|
86
|
const [open, setOpen] = React.useState(false);
|
52
|
87
|
const [date, setDate] = React.useState(new Date());
|
53
|
88
|
const [tab, setTab] = React.useState(0);
|
54
|
89
|
const [checklist, setChecklist] = React.useState([]);
|
|
90
|
+ const [openDialog, toggleOpenDialog] = React.useState(false);
|
|
91
|
+ const [openSugg, setOpenSugg] = React.useState(false);
|
|
92
|
+ const [options, setOptions] = React.useState([]);
|
|
93
|
+ const [dialogValue, setDialogValueHook] = React.useState({
|
|
94
|
+ title: '',
|
|
95
|
+ id: '',
|
|
96
|
+ });
|
|
97
|
+
|
|
98
|
+ let setDialogValue = (value) => {
|
|
99
|
+ // console.log('llamada', value)
|
|
100
|
+ // setValues({...values, puestosuperior: value?.title })
|
|
101
|
+ setDialogValueHook(value)
|
|
102
|
+ }
|
|
103
|
+
|
|
104
|
+ const loading = openSugg && options.length === 0;
|
|
105
|
+
|
|
106
|
+ React.useEffect(() => {
|
|
107
|
+
|
|
108
|
+ let active = true;
|
|
109
|
+ if (!loading) {
|
|
110
|
+ return undefined;
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ (async () => {
|
|
114
|
+ let puestos = await getPuestoSuperior(dialogValue.title, auth)
|
|
115
|
+ if (active) {
|
|
116
|
+ setOptions(puestos);
|
|
117
|
+ }
|
|
118
|
+ })();
|
|
119
|
+
|
|
120
|
+ return () => {
|
|
121
|
+ active = false;
|
|
122
|
+ };
|
|
123
|
+
|
|
124
|
+ }, [loading, dialogValue, auth]);
|
|
125
|
+
|
|
126
|
+
|
55
|
127
|
|
56
|
128
|
const handleClose = () => false
|
57
|
129
|
|
|
@@ -59,23 +131,69 @@ function Manual(props) {
|
59
|
131
|
setDepartamento(event.target.value);
|
60
|
132
|
};
|
61
|
133
|
|
62
|
|
- const changePuestoSup = (event) => {
|
63
|
|
- setPuestoSup(event.target.value);
|
|
134
|
+ const handleCloseDialog = () => {
|
|
135
|
+ setDialogValue({
|
|
136
|
+ title: '',
|
|
137
|
+ id: '',
|
|
138
|
+ });
|
|
139
|
+ toggleOpenDialog(false);
|
64
|
140
|
};
|
65
|
141
|
|
|
142
|
+
|
|
143
|
+ const handleSubmitDialog = async (event) => {
|
|
144
|
+ event.preventDefault();
|
|
145
|
+ console.log('to save: ', dialogValue)
|
|
146
|
+ let { id, nombre } = await savePuestoSuperior(dialogValue, auth)
|
|
147
|
+ if (id) {
|
|
148
|
+ setDialogValue({
|
|
149
|
+ title: nombre,
|
|
150
|
+ id: id,
|
|
151
|
+ });
|
|
152
|
+ }
|
|
153
|
+
|
|
154
|
+ setDialogValue({
|
|
155
|
+ title: dialogValue.title,
|
|
156
|
+ id: dialogValue.id
|
|
157
|
+ });
|
|
158
|
+ handleCloseDialog();
|
|
159
|
+ };
|
|
160
|
+
|
|
161
|
+ const AutoCompleteChange = (event, newValue) => {
|
|
162
|
+ console.log('newValue', newValue)
|
|
163
|
+ // TODO : formik logic to validate autocomplete
|
|
164
|
+ setValues({ ...values, puestosuperior: newValue?.id })
|
|
165
|
+
|
|
166
|
+ if (typeof newValue === 'string') {
|
|
167
|
+ setTimeout(() => {
|
|
168
|
+ toggleOpenDialog(true);
|
|
169
|
+ setDialogValue({
|
|
170
|
+ title: newValue,
|
|
171
|
+ id: '',
|
|
172
|
+ });
|
|
173
|
+ });
|
|
174
|
+ } else if (newValue && newValue.inputValue) {
|
|
175
|
+ toggleOpenDialog(true);
|
|
176
|
+ setDialogValue({
|
|
177
|
+ title: newValue.inputValue,
|
|
178
|
+ id: '',
|
|
179
|
+ });
|
|
180
|
+ } else {
|
|
181
|
+ setDialogValue(newValue);
|
|
182
|
+ }
|
|
183
|
+ }
|
|
184
|
+
|
66
|
185
|
const agregarPuesto = async (puesto) => {
|
67
|
186
|
let rest = new Service('/plaza/save');
|
68
|
187
|
return await rest.postQuery(puesto, auth.token);
|
69
|
188
|
}
|
70
|
189
|
|
71
|
190
|
const puestoMutation = useMutation(agregarPuesto)
|
72
|
|
-
|
73
|
191
|
let { visible, onClose } = props
|
74
|
192
|
|
75
|
193
|
const formik = useFormik({
|
76
|
194
|
initialValues: {
|
77
|
195
|
nombrepuesto: "",
|
78
|
|
- puestosuperior: 1,
|
|
196
|
+ puestosuperior: null,
|
79
|
197
|
aredepto: 1,
|
80
|
198
|
fecha: date,
|
81
|
199
|
notas: "",
|
|
@@ -83,17 +201,15 @@ function Manual(props) {
|
83
|
201
|
},
|
84
|
202
|
onSubmit: (fields, { resetForm }) => {
|
85
|
203
|
|
86
|
|
- if(fields.tests.length === 0){
|
|
204
|
+ if (fields.tests.length === 0) {
|
87
|
205
|
toast.error("Recuerda que seleccionar al menos un test")
|
88
|
206
|
setTab(1)
|
89
|
207
|
return
|
90
|
208
|
}
|
91
|
|
-
|
92
|
209
|
setOpen(true)
|
93
|
210
|
fields['fecha'] = new Date(fields.fecha).toISOString();
|
94
|
211
|
fields['areadeptoplz_id'] = 1;
|
95
|
212
|
fields['id'] = -1;
|
96
|
|
-
|
97
|
213
|
puestoMutation.mutate(fields, {
|
98
|
214
|
onSuccess: () => {
|
99
|
215
|
setOpen(false)
|
|
@@ -111,12 +227,10 @@ function Manual(props) {
|
111
|
227
|
validationSchema: NewPlazaSchema,
|
112
|
228
|
});
|
113
|
229
|
|
114
|
|
- const changeTab = (_event, newValue) => {
|
115
|
|
- setTab(newValue);
|
116
|
|
- };
|
117
|
|
-
|
|
230
|
+ const changeTab = (_event, newValue) => setTab(newValue);
|
118
|
231
|
|
119
|
232
|
const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
|
|
233
|
+ // console.log({ values })
|
120
|
234
|
|
121
|
235
|
const addPrueba = (check, id) => {
|
122
|
236
|
let { tests } = values
|
|
@@ -139,9 +253,9 @@ function Manual(props) {
|
139
|
253
|
aria-labelledby="contained-modal-title-vcenter"
|
140
|
254
|
onClose={onClose}>
|
141
|
255
|
|
142
|
|
- <DialogTitle>
|
|
256
|
+ <DialogTitle className="modal-title" style={{ color: '#252525' }}>
|
143
|
257
|
<button onClick={onClose} type="button" className="close" data-dismiss="modal">×</button>
|
144
|
|
- <h4 className="modal-title" style={{ color: '#252525' }}>Agregar Puesto</h4>
|
|
258
|
+ Agregar Puesto
|
145
|
259
|
</DialogTitle>
|
146
|
260
|
|
147
|
261
|
<DialogContent className="modal-body">
|
|
@@ -151,6 +265,54 @@ function Manual(props) {
|
151
|
265
|
<Tab label="Pruebas" />
|
152
|
266
|
</Tabs>
|
153
|
267
|
|
|
268
|
+ <Dialog open={openDialog} onClose={handleCloseDialog}>
|
|
269
|
+ <form onSubmit={handleSubmitDialog}>
|
|
270
|
+ <DialogTitle>Agrega un nuevo Puesto</DialogTitle>
|
|
271
|
+ <DialogContent>
|
|
272
|
+ <DialogContentText>
|
|
273
|
+ Agrega la descripcion del puesto
|
|
274
|
+ </DialogContentText>
|
|
275
|
+
|
|
276
|
+ <TextField
|
|
277
|
+ autoFocus
|
|
278
|
+ margin="dense"
|
|
279
|
+ id="name"
|
|
280
|
+ value={dialogValue?.title}
|
|
281
|
+ onChange={(event) =>
|
|
282
|
+ setDialogValue({
|
|
283
|
+ ...dialogValue,
|
|
284
|
+ title: event.target.value,
|
|
285
|
+ })
|
|
286
|
+ }
|
|
287
|
+ label="Puesto"
|
|
288
|
+ type="text"
|
|
289
|
+ variant="standard"
|
|
290
|
+ />
|
|
291
|
+
|
|
292
|
+ <TextField
|
|
293
|
+ margin="dense"
|
|
294
|
+ id="name"
|
|
295
|
+ value={dialogValue?.id}
|
|
296
|
+ onChange={(event) =>
|
|
297
|
+ setDialogValue({
|
|
298
|
+ ...dialogValue,
|
|
299
|
+ id: event.target.value,
|
|
300
|
+ })
|
|
301
|
+ }
|
|
302
|
+ label="Descripción"
|
|
303
|
+ type="text"
|
|
304
|
+ variant="standard"
|
|
305
|
+ />
|
|
306
|
+ </DialogContent>
|
|
307
|
+ <DialogActions>
|
|
308
|
+ <Button onClick={handleCloseDialog}>Cancelar</Button>
|
|
309
|
+ <Button type="submit">Agregar</Button>
|
|
310
|
+ </DialogActions>
|
|
311
|
+ </form>
|
|
312
|
+ </Dialog>
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
154
|
316
|
<FormikProvider style={{ paddingTop: 25 }} value={formik}>
|
155
|
317
|
<Form autoComplete="off" noValidate onSubmit={handleSubmit}>
|
156
|
318
|
|
|
@@ -185,7 +347,6 @@ function Manual(props) {
|
185
|
347
|
|
186
|
348
|
<Stack spacing={3}>
|
187
|
349
|
|
188
|
|
-
|
189
|
350
|
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={4}>
|
190
|
351
|
<TextField
|
191
|
352
|
label="Nombre"
|
|
@@ -196,24 +357,77 @@ function Manual(props) {
|
196
|
357
|
/>
|
197
|
358
|
|
198
|
359
|
<FormControl fullWidth>
|
199
|
|
- <InputLabel id="demo-simple-select-label">Puesto Superior</InputLabel>
|
200
|
|
- <Select
|
201
|
|
- labelId="demo-simple-select-label"
|
202
|
|
- value={puestoSup}
|
203
|
|
- label="Puesto Superior"
|
204
|
|
- onChange={changePuestoSup}
|
205
|
|
- {...getFieldProps('puestosuperior')}
|
206
|
|
- error={Boolean(touched.puestosuperior && errors.puestosuperior)} >
|
207
|
|
- {
|
208
|
|
- data ?
|
209
|
|
- data.data.map(cate => {
|
210
|
|
- return (
|
211
|
|
- <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
|
212
|
|
- )
|
213
|
|
- })
|
214
|
|
- : <MenuItem>Null</MenuItem>
|
215
|
|
- }
|
216
|
|
- </Select>
|
|
360
|
+
|
|
361
|
+ <Autocomplete
|
|
362
|
+ fullWidth
|
|
363
|
+ value={dialogValue}
|
|
364
|
+ onChange={AutoCompleteChange}
|
|
365
|
+ open={openSugg}
|
|
366
|
+ onOpen={() => {
|
|
367
|
+ setOpenSugg(true);
|
|
368
|
+ }}
|
|
369
|
+ onClose={() => {
|
|
370
|
+ setOpenSugg(false);
|
|
371
|
+ }}
|
|
372
|
+ isOptionEqualToValue={(option, value) => option.title === value.title}
|
|
373
|
+ filterOptions={(options, params) => {
|
|
374
|
+ const filtered = filter(options, params);
|
|
375
|
+
|
|
376
|
+ if (params.inputValue !== '') {
|
|
377
|
+ filtered.push({
|
|
378
|
+ inputValue: params.inputValue,
|
|
379
|
+ title: `Add "${params.inputValue}"`,
|
|
380
|
+ });
|
|
381
|
+ }
|
|
382
|
+
|
|
383
|
+ return filtered;
|
|
384
|
+ }}
|
|
385
|
+ id="puesto_superior_autocomplete"
|
|
386
|
+ options={options}
|
|
387
|
+ loading={loading}
|
|
388
|
+ getOptionLabel={(option) => {
|
|
389
|
+ if (typeof option === 'string') {
|
|
390
|
+ return option;
|
|
391
|
+ }
|
|
392
|
+ if (option.inputValue) {
|
|
393
|
+ return option.inputValue;
|
|
394
|
+ }
|
|
395
|
+ return option.title;
|
|
396
|
+ }}
|
|
397
|
+ selectOnFocus
|
|
398
|
+ clearOnBlur
|
|
399
|
+ handleHomeEndKeys
|
|
400
|
+ renderOption={(props, option) => <li {...props}>{option.title}</li>}
|
|
401
|
+ freeSolo
|
|
402
|
+ renderInput={(params) => (
|
|
403
|
+ <TextField
|
|
404
|
+ {...params}
|
|
405
|
+ {...getFieldProps('puestosuperior')}
|
|
406
|
+ error={Boolean(touched.puestosuperior && errors.puestosuperior)}
|
|
407
|
+ label="Puesto Superior"
|
|
408
|
+ InputProps={{
|
|
409
|
+ ...params.InputProps,
|
|
410
|
+ onChange: (event) => {
|
|
411
|
+ // let title = event.target.value;
|
|
412
|
+ // console.log('titulo',title)
|
|
413
|
+ setOptions([]);
|
|
414
|
+ setDialogValue({
|
|
415
|
+ title: event.target.value,
|
|
416
|
+ id: '',
|
|
417
|
+ });
|
|
418
|
+ },
|
|
419
|
+ endAdornment: (
|
|
420
|
+ <React.Fragment>
|
|
421
|
+ {loading ? <CircularProgress color="inherit" size={20} /> : null}
|
|
422
|
+ {params.InputProps.endAdornment}
|
|
423
|
+ </React.Fragment>
|
|
424
|
+ ),
|
|
425
|
+ }}
|
|
426
|
+ />
|
|
427
|
+ )}
|
|
428
|
+
|
|
429
|
+ />
|
|
430
|
+
|
217
|
431
|
</FormControl>
|
218
|
432
|
|
219
|
433
|
</Stack>
|