|
@@ -6,10 +6,12 @@ import toast, { Toaster } from 'react-hot-toast';
|
6
|
6
|
|
7
|
7
|
import DateFnsUtils from '@date-io/date-fns';
|
8
|
8
|
import { DesktopDatePicker, LocalizationProvider } from '@mui/lab';
|
|
9
|
+import { TabPanel } from './TabPanel'
|
9
|
10
|
|
10
|
11
|
import {
|
11
|
12
|
Button, Stack, TextField, MenuItem, FormControl, InputLabel, Select,
|
12
|
|
- Backdrop, CircularProgress
|
|
13
|
+ Backdrop, CircularProgress,
|
|
14
|
+ Tabs,Tab,Box, Divider,FormGroup,FormControlLabel,Checkbox
|
13
|
15
|
} from '@mui/material';
|
14
|
16
|
|
15
|
17
|
import { Service } from '../../Utils/HTTP';
|
|
@@ -26,6 +28,7 @@ const NewPlazaSchema = Yup.object().shape({
|
26
|
28
|
aredepto: Yup.number().required('Escoge alguna área'),
|
27
|
29
|
fecha: Yup.date("Ingresa una fecha válida"),
|
28
|
30
|
notas: Yup.string("Ingresa una nota válida").min(5).max(150),
|
|
31
|
+ pruebas: Yup.array()
|
29
|
32
|
})
|
30
|
33
|
|
31
|
34
|
|
|
@@ -46,6 +49,21 @@ function Edit(props) {
|
46
|
49
|
}, []);
|
47
|
50
|
|
48
|
51
|
const [date, setDate] = React.useState(now);
|
|
52
|
+ const [tab, setTab] = React.useState(0);
|
|
53
|
+ const [checklist, setChecklist] = React.useState([]);
|
|
54
|
+
|
|
55
|
+ const addPrueba = (check,id) => {
|
|
56
|
+ let { pruebas } = values
|
|
57
|
+ console.log(pruebas)
|
|
58
|
+ let temp ;
|
|
59
|
+ if(check){
|
|
60
|
+ temp = [...pruebas, {id}]
|
|
61
|
+ }else{
|
|
62
|
+ temp = pruebas.filter( test => test.id !== id);
|
|
63
|
+ }
|
|
64
|
+ setChecklist(temp.map( test => test.id) )
|
|
65
|
+ setValues({...values, pruebas: temp})
|
|
66
|
+ };
|
49
|
67
|
|
50
|
68
|
const getCategories = async () => {
|
51
|
69
|
let rest = new Service("/categoria/getAll")
|
|
@@ -56,13 +74,18 @@ function Edit(props) {
|
56
|
74
|
let rest = new Service('/plaza/edit');
|
57
|
75
|
return rest.putQuery(fields, token)
|
58
|
76
|
}
|
|
77
|
+
|
|
78
|
+ const getTest = async () => {
|
|
79
|
+ let rest = new Service("/tests/getAll")
|
|
80
|
+ return await rest.getQuery(token)
|
|
81
|
+ }
|
59
|
82
|
|
60
|
83
|
const puestoMutation = useMutation(updatePuesto)
|
61
|
84
|
|
62
|
85
|
const close = () => toggle("EDIT");
|
63
|
86
|
|
64
|
87
|
const { data } = useQuery('categories', getCategories);
|
65
|
|
-
|
|
88
|
+ const { data: tests } = useQuery('tests', getTest);
|
66
|
89
|
|
67
|
90
|
const formik = useFormik({
|
68
|
91
|
initialValues: {
|
|
@@ -71,7 +94,8 @@ function Edit(props) {
|
71
|
94
|
puestosuperior: 1,
|
72
|
95
|
aredepto: 1,
|
73
|
96
|
fecha: now,
|
74
|
|
- notas: ""
|
|
97
|
+ notas: "",
|
|
98
|
+ pruebas : []
|
75
|
99
|
},
|
76
|
100
|
onSubmit: (fields, { resetForm }) => {
|
77
|
101
|
setOpen(true);
|
|
@@ -96,7 +120,7 @@ function Edit(props) {
|
96
|
120
|
validationSchema: NewPlazaSchema,
|
97
|
121
|
});
|
98
|
122
|
|
99
|
|
- const { errors, touched, handleSubmit, getFieldProps, setValues } = formik;
|
|
123
|
+ const { errors, touched, handleSubmit, getFieldProps, setValues, values } = formik;
|
100
|
124
|
|
101
|
125
|
useEffect(() => {
|
102
|
126
|
console.log("PUESTO :: ", puesto)
|
|
@@ -107,11 +131,17 @@ function Edit(props) {
|
107
|
131
|
puestosuperior: puesto.puestosuperior,
|
108
|
132
|
aredepto: puesto.areadeptoplz_id,
|
109
|
133
|
fecha: new Date(puesto.create_day),
|
110
|
|
- notas: puesto.notas
|
|
134
|
+ notas: puesto.notas,
|
|
135
|
+ pruebas : puesto.tests
|
111
|
136
|
})
|
|
137
|
+ setChecklist(puesto.tests.map(( {id} ) => id))
|
112
|
138
|
}
|
113
|
139
|
}, [puesto, now, setValues])
|
114
|
140
|
|
|
141
|
+ const changeTab = (_event, newValue) => {
|
|
142
|
+ setTab(newValue);
|
|
143
|
+ };
|
|
144
|
+
|
115
|
145
|
return (
|
116
|
146
|
|
117
|
147
|
<Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered show={visible} onHide={close}>
|
|
@@ -121,8 +151,44 @@ function Edit(props) {
|
121
|
151
|
</Modal.Header>
|
122
|
152
|
<Modal.Body className="modal-body">
|
123
|
153
|
|
|
154
|
+ <Tabs value={tab} onChange={changeTab} aria-label="basic tabs example">
|
|
155
|
+ <Tab label="Información" />
|
|
156
|
+ <Tab label="Pruebas" />
|
|
157
|
+ </Tabs>
|
|
158
|
+
|
124
|
159
|
<FormikProvider style={{ padding: 25 }} value={formik}>
|
125
|
160
|
<Form autoComplete="off" noValidate onSubmit={handleSubmit}>
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+ <TabPanel value={tab} index={1}>
|
|
164
|
+ <Stack spacing={1}>
|
|
165
|
+ <Box style={{ paddingTop :5, paddingLeft :15 }}>
|
|
166
|
+ <Divider/>
|
|
167
|
+ <h4 style={{paddingTop :10, paddingBottom:10}}>Seleciona los test a realizar</h4>
|
|
168
|
+ <Divider/>
|
|
169
|
+ <FormGroup>
|
|
170
|
+ {
|
|
171
|
+ tests ?
|
|
172
|
+ tests.data.map( test => (
|
|
173
|
+ <FormControlLabel
|
|
174
|
+ key={test.id}
|
|
175
|
+ control={
|
|
176
|
+ <Checkbox
|
|
177
|
+ checked={checklist.includes((test.id))}
|
|
178
|
+ onChange={(event)=> addPrueba(event.target.checked,test.id)}
|
|
179
|
+ />
|
|
180
|
+ }
|
|
181
|
+ label={test.nombre}
|
|
182
|
+ />
|
|
183
|
+ )): null
|
|
184
|
+ }
|
|
185
|
+ </FormGroup>
|
|
186
|
+ </Box>
|
|
187
|
+ </Stack>
|
|
188
|
+ </TabPanel>
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+ <TabPanel value={tab} index={0} >
|
126
|
192
|
<Stack spacing={3}>
|
127
|
193
|
|
128
|
194
|
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
|
|
@@ -204,6 +270,7 @@ function Edit(props) {
|
204
|
270
|
/>
|
205
|
271
|
</Stack>
|
206
|
272
|
</Stack>
|
|
273
|
+ </TabPanel>
|
207
|
274
|
|
208
|
275
|
|
209
|
276
|
<Modal.Footer>
|