|
@@ -11,7 +11,7 @@ import { TabPanel } from './TabPanel'
|
11
|
11
|
import {
|
12
|
12
|
Button, Stack, TextField, MenuItem, FormControl, InputLabel, Select,
|
13
|
13
|
Backdrop, CircularProgress,
|
14
|
|
- Tabs,Tab,Box, Divider,FormGroup,FormControlLabel,Checkbox
|
|
14
|
+ Tabs, Tab, Box, Divider, FormGroup, FormControlLabel, Checkbox
|
15
|
15
|
} from '@mui/material';
|
16
|
16
|
|
17
|
17
|
import toast, { Toaster } from 'react-hot-toast';
|
|
@@ -23,9 +23,9 @@ import { useQuery, useMutation, useQueryClient } from 'react-query'
|
23
|
23
|
const plazeSchema = Yup.object({
|
24
|
24
|
id: Yup.number(),
|
25
|
25
|
nombrepuesto:
|
26
|
|
- Yup.string().required('El nombre es requerido')
|
27
|
|
- .min(5, "El nombre del puesto debe ser mayor a 5 caracteres")
|
28
|
|
- .max(100),
|
|
26
|
+ Yup.string().required('El nombre es requerido')
|
|
27
|
+ .min(5, "El nombre del puesto debe ser mayor a 5 caracteres")
|
|
28
|
+ .max(100),
|
29
|
29
|
puestosuperior: Yup.number("El puesto superior debe ser un número").required("El puesto es requerido"),
|
30
|
30
|
aredepto: Yup.number('El área debe ser un número').required('Escoge alguna área'),
|
31
|
31
|
fecha: Yup.date("Ingresa una fecha válida").required(),
|
|
@@ -36,15 +36,15 @@ const plazeSchema = Yup.object({
|
36
|
36
|
|
37
|
37
|
function Edit(props) {
|
38
|
38
|
|
39
|
|
- const { setValue,getValues,reset,control,register, handleSubmit, formState: { errors } } = useForm({
|
40
|
|
- resolver : yupResolver(plazeSchema),
|
|
39
|
+ const { setValue, getValues, reset, control, register, handleSubmit, formState: { errors } } = useForm({
|
|
40
|
+ resolver: yupResolver(plazeSchema),
|
41
|
41
|
defaultValues: {
|
42
|
42
|
nombrepuesto: 'mingtest',
|
43
|
43
|
puestosuperior: 77,
|
44
|
44
|
fecha: '01/01/2019',
|
45
|
45
|
notas: 'esto es un ejemplod e una nota',
|
46
|
|
- aredepto : 1,
|
47
|
|
- tests : []
|
|
46
|
+ aredepto: 1,
|
|
47
|
+ tests: []
|
48
|
48
|
}
|
49
|
49
|
});
|
50
|
50
|
|
|
@@ -52,7 +52,7 @@ function Edit(props) {
|
52
|
52
|
|
53
|
53
|
let body = {
|
54
|
54
|
...data,
|
55
|
|
- fecha : new Date(data.fecha).toISOString()
|
|
55
|
+ fecha: new Date(data.fecha).toISOString()
|
56
|
56
|
}
|
57
|
57
|
|
58
|
58
|
puestoMutation.mutate(body, {
|
|
@@ -62,7 +62,7 @@ function Edit(props) {
|
62
|
62
|
toast.success("Puesto Actualizado!!")
|
63
|
63
|
queryClient.invalidateQueries('puestos')
|
64
|
64
|
},
|
65
|
|
- onError:() => {
|
|
65
|
+ onError: () => {
|
66
|
66
|
//close();
|
67
|
67
|
//setOpen(false)
|
68
|
68
|
toast.error("Lo sentimos ocurrió error inténtalo más tarde")
|
|
@@ -74,21 +74,26 @@ function Edit(props) {
|
74
|
74
|
const auth = useSelector((state) => state.token)
|
75
|
75
|
const queryClient = useQueryClient()
|
76
|
76
|
let { visible, toggle } = props
|
|
77
|
+ const [puestoSup, setPuestoSup] = React.useState('');
|
77
|
78
|
|
78
|
79
|
const [open, setOpen] = React.useState(false);
|
79
|
80
|
const [tab, setTab] = React.useState(0);
|
80
|
81
|
const [checklist, setChecklist] = React.useState([]);
|
81
|
82
|
|
82
|
|
- const addPrueba = (check,id) => {
|
|
83
|
+ const changePuestoSup = (event) => {
|
|
84
|
+ setPuestoSup(event.target.value);
|
|
85
|
+ };
|
|
86
|
+
|
|
87
|
+ const addPrueba = (check, id) => {
|
83
|
88
|
let tests = getValues("tests")
|
84
|
89
|
console.log(tests)
|
85
|
|
- let temp ;
|
86
|
|
- if(check){
|
87
|
|
- temp = [...tests, {id}]
|
88
|
|
- }else{
|
89
|
|
- temp = tests.filter( test => test.id !== id);
|
|
90
|
+ let temp;
|
|
91
|
+ if (check) {
|
|
92
|
+ temp = [...tests, { id }]
|
|
93
|
+ } else {
|
|
94
|
+ temp = tests.filter(test => test.id !== id);
|
90
|
95
|
}
|
91
|
|
- setChecklist(temp.map( test => test.id) )
|
|
96
|
+ setChecklist(temp.map(test => test.id))
|
92
|
97
|
setValue('tests', temp)
|
93
|
98
|
};
|
94
|
99
|
|
|
@@ -109,25 +114,25 @@ function Edit(props) {
|
109
|
114
|
|
110
|
115
|
const puestoMutation = useMutation(updatePuesto)
|
111
|
116
|
|
112
|
|
- const close = () => toggle("EDIT", {id : null});
|
|
117
|
+ const close = () => toggle("EDIT", { id: null });
|
113
|
118
|
|
114
|
119
|
const { data: categories } = useQuery('categories', getCategories);
|
115
|
120
|
const { data: testsCatalog } = useQuery('tests', getTest);
|
116
|
121
|
|
117
|
122
|
useEffect(() => {
|
118
|
|
- if(visible == null) return;
|
|
123
|
+ if (visible == null) return;
|
119
|
124
|
let rest = new Service(`/plaza/getthis/${visible}`)
|
120
|
125
|
rest
|
121
|
126
|
.getQuery(auth.token)
|
122
|
|
- .then( response => {
|
|
127
|
+ .then(response => {
|
123
|
128
|
console.log(response.data)
|
124
|
129
|
let { areadeptoplz_id, fecha, tests } = response.data;
|
125
|
|
- let temp_test = tests.map( t => ({ id : t.id} ))
|
126
|
|
- setChecklist(temp_test.map( t => t.id))
|
127
|
|
- reset({...response.data, aredepto : areadeptoplz_id, fecha : new Date(fecha) , tests : temp_test })
|
|
130
|
+ let temp_test = tests.map(t => ({ id: t.id }))
|
|
131
|
+ setChecklist(temp_test.map(t => t.id))
|
|
132
|
+ reset({ ...response.data, aredepto: areadeptoplz_id, fecha: new Date(fecha), tests: temp_test })
|
128
|
133
|
})
|
129
|
134
|
.catch(console.log)
|
130
|
|
- },[visible, auth,reset])
|
|
135
|
+ }, [visible, auth, reset])
|
131
|
136
|
|
132
|
137
|
const changeTab = (_event, newValue) => setTab(newValue);
|
133
|
138
|
|
|
@@ -148,24 +153,24 @@ function Edit(props) {
|
148
|
153
|
<form onSubmit={handleSubmit(onSubmit)}>
|
149
|
154
|
<TabPanel value={tab} index={1}>
|
150
|
155
|
<Stack spacing={1}>
|
151
|
|
- <Box style={{ paddingTop :5, paddingLeft :15 }}>
|
152
|
|
- <Divider/>
|
153
|
|
- <h4 style={{paddingTop :10, paddingBottom:10}}>Seleciona los test a realizar</h4>
|
154
|
|
- <Divider/>
|
|
156
|
+ <Box style={{ paddingTop: 5, paddingLeft: 15 }}>
|
|
157
|
+ <Divider />
|
|
158
|
+ <h4 style={{ paddingTop: 10, paddingBottom: 10 }}>Seleciona los test a realizar</h4>
|
|
159
|
+ <Divider />
|
155
|
160
|
<FormGroup>
|
156
|
161
|
{
|
157
|
|
- testsCatalog ?
|
158
|
|
- testsCatalog.data.map( test => (
|
159
|
|
- <FormControlLabel
|
160
|
|
- label={test.nombre}
|
161
|
|
- key={test.id}
|
162
|
|
- control={
|
163
|
|
- <Checkbox
|
164
|
|
- checked={checklist.includes((test.id))}
|
165
|
|
- onChange={(event)=> addPrueba(event.target.checked,test.id)} /> }
|
|
162
|
+ testsCatalog ?
|
|
163
|
+ testsCatalog.data.map(test => (
|
|
164
|
+ <FormControlLabel
|
|
165
|
+ label={test.nombre}
|
|
166
|
+ key={test.id}
|
|
167
|
+ control={
|
|
168
|
+ <Checkbox
|
|
169
|
+ checked={checklist.includes((test.id))}
|
|
170
|
+ onChange={(event) => addPrueba(event.target.checked, test.id)} />}
|
166
|
171
|
/>
|
167
|
|
- )): null
|
168
|
|
- }
|
|
172
|
+ )) : null
|
|
173
|
+ }
|
169
|
174
|
</FormGroup>
|
170
|
175
|
</Box>
|
171
|
176
|
</Stack>
|
|
@@ -184,38 +189,54 @@ function Edit(props) {
|
184
|
189
|
error={Boolean(errors?.nombrepuesto)}
|
185
|
190
|
{...register("nombrepuesto")} />
|
186
|
191
|
|
187
|
|
- <TextField
|
188
|
|
- name="puestosuperior"
|
189
|
|
- label="Puesto superior"
|
190
|
|
- fullWidth
|
191
|
|
- helperText={errors.puestosuperior?.message}
|
192
|
|
- error={Boolean(errors?.puestosuperior)}
|
193
|
|
- {...register("puestosuperior")} />
|
194
|
|
-
|
|
192
|
+ <FormControl fullWidth>
|
|
193
|
+ <InputLabel id="demo-simple-select-label">Puesto Superior</InputLabel>
|
|
194
|
+ <Controller
|
|
195
|
+ helperText={errors.puestosuperior?.message}
|
|
196
|
+ error={Boolean(errors?.puestosuperior)}
|
|
197
|
+ name="puestosuperior"
|
|
198
|
+ control={control}
|
|
199
|
+ render={({field}) =>
|
|
200
|
+ <Select {...field}>
|
|
201
|
+ {
|
|
202
|
+ categories ?
|
|
203
|
+ categories.data.map(cate => {
|
|
204
|
+ return (
|
|
205
|
+ <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
|
|
206
|
+ )
|
|
207
|
+ })
|
|
208
|
+ : <MenuItem>Null</MenuItem>
|
|
209
|
+ }
|
|
210
|
+ </Select>
|
|
211
|
+ }
|
|
212
|
+ >
|
|
213
|
+
|
|
214
|
+ </Controller>
|
|
215
|
+ </FormControl>
|
195
|
216
|
</Stack>
|
196
|
217
|
|
197
|
218
|
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
|
198
|
219
|
|
199
|
220
|
<FormControl fullWidth>
|
200
|
|
- <InputLabel>Departamento</InputLabel>
|
|
221
|
+ <InputLabel id="demo-simple-select-label2">Departamento</InputLabel>
|
201
|
222
|
<Controller
|
202
|
223
|
helperText={errors.aredepto?.message}
|
203
|
224
|
error={Boolean(errors?.aredepto)}
|
204
|
225
|
name="aredepto"
|
205
|
226
|
control={control}
|
206
|
|
- render={ ({field}) =>
|
|
227
|
+ render={({ field }) =>
|
207
|
228
|
<Select {...field}>
|
208
|
229
|
{
|
209
|
|
- categories ?
|
210
|
|
- categories.data.map(cate => {
|
211
|
|
- return (
|
212
|
|
- <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
|
213
|
|
- )
|
214
|
|
- })
|
215
|
|
- : <MenuItem value={1}>hola</MenuItem>
|
216
|
|
- }
|
|
230
|
+ categories ?
|
|
231
|
+ categories.data.map(cate => {
|
|
232
|
+ return (
|
|
233
|
+ <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
|
|
234
|
+ )
|
|
235
|
+ })
|
|
236
|
+ : <MenuItem value={1}>hola</MenuItem>
|
|
237
|
+ }
|
217
|
238
|
</Select>
|
218
|
|
- }>
|
|
239
|
+ }>
|
219
|
240
|
</Controller>
|
220
|
241
|
</FormControl>
|
221
|
242
|
|
|
@@ -223,7 +244,7 @@ function Edit(props) {
|
223
|
244
|
<Controller
|
224
|
245
|
name="fecha"
|
225
|
246
|
control={control}
|
226
|
|
- render={({field}) =>
|
|
247
|
+ render={({ field }) =>
|
227
|
248
|
<DesktopDatePicker
|
228
|
249
|
{...field}
|
229
|
250
|
helperText={errors.fecha?.message}
|
|
@@ -231,8 +252,8 @@ function Edit(props) {
|
231
|
252
|
label="Fecha Creación"
|
232
|
253
|
fullWidth
|
233
|
254
|
inputFormat="dd/MM/yyyy"
|
234
|
|
- renderInput={(params) => <TextField {...params} helperText={errors.fecha?.message} />} /> }
|
235
|
|
- >
|
|
255
|
+ renderInput={(params) => <TextField {...params} helperText={errors.fecha?.message} />} />}
|
|
256
|
+ >
|
236
|
257
|
</Controller>
|
237
|
258
|
</LocalizationProvider>
|
238
|
259
|
</Stack>
|
|
@@ -248,7 +269,7 @@ function Edit(props) {
|
248
|
269
|
fullWidth
|
249
|
270
|
type="text"
|
250
|
271
|
{...register("notas")}
|
251
|
|
- />
|
|
272
|
+ />
|
252
|
273
|
</Stack>
|
253
|
274
|
</Stack>
|
254
|
275
|
</TabPanel>
|