|
@@ -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';
|
|
@@ -28,7 +30,6 @@ async function getPuestoSuperior(puesto, auth) {
|
28
|
30
|
if (puesto.length < 2) return []
|
29
|
31
|
let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
|
30
|
32
|
let result = await rest.get(auth.token)
|
31
|
|
- // console.log(result)
|
32
|
33
|
if (result?.data?.length > 0) {
|
33
|
34
|
result = result.data.map((item) => ({ 'title': item.nombre, id: item.id }))
|
34
|
35
|
return result;
|
|
@@ -36,6 +37,23 @@ async function getPuestoSuperior(puesto, auth) {
|
36
|
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
|
58
|
const plazeSchema = Yup.object({
|
41
|
59
|
id: Yup.number(),
|
|
@@ -104,9 +122,31 @@ function Edit(props) {
|
104
|
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
|
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
|
150
|
setDialogValueHook(value)
|
111
|
151
|
}
|
112
|
152
|
|
|
@@ -179,12 +219,18 @@ function Edit(props) {
|
179
|
219
|
let { areadeptoplz_id, fecha, tests, puestosuperior } = response.data;
|
180
|
220
|
let temp_test = tests.map(t => ({ id: t.id }))
|
181
|
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
|
234
|
puestosuperior: puestosuperior.id
|
189
|
235
|
})
|
190
|
236
|
// setDialogValue({ title: puestosuperior.nombre, id: puestosuperior.id })
|
|
@@ -228,6 +274,55 @@ function Edit(props) {
|
228
|
274
|
<Tab label="Pruebas" />
|
229
|
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
|
326
|
<form onSubmit={handleSubmit(onSubmit)}>
|
232
|
327
|
<TabPanel value={tab} index={1}>
|
233
|
328
|
<Stack spacing={1}>
|
|
@@ -350,35 +445,6 @@ function Edit(props) {
|
350
|
445
|
</Controller>
|
351
|
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
|
448
|
</Stack>
|
383
|
449
|
|
384
|
450
|
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
|