Browse Source

first aproach

amenpunk 1 year ago
parent
commit
a8c0515e44
1 changed files with 33 additions and 10 deletions
  1. 33 10
      src/Components/Modal/EditPlaza.js

+ 33 - 10
src/Components/Modal/EditPlaza.js

27
 const filter = createFilterOptions();
27
 const filter = createFilterOptions();
28
 
28
 
29
 async function getPuestoSuperior(puesto, auth) {
29
 async function getPuestoSuperior(puesto, auth) {
30
+console.log('P:',puesto)
30
   if (puesto.length < 2) return []
31
   if (puesto.length < 2) return []
31
   let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
32
   let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
32
   let result = await rest.get(auth.token)
33
   let result = await rest.get(auth.token)
128
   };
129
   };
129
 
130
 
130
   const handleSubmitDialog = async (event) => {
131
   const handleSubmitDialog = async (event) => {
132
+  console.log('handlesubmit',dialogValue)
131
     event.preventDefault();
133
     event.preventDefault();
132
     let { id, nombre } = await savePuestoSuperior(dialogValue, auth)
134
     let { id, nombre } = await savePuestoSuperior(dialogValue, auth)
133
     if (id) {
135
     if (id) {
137
       }
139
       }
138
       if (to_set.id) {
140
       if (to_set.id) {
139
         setDialogValue(to_set);
141
         setDialogValue(to_set);
142
+        reset({ ...getValues(),puestosuperior: to_set.id })
140
       }
143
       }
141
     }
144
     }
142
     handleCloseDialog();
145
     handleCloseDialog();
144
 
147
 
145
   let setDialogValue = useCallback((value) => {
148
   let setDialogValue = useCallback((value) => {
146
     console.log('value receivied', value)
149
     console.log('value receivied', value)
147
-    let id = value.id || 0;
150
+    let id = value?.id || 0;
148
     if (id !== 0) {
151
     if (id !== 0) {
149
-      // setValues({ ...values, puestosuperior: value?.id })
150
-      console.log('setting: ', value)
151
-      setValue('puestosuperior',)
152
-      console.log('inside', getValues())
153
-      // return
152
+      reset({ ...getValues(),puestosuperior: id })
153
+      setValue('puestosuperior',id)
154
+      setDialogValueHook(value)
154
     }
155
     }
155
     setDialogValueHook(value)
156
     setDialogValueHook(value)
156
-  },[setValue,getValues])
157
+  },[setValue,reset,getValues])
158
+
159
+
160
+
161
+  // let setDialogValue = useCallback((value) => {
162
+  // console.log('value receivied', value)
163
+  //   let id = value.id || 0;
164
+  //   if (id !== 0) {
165
+  //     console.log('setiando valor', value)
166
+  //     setValue({ puestosuperior: value?.id })
167
+  //      // setDialogValueHook(value)
168
+  //   }
169
+  //   console.log("setiando valor false", value)
170
+  //   // setDialogValueHook(value)
171
+  // }, [setValue])
172
+
173
+
174
+
157
 
175
 
158
   const loading = openSugg && options.length === 0;
176
   const loading = openSugg && options.length === 0;
159
 
177
 
160
   const AutoCompleteChange = (event, newValue) => {
178
   const AutoCompleteChange = (event, newValue) => {
161
     console.log('newValue', newValue)
179
     console.log('newValue', newValue)
180
+    //this should be change
162
     setValue('puestosuperior', newValue?.id)
181
     setValue('puestosuperior', newValue?.id)
163
 
182
 
164
     if (typeof newValue === 'string') {
183
     if (typeof newValue === 'string') {
184
+    console.log('if1')
165
       setTimeout(() => {
185
       setTimeout(() => {
166
         toggleOpenDialog(true);
186
         toggleOpenDialog(true);
167
         setDialogValue({
187
         setDialogValue({
170
         });
190
         });
171
       });
191
       });
172
     } else if (newValue && newValue.inputValue) {
192
     } else if (newValue && newValue.inputValue) {
193
+    console.log('if2')
173
       toggleOpenDialog(true);
194
       toggleOpenDialog(true);
174
       setDialogValue({
195
       setDialogValue({
175
         title: newValue.inputValue,
196
         title: newValue.inputValue,
176
         id: '',
197
         id: '',
177
       });
198
       });
178
     } else {
199
     } else {
200
+    console.log('if3')
179
       setDialogValue(newValue);
201
       setDialogValue(newValue);
180
     }
202
     }
181
   }
203
   }
217
   useEffect(() => {
239
   useEffect(() => {
218
 
240
 
219
     let current_id = getValues('id')
241
     let current_id = getValues('id')
220
-    console.log({ current_id, visible })
242
+    // console.log({ current_id, visible })
221
 
243
 
222
     if (visible == null) return;
244
     if (visible == null) return;
223
 
245
 
224
     if (current_id !== visible) {
246
     if (current_id !== visible) {
247
+    console.log('change with use effect')
225
 
248
 
226
       let rest = new Service(`/plaza/getthis/${visible}`)
249
       let rest = new Service(`/plaza/getthis/${visible}`)
227
       rest
250
       rest
261
 
284
 
262
     return () => {
285
     return () => {
263
       active = false;
286
       active = false;
264
-      reset()
287
+      // reset()
265
     };
288
     };
266
 
289
 
267
 
290
 
268
 
291
 
269
-  }, [visible, auth, reset, loading, dialogValue, getValues,setDialogValue])
292
+  }, [visible, auth, reset, loading, dialogValue, getValues, setDialogValue])
270
   // console.log('PROPS', props)
293
   // console.log('PROPS', props)
271
 
294
 
272
 
295