|
@@ -1,324 +1,54 @@
|
1
|
|
-import React, { memo, useCallback, useMemo, useEffect } from 'react';
|
2
|
|
-import * as Yup from 'yup';
|
3
|
|
-// import { useFormik, Form, FormikProvider } from 'formik';
|
4
|
|
-import { Modal } from 'react-bootstrap'
|
5
|
|
-import toast, { Toaster } from 'react-hot-toast';
|
6
|
|
-import { useForm, Controller } from "react-hook-form";
|
7
|
|
-
|
8
|
|
-import DateFnsUtils from '@date-io/date-fns';
|
9
|
|
-import { DesktopDatePicker, LocalizationProvider } from '@mui/lab';
|
10
|
|
-import { TabPanel } from './TabPanel'
|
11
|
|
-
|
12
|
|
-import {
|
13
|
|
- Button, Stack, TextField, MenuItem, FormControl, InputLabel, Select,
|
14
|
|
- Backdrop, CircularProgress,
|
15
|
|
- Tabs,Tab,Box, Divider,FormGroup,FormControlLabel,Checkbox
|
16
|
|
-} from '@mui/material';
|
17
|
|
-
|
18
|
|
-import { Service } from '../../Utils/HTTP';
|
19
|
|
-import { useSelector } from 'react-redux'
|
20
|
|
-import { useQuery, useMutation, useQueryClient } from 'react-query'
|
21
|
|
-
|
22
|
|
-const NewPlazaSchema = Yup.object().shape({
|
23
|
|
- id: Yup.number(),
|
24
|
|
- nombrepuesto:
|
25
|
|
- Yup.string().required('El nombre es requerido')
|
26
|
|
- .min(5, "El nombre del puesto debe ser mayor a 5 caracteres")
|
27
|
|
- .max(100),
|
28
|
|
- puestosuperior: Yup.number("El puesto superior debe ser un número").required("El puesto es requerido"),
|
29
|
|
- aredepto: Yup.number().required('Escoge alguna área'),
|
30
|
|
- fecha: Yup.date("Ingresa una fecha válida"),
|
31
|
|
- notas: Yup.string("Ingresa una nota válida").min(5).max(150),
|
32
|
|
- tests: Yup.array()
|
33
|
|
-})
|
34
|
|
-
|
35
|
|
-
|
36
|
|
-
|
37
|
|
-function Edit(props) {
|
38
|
|
-
|
39
|
|
- const { getValues ,control,register, handleSubmit, watch, formState: { errors } } = useForm({
|
40
|
|
- defaultValues: {
|
41
|
|
- departamento: 1,
|
42
|
|
- }
|
43
|
|
- });
|
44
|
|
-
|
45
|
|
- console.log(errors)
|
46
|
|
-
|
47
|
|
- const onSubmit = data => console.log(data);
|
48
|
|
- console.log(watch("departamento")); // watch input value by passing the name of it
|
49
|
|
- //
|
50
|
|
- const now = useMemo(() => new Date(), [])
|
51
|
|
- const auth = useSelector((state) => state.token)
|
52
|
|
- const queryClient = useQueryClient()
|
53
|
|
- let { visible, toggle } = props
|
54
|
|
-
|
55
|
|
- // const [departamento, setDepartamento] = React.useState('');
|
56
|
|
- const [open, setOpen] = React.useState(false);
|
57
|
|
-
|
58
|
|
- // const changeDepartamento = useCallback((event) => {
|
59
|
|
- // setDepartamento(event.target.value);
|
60
|
|
- // }, []);
|
61
|
|
-
|
62
|
|
- const [date, setDate] = React.useState(now);
|
63
|
|
- const [tab, setTab] = React.useState(0);
|
64
|
|
- const [checklist, setChecklist] = React.useState([]);
|
65
|
|
-
|
66
|
|
- const addPrueba = (check,id) => {
|
67
|
|
- let { tests } = getValues("tests")
|
68
|
|
- console.log(tests);
|
69
|
|
- let temp ;
|
70
|
|
- if(check){
|
71
|
|
- temp = [...tests, {id}]
|
72
|
|
- }else{
|
73
|
|
- temp = tests.filter( test => test.id !== id);
|
74
|
|
- }
|
75
|
|
- setChecklist(temp.map( test => test.id) )
|
76
|
|
- // setValues({...values, tests: temp})
|
77
|
|
- };
|
78
|
|
-
|
79
|
|
- const getCategories = async () => {
|
80
|
|
- let rest = new Service("/categoria/getAll")
|
81
|
|
- return await rest.getQuery(auth.token)
|
82
|
|
- }
|
83
|
|
-
|
84
|
|
- const updatePuesto = async (fields) => {
|
85
|
|
- let rest = new Service('/plaza/edit');
|
86
|
|
- return rest.putQuery(fields, auth.token)
|
87
|
|
- }
|
88
|
|
-
|
89
|
|
- const getTest = async () => {
|
90
|
|
- let rest = new Service("/tests/getAll")
|
91
|
|
- return await rest.getQuery(auth.token)
|
92
|
|
- }
|
93
|
|
-
|
94
|
|
- const puestoMutation = useMutation(updatePuesto)
|
95
|
|
-
|
96
|
|
- const close = () => toggle("EDIT", {id : null});
|
97
|
|
-
|
98
|
|
- const { data: categories } = useQuery('categories', getCategories);
|
99
|
|
- const { data: testsCatalog } = useQuery('tests', getTest);
|
100
|
|
- /*
|
101
|
|
- const formik = useFormik({
|
102
|
|
- initialValues: {
|
103
|
|
- id: 1,
|
104
|
|
- nombrepuesto: "",
|
105
|
|
- puestosuperior: 1,
|
106
|
|
- aredepto: 1,
|
107
|
|
- fecha: now,
|
108
|
|
- notas: "",
|
109
|
|
- tests : []
|
110
|
|
- },
|
111
|
|
- onSubmit: (fields, { resetForm }) => {
|
112
|
|
- setOpen(true);
|
113
|
|
- fields['fecha'] = new Date(fields.fecha).toISOString();
|
114
|
|
-
|
115
|
|
- puestoMutation.mutate(fields, {
|
116
|
|
- onSuccess: () => {
|
117
|
|
- close();
|
118
|
|
- setOpen(false)
|
119
|
|
- toast.success("Puesto Actualizado!!")
|
120
|
|
- queryClient.invalidateQueries('puestos')
|
121
|
|
- },
|
122
|
|
- onError:() => {
|
123
|
|
- close();
|
124
|
|
- setOpen(false)
|
125
|
|
- toast.error("Lo sentimos ocurrió error inténtalo más tarde")
|
126
|
|
- }
|
127
|
|
- })
|
128
|
|
-
|
129
|
|
- resetForm();
|
130
|
|
- },
|
131
|
|
- validationSchema: NewPlazaSchema,
|
132
|
|
- });
|
133
|
|
-*/
|
134
|
|
-
|
135
|
|
- // const { errors, touched, handleSubmit, getFieldProps, setValues, values } = formik;
|
136
|
|
-
|
137
|
|
- useEffect(() => {
|
138
|
|
- console.info('use effect edit', props)
|
139
|
|
- },[props])
|
140
|
|
-
|
141
|
|
- // useEffect(() => {
|
142
|
|
- // if (puesto) {
|
143
|
|
- // setValues({
|
144
|
|
- // id: puesto.id,
|
145
|
|
- // nombrepuesto: puesto.nombrepuesto,
|
146
|
|
- // puestosuperior: puesto.puestosuperior,
|
147
|
|
- // aredepto: puesto.areadeptoplz_id,
|
148
|
|
- // fecha: new Date(puesto.create_day),
|
149
|
|
- // notas: puesto.notas,
|
150
|
|
- // tests : puesto.tests
|
151
|
|
- // })
|
152
|
|
- // setChecklist(puesto.tests.map(( {id} ) => id))
|
153
|
|
- // }
|
154
|
|
- // }, [puesto, now, setValues])
|
|
1
|
+import * as React from 'react';
|
|
2
|
+import Table from '@mui/material/Table';
|
|
3
|
+import TableBody from '@mui/material/TableBody';
|
|
4
|
+import TableCell from '@mui/material/TableCell';
|
|
5
|
+import TableContainer from '@mui/material/TableContainer';
|
|
6
|
+import TableHead from '@mui/material/TableHead';
|
|
7
|
+import TableRow from '@mui/material/TableRow';
|
|
8
|
+import Paper from '@mui/material/Paper';
|
|
9
|
+
|
|
10
|
+function createData(name, calories, fat, carbs, protein) {
|
|
11
|
+ return { name, calories, fat, carbs, protein };
|
|
12
|
+}
|
155
|
13
|
|
156
|
|
- const changeTab = (_event, newValue) => {
|
157
|
|
- setTab(newValue);
|
158
|
|
- };
|
|
14
|
+const rows = [
|
|
15
|
+ createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
|
|
16
|
+ createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
|
|
17
|
+ createData('Eclair', 262, 16.0, 24, 6.0),
|
|
18
|
+ createData('Cupcake', 305, 3.7, 67, 4.3),
|
|
19
|
+ createData('Gingerbread', 356, 16.0, 49, 3.9),
|
|
20
|
+];
|
159
|
21
|
|
|
22
|
+export default function DenseTable() {
|
160
|
23
|
return (
|
161
|
|
-
|
162
|
|
- <Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered show={visible} onHide={close}>
|
163
|
|
- <Modal.Header>
|
164
|
|
- <button onClick={close} type="button" className="close" data-dismiss="modal">×</button>
|
165
|
|
- <h4 className="modal-title" style={{ color: '#252525' }}>Editar puesto</h4>
|
166
|
|
- </Modal.Header>
|
167
|
|
- <Modal.Body className="modal-body">
|
168
|
|
-
|
169
|
|
- <Tabs value={tab} onChange={changeTab} aria-label="basic tabs example">
|
170
|
|
- <Tab label="Información" />
|
171
|
|
- <Tab label="Pruebas" />
|
172
|
|
- </Tabs>
|
173
|
|
-
|
174
|
|
- <form onSubmit={handleSubmit(onSubmit)}>
|
175
|
|
- <TabPanel value={tab} index={1}>
|
176
|
|
- <Stack spacing={1}>
|
177
|
|
-<Box style={{ paddingTop :5, paddingLeft :15 }}>
|
178
|
|
- <Divider/>
|
179
|
|
- <h4 style={{paddingTop :10, paddingBottom:10}}>Seleciona los test a realizar</h4>
|
180
|
|
- <Divider/>
|
181
|
|
- <FormGroup>
|
182
|
|
- {
|
183
|
|
- testsCatalog ?
|
184
|
|
- testsCatalog.data.map( test => (
|
185
|
|
- <FormControlLabel
|
186
|
|
- key={test.id}
|
187
|
|
- control={
|
188
|
|
- <Checkbox
|
189
|
|
- checked={checklist.includes((test.id))}
|
190
|
|
- onChange={(event)=> addPrueba(event.target.checked,test.id)}
|
191
|
|
- />
|
192
|
|
- }
|
193
|
|
- label={test.nombre}
|
194
|
|
- />
|
195
|
|
- )): null
|
196
|
|
- }
|
197
|
|
- </FormGroup>
|
198
|
|
- </Box>
|
199
|
|
- </Stack>
|
200
|
|
- </TabPanel>
|
201
|
|
-
|
202
|
|
-
|
203
|
|
- <TabPanel value={tab} index={0} >
|
204
|
|
- <Stack spacing={3}>
|
205
|
|
-
|
206
|
|
- <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
|
207
|
|
-
|
208
|
|
- <TextField
|
209
|
|
- label="Nombre"
|
210
|
|
- fullWidth
|
211
|
|
- {...register("nombre")}
|
212
|
|
- // {...getFieldProps('nombrepuesto')}
|
213
|
|
- // error={Boolean(touched.nombrepuesto && errors.nombrepuesto)}
|
214
|
|
- // helperText={touched.nombrepuesto && errors.nombrepuesto}
|
215
|
|
- />
|
216
|
|
-
|
217
|
|
- <TextField
|
218
|
|
- label="Puesto Superior"
|
219
|
|
- fullWidth
|
220
|
|
- {...register("puesto_superior")}
|
221
|
|
- //{...getFieldProps('puestosuperior')}
|
222
|
|
- //error={Boolean(touched.puestosuperior && errors.puestosuperior)}
|
223
|
|
- //helperText={touched.puestosuperior && errors.puestosuperior}
|
224
|
|
- />
|
225
|
|
-
|
226
|
|
- </Stack>
|
227
|
|
- <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
|
228
|
|
- <FormControl fullWidth>
|
229
|
|
- <InputLabel id="demo-simple-select-label">Departamento</InputLabel>
|
230
|
|
- <Select
|
231
|
|
- {...register("departamento")}
|
232
|
|
- labelId="departamento"
|
233
|
|
- id="departamento"
|
234
|
|
- label="Departamento"
|
235
|
|
- name={"departamento"}
|
236
|
|
- constrol={control}
|
237
|
|
- value={1}
|
238
|
|
- //value={departamento}
|
239
|
|
- //{...getFieldProps('puestosuperior')}
|
240
|
|
- // onChange={changeDepartamento}
|
241
|
|
- // {...getFieldProps('aredepto')}
|
242
|
|
- // error={Boolean(touched.aredepto && errors.aredepto)}
|
243
|
|
- >
|
244
|
|
- {
|
245
|
|
- categories ?
|
246
|
|
- categories.data.map(cate => {
|
247
|
|
- return (
|
248
|
|
- <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
|
249
|
|
- )
|
250
|
|
- })
|
251
|
|
- : <MenuItem value={1}>hola</MenuItem>
|
252
|
|
- }
|
253
|
|
- </Select>
|
254
|
|
- </FormControl>
|
255
|
|
-
|
256
|
|
-
|
257
|
|
- <LocalizationProvider
|
258
|
|
- dateAdapter={DateFnsUtils}>
|
259
|
|
- <DesktopDatePicker
|
260
|
|
- label="Fecha Creación"
|
261
|
|
- fullWidth
|
262
|
|
- inputFormat="dd/MM/yyyy"
|
263
|
|
- // {...getFieldProps('fecha')}
|
264
|
|
- {...register("fecha")}
|
265
|
|
- value={date}
|
266
|
|
- onChange={setDate}
|
267
|
|
- renderInput={(params) =>
|
268
|
|
- <TextField
|
269
|
|
- disabled={true}
|
270
|
|
- label="Fecha Creación"
|
271
|
|
- fullWidth
|
272
|
|
- {...params}
|
273
|
|
- />}
|
274
|
|
- />
|
275
|
|
- </LocalizationProvider>
|
276
|
|
-
|
277
|
|
- </Stack>
|
278
|
|
-
|
279
|
|
- <Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>
|
280
|
|
- <TextField
|
281
|
|
- id="filled-multiline-static"
|
282
|
|
- multiline
|
283
|
|
- rows={4}
|
284
|
|
- variant="filled"
|
285
|
|
- label="Notas"
|
286
|
|
- fullWidth
|
287
|
|
- type="text"
|
288
|
|
- {...register("notas")}
|
289
|
|
- // {...getFieldProps('notas')}
|
290
|
|
- // error={Boolean(touched.notas && errors.notas)}
|
291
|
|
- // helperText={touched.notas && errors.notas}
|
292
|
|
- />
|
293
|
|
- </Stack>
|
294
|
|
- </Stack>
|
295
|
|
- </TabPanel>
|
296
|
|
-
|
297
|
|
-
|
298
|
|
- <Modal.Footer>
|
299
|
|
- <Button
|
300
|
|
- type="submit"
|
301
|
|
- className="registerBtn"
|
302
|
|
- variant="contained"
|
303
|
|
- sx={{ mt: 1, mr: 1 }} >
|
304
|
|
- {'Actualizar'}
|
305
|
|
- </Button>
|
306
|
|
- </Modal.Footer>
|
307
|
|
-
|
308
|
|
- </form>
|
309
|
|
-
|
310
|
|
- </Modal.Body>
|
311
|
|
- <Backdrop
|
312
|
|
- sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
|
313
|
|
- open={open}
|
314
|
|
- onClick={() => console.log('backdrop')} >
|
315
|
|
- <CircularProgress color="inherit" />
|
316
|
|
- </Backdrop>
|
317
|
|
- <Toaster position="top-right" />
|
318
|
|
-
|
319
|
|
- </Modal>
|
320
|
|
- )
|
|
24
|
+ <TableContainer component={Paper}>
|
|
25
|
+ <Table sx={{ minWidth: 650 }} size="small" aria-label="a dense table">
|
|
26
|
+ <TableHead>
|
|
27
|
+ <TableRow>
|
|
28
|
+ <TableCell>Dessert (100g serving)</TableCell>
|
|
29
|
+ <TableCell align="right">Calories</TableCell>
|
|
30
|
+ <TableCell align="right">Fat (g)</TableCell>
|
|
31
|
+ <TableCell align="right">Carbs (g)</TableCell>
|
|
32
|
+ <TableCell align="right">Protein (g)</TableCell>
|
|
33
|
+ </TableRow>
|
|
34
|
+ </TableHead>
|
|
35
|
+ <TableBody>
|
|
36
|
+ {rows.map((row) => (
|
|
37
|
+ <TableRow
|
|
38
|
+ key={row.name}
|
|
39
|
+ sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
|
|
40
|
+ >
|
|
41
|
+ <TableCell component="th" scope="row">
|
|
42
|
+ {row.name}
|
|
43
|
+ </TableCell>
|
|
44
|
+ <TableCell align="right">{row.calories}</TableCell>
|
|
45
|
+ <TableCell align="right">{row.fat}</TableCell>
|
|
46
|
+ <TableCell align="right">{row.carbs}</TableCell>
|
|
47
|
+ <TableCell align="right">{row.protein}</TableCell>
|
|
48
|
+ </TableRow>
|
|
49
|
+ ))}
|
|
50
|
+ </TableBody>
|
|
51
|
+ </Table>
|
|
52
|
+ </TableContainer>
|
|
53
|
+ );
|
321
|
54
|
}
|
322
|
|
-
|
323
|
|
-
|
324
|
|
-export default memo(Edit);
|