|
@@ -1,4 +1,4 @@
|
1
|
|
-import React, { memo, useEffect } from 'react';
|
|
1
|
+import React, { memo, useEffect, useCallback } from 'react';
|
2
|
2
|
import { Modal } from 'react-bootstrap'
|
3
|
3
|
import { useForm, Controller } from "react-hook-form";
|
4
|
4
|
import { yupResolver } from '@hookform/resolvers/yup';
|
|
@@ -74,8 +74,9 @@ function Edit(props) {
|
74
|
74
|
const { setValue, getValues, reset, control, register, handleSubmit, formState: { errors } } = useForm({
|
75
|
75
|
resolver: yupResolver(plazeSchema),
|
76
|
76
|
defaultValues: {
|
|
77
|
+ id: 0,
|
77
|
78
|
nombrepuesto: 'mingtest',
|
78
|
|
- puestosuperior: null,
|
|
79
|
+ puestosuperior: 0,
|
79
|
80
|
fecha: '01/01/2019',
|
80
|
81
|
notas: 'esto es un ejemplod e una nota',
|
81
|
82
|
aredepto: 1,
|
|
@@ -109,7 +110,6 @@ function Edit(props) {
|
109
|
110
|
const auth = useSelector((state) => state.token)
|
110
|
111
|
const queryClient = useQueryClient()
|
111
|
112
|
let { visible, toggle } = props
|
112
|
|
- // const [puestoSup, setPuestoSup] = React.useState('');
|
113
|
113
|
|
114
|
114
|
const [open, setOpen] = React.useState(false);
|
115
|
115
|
const [tab, setTab] = React.useState(0);
|
|
@@ -142,13 +142,18 @@ function Edit(props) {
|
142
|
142
|
handleCloseDialog();
|
143
|
143
|
};
|
144
|
144
|
|
145
|
|
- let setDialogValue = (value) => {
|
146
|
|
- if (value?.id !== undefined && isNaN(value?.id) === false) {
|
|
145
|
+ let setDialogValue = useCallback((value) => {
|
|
146
|
+ console.log('value receivied', value)
|
|
147
|
+ let id = value.id || 0;
|
|
148
|
+ if (id !== 0) {
|
147
|
149
|
// setValues({ ...values, puestosuperior: value?.id })
|
148
|
|
- setValue('puestosuperior', value?.id)
|
|
150
|
+ console.log('setting: ', value)
|
|
151
|
+ setValue('puestosuperior',)
|
|
152
|
+ console.log('inside', getValues())
|
|
153
|
+ // return
|
149
|
154
|
}
|
150
|
155
|
setDialogValueHook(value)
|
151
|
|
- }
|
|
156
|
+ },[setValue,getValues])
|
152
|
157
|
|
153
|
158
|
const loading = openSugg && options.length === 0;
|
154
|
159
|
|
|
@@ -211,32 +216,36 @@ function Edit(props) {
|
211
|
216
|
|
212
|
217
|
useEffect(() => {
|
213
|
218
|
|
|
219
|
+ let current_id = getValues('id')
|
|
220
|
+ console.log({ current_id, visible })
|
|
221
|
+
|
214
|
222
|
if (visible == null) return;
|
215
|
|
- let rest = new Service(`/plaza/getthis/${visible}`)
|
216
|
|
- rest
|
217
|
|
- .getQuery(auth.token)
|
218
|
|
- .then(response => {
|
219
|
|
- let { areadeptoplz_id, fecha, tests, puestosuperior } = response.data;
|
220
|
|
- let temp_test = tests.map(t => ({ id: t.id }))
|
221
|
|
- setChecklist(temp_test.map(t => t.id))
|
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,
|
234
|
|
- puestosuperior: puestosuperior.id
|
|
223
|
+
|
|
224
|
+ if (current_id !== visible) {
|
|
225
|
+
|
|
226
|
+ let rest = new Service(`/plaza/getthis/${visible}`)
|
|
227
|
+ rest
|
|
228
|
+ .getQuery(auth.token)
|
|
229
|
+ .then(response => {
|
|
230
|
+ let { areadeptoplz_id, fecha, tests, puestosuperior } = response.data;
|
|
231
|
+ let temp_test = tests.map(t => ({ id: t.id }))
|
|
232
|
+ setChecklist(temp_test.map(t => t.id))
|
|
233
|
+ console.log('puesto sup', puestosuperior)
|
|
234
|
+ setDialogValue({
|
|
235
|
+ title: puestosuperior.nombre,
|
|
236
|
+ id: puestosuperior.id
|
|
237
|
+ })
|
|
238
|
+ reset({
|
|
239
|
+ ...response.data,
|
|
240
|
+ aredepto: areadeptoplz_id,
|
|
241
|
+ fecha: new Date(fecha),
|
|
242
|
+ tests: temp_test,
|
|
243
|
+ puestosuperior: puestosuperior.id
|
|
244
|
+ })
|
235
|
245
|
})
|
236
|
|
- // setDialogValue({ title: puestosuperior.nombre, id: puestosuperior.id })
|
237
|
|
- })
|
238
|
|
- .catch(e => console.log(e))
|
|
246
|
+ .catch(e => console.log(e))
|
239
|
247
|
|
|
248
|
+ }
|
240
|
249
|
|
241
|
250
|
let active = true;
|
242
|
251
|
if (!loading) {
|
|
@@ -252,11 +261,46 @@ function Edit(props) {
|
252
|
261
|
|
253
|
262
|
return () => {
|
254
|
263
|
active = false;
|
|
264
|
+ reset()
|
255
|
265
|
};
|
256
|
266
|
|
257
|
267
|
|
258
|
268
|
|
259
|
|
- }, [visible, auth, reset, loading, dialogValue])
|
|
269
|
+ }, [visible, auth, reset, loading, dialogValue, getValues,setDialogValue])
|
|
270
|
+ // console.log('PROPS', props)
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+ // if (props.visible !== getValues('id') ) {
|
|
274
|
+ //
|
|
275
|
+ // let rest = new Service(`/plaza/getthis/${visible}`)
|
|
276
|
+ // rest
|
|
277
|
+ // .getQuery(auth.token)
|
|
278
|
+ // .then(response => {
|
|
279
|
+ //
|
|
280
|
+ // console.log('initial value', dialogValue)
|
|
281
|
+ // let { areadeptoplz_id, fecha, tests, puestosuperior } = response.data;
|
|
282
|
+ // let temp_test = tests.map(t => ({ id: t.id }))
|
|
283
|
+ // setChecklist(temp_test.map(t => t.id))
|
|
284
|
+ // console.log('puesto sup', puestosuperior)
|
|
285
|
+ // reset({
|
|
286
|
+ // ...response.data,
|
|
287
|
+ // aredepto: areadeptoplz_id,
|
|
288
|
+ // fecha: new Date(fecha),
|
|
289
|
+ // tests: temp_test,
|
|
290
|
+ // puestosuperior: puestosuperior.id
|
|
291
|
+ // })
|
|
292
|
+ // let temp = { title: puestosuperior.nombre, id: puestosuperior.id }
|
|
293
|
+ // console.log(temp)
|
|
294
|
+ // if (dialogValue?.id !== temp.id) {
|
|
295
|
+ // setDialogValueHook(temp)
|
|
296
|
+ // }
|
|
297
|
+ //
|
|
298
|
+ // })
|
|
299
|
+ // .catch(e => console.log(e))
|
|
300
|
+ // }else {
|
|
301
|
+ // console.log("no es visible y el puesto superior no es 0",{ visible,"p": getValues('puestosuperior')})
|
|
302
|
+ // }
|
|
303
|
+
|
260
|
304
|
|
261
|
305
|
const changeTab = (_event, newValue) => setTab(newValue);
|
262
|
306
|
|