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,6 +27,7 @@ import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
27 27
 const filter = createFilterOptions();
28 28
 
29 29
 async function getPuestoSuperior(puesto, auth) {
30
+console.log('P:',puesto)
30 31
   if (puesto.length < 2) return []
31 32
   let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
32 33
   let result = await rest.get(auth.token)
@@ -128,6 +129,7 @@ function Edit(props) {
128 129
   };
129 130
 
130 131
   const handleSubmitDialog = async (event) => {
132
+  console.log('handlesubmit',dialogValue)
131 133
     event.preventDefault();
132 134
     let { id, nombre } = await savePuestoSuperior(dialogValue, auth)
133 135
     if (id) {
@@ -137,6 +139,7 @@ function Edit(props) {
137 139
       }
138 140
       if (to_set.id) {
139 141
         setDialogValue(to_set);
142
+        reset({ ...getValues(),puestosuperior: to_set.id })
140 143
       }
141 144
     }
142 145
     handleCloseDialog();
@@ -144,24 +147,41 @@ function Edit(props) {
144 147
 
145 148
   let setDialogValue = useCallback((value) => {
146 149
     console.log('value receivied', value)
147
-    let id = value.id || 0;
150
+    let id = value?.id || 0;
148 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 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 176
   const loading = openSugg && options.length === 0;
159 177
 
160 178
   const AutoCompleteChange = (event, newValue) => {
161 179
     console.log('newValue', newValue)
180
+    //this should be change
162 181
     setValue('puestosuperior', newValue?.id)
163 182
 
164 183
     if (typeof newValue === 'string') {
184
+    console.log('if1')
165 185
       setTimeout(() => {
166 186
         toggleOpenDialog(true);
167 187
         setDialogValue({
@@ -170,12 +190,14 @@ function Edit(props) {
170 190
         });
171 191
       });
172 192
     } else if (newValue && newValue.inputValue) {
193
+    console.log('if2')
173 194
       toggleOpenDialog(true);
174 195
       setDialogValue({
175 196
         title: newValue.inputValue,
176 197
         id: '',
177 198
       });
178 199
     } else {
200
+    console.log('if3')
179 201
       setDialogValue(newValue);
180 202
     }
181 203
   }
@@ -217,11 +239,12 @@ function Edit(props) {
217 239
   useEffect(() => {
218 240
 
219 241
     let current_id = getValues('id')
220
-    console.log({ current_id, visible })
242
+    // console.log({ current_id, visible })
221 243
 
222 244
     if (visible == null) return;
223 245
 
224 246
     if (current_id !== visible) {
247
+    console.log('change with use effect')
225 248
 
226 249
       let rest = new Service(`/plaza/getthis/${visible}`)
227 250
       rest
@@ -261,12 +284,12 @@ function Edit(props) {
261 284
 
262 285
     return () => {
263 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 293
   // console.log('PROPS', props)
271 294
 
272 295