amenpunk před 2 roky
rodič
revize
a8c0515e44
1 změnil soubory, kde provedl 33 přidání a 10 odebrání
  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';
 const filter = createFilterOptions();
 
 async function getPuestoSuperior(puesto, auth) {
+console.log('P:',puesto)
   if (puesto.length < 2) return []
   let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
   let result = await rest.get(auth.token)
@@ -128,6 +129,7 @@ function Edit(props) {
   };
 
   const handleSubmitDialog = async (event) => {
+  console.log('handlesubmit',dialogValue)
     event.preventDefault();
     let { id, nombre } = await savePuestoSuperior(dialogValue, auth)
     if (id) {
@@ -137,6 +139,7 @@ function Edit(props) {
       }
       if (to_set.id) {
         setDialogValue(to_set);
+        reset({ ...getValues(),puestosuperior: to_set.id })
       }
     }
     handleCloseDialog();
@@ -144,24 +147,41 @@ function Edit(props) {
 
   let setDialogValue = useCallback((value) => {
     console.log('value receivied', value)
-    let id = value.id || 0;
+    let id = value?.id || 0;
     if (id !== 0) {
-      // setValues({ ...values, puestosuperior: value?.id })
-      console.log('setting: ', value)
-      setValue('puestosuperior',)
-      console.log('inside', getValues())
-      // return
+      reset({ ...getValues(),puestosuperior: id })
+      setValue('puestosuperior',id)
+      setDialogValueHook(value)
     }
     setDialogValueHook(value)
-  },[setValue,getValues])
+  },[setValue,reset,getValues])
+
+
+
+  // let setDialogValue = useCallback((value) => {
+  // console.log('value receivied', value)
+  //   let id = value.id || 0;
+  //   if (id !== 0) {
+  //     console.log('setiando valor', value)
+  //     setValue({ puestosuperior: value?.id })
+  //      // setDialogValueHook(value)
+  //   }
+  //   console.log("setiando valor false", value)
+  //   // setDialogValueHook(value)
+  // }, [setValue])
+
+
+
 
   const loading = openSugg && options.length === 0;
 
   const AutoCompleteChange = (event, newValue) => {
     console.log('newValue', newValue)
+    //this should be change
     setValue('puestosuperior', newValue?.id)
 
     if (typeof newValue === 'string') {
+    console.log('if1')
       setTimeout(() => {
         toggleOpenDialog(true);
         setDialogValue({
@@ -170,12 +190,14 @@ function Edit(props) {
         });
       });
     } else if (newValue && newValue.inputValue) {
+    console.log('if2')
       toggleOpenDialog(true);
       setDialogValue({
         title: newValue.inputValue,
         id: '',
       });
     } else {
+    console.log('if3')
       setDialogValue(newValue);
     }
   }
@@ -217,11 +239,12 @@ function Edit(props) {
   useEffect(() => {
 
     let current_id = getValues('id')
-    console.log({ current_id, visible })
+    // console.log({ current_id, visible })
 
     if (visible == null) return;
 
     if (current_id !== visible) {
+    console.log('change with use effect')
 
       let rest = new Service(`/plaza/getthis/${visible}`)
       rest
@@ -261,12 +284,12 @@ function Edit(props) {
 
     return () => {
       active = false;
-      reset()
+      // reset()
     };
 
 
 
-  }, [visible, auth, reset, loading, dialogValue, getValues,setDialogValue])
+  }, [visible, auth, reset, loading, dialogValue, getValues, setDialogValue])
   // console.log('PROPS', props)