Bladeren bron

pre save new puesto superior

amenpunk 2 jaren geleden
bovenliggende
commit
06a41cd137
1 gewijzigde bestanden met toevoegingen van 29 en 53 verwijderingen
  1. 29 53
      src/Components/Modal/AgregarManual.js

+ 29 - 53
src/Components/Modal/AgregarManual.js

@@ -24,17 +24,17 @@ import { useSelector } from 'react-redux';
 
 const filter = createFilterOptions();
 
-  async function getPuestoSuperior  (puesto, auth) {
-    if (puesto.length < 3) return []
-    let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
-    let result = await rest.get(auth.token)
-    console.log(result)
-    if (result?.data?.length > 0) {
-      result = result.data.map((item) => ({ 'title': item.nombre, year: item.id }))
-      return result;
-    }
-    return [];
+async function getPuestoSuperior(puesto, auth) {
+  if (puesto.length < 3) return []
+  let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
+  let result = await rest.get(auth.token)
+  // console.log(result)
+  if (result?.data?.length > 0) {
+    result = result.data.map((item) => ({ 'title': item.nombre, year: item.id }))
+    return result;
   }
+  return [];
+}
 
 
 function Manual(props) {
@@ -70,30 +70,31 @@ function Manual(props) {
   const [date, setDate] = React.useState(new Date());
   const [tab, setTab] = React.useState(0);
   const [checklist, setChecklist] = React.useState([]);
-  const [valueDialog, setValueDialog] = React.useState();
   const [openDialog, toggleOpenDialog] = React.useState(false);
   const [openSugg, setOpenSugg] = React.useState(false);
   const [options, setOptions] = React.useState([]);
-  const [dialogValue, setDialogValue] = React.useState({
+  const [dialogValue, setDialogValueHook] = React.useState({
     title: '',
     year: '',
   });
 
+  let setDialogValue = (value) => {
+    console.log('llamada', value)
+    // setValues({...values, puestosuperior: value?.title })
+    setDialogValueHook(value)
+  }
+
   const loading = openSugg && options.length === 0;
 
   React.useEffect(() => {
 
-    console.log('dialogValue', dialogValue)
     let active = true;
-    console.log('loading', loading)
     if (!loading) {
       return undefined;
     }
 
     (async () => {
       let puestos = await getPuestoSuperior(dialogValue.title, auth)
-      console.log('puestos', puestos)
-
       if (active) {
         setOptions(puestos);
       }
@@ -124,7 +125,7 @@ function Manual(props) {
 
   const handleSubmitDialog = (event) => {
     event.preventDefault();
-    setValueDialog({
+    setDialogValue({
       title: dialogValue.title,
       year: parseInt(dialogValue.year, 10),
     });
@@ -133,8 +134,9 @@ function Manual(props) {
 
   const AutoCompleteChange = (event, newValue) => {
     console.log('newValue', newValue)
+    // TODO : formik logic to validate autocomplete
+
     if (typeof newValue === 'string') {
-      // timeout to avoid instant validation of the dialog's form.
       setTimeout(() => {
         toggleOpenDialog(true);
         setDialogValue({
@@ -149,7 +151,7 @@ function Manual(props) {
         year: '',
       });
     } else {
-      setValueDialog(newValue);
+      setDialogValue(newValue);
     }
   }
 
@@ -159,13 +161,12 @@ function Manual(props) {
   }
 
   const puestoMutation = useMutation(agregarPuesto)
-
   let { visible, onClose } = props
 
   const formik = useFormik({
     initialValues: {
       nombrepuesto: "",
-      puestosuperior: "The Godfather",
+      puestosuperior: "",
       aredepto: 1,
       fecha: date,
       notas: "",
@@ -178,12 +179,10 @@ function Manual(props) {
         setTab(1)
         return
       }
-
       setOpen(true)
       fields['fecha'] = new Date(fields.fecha).toISOString();
       fields['areadeptoplz_id'] = 1;
       fields['id'] = -1;
-
       puestoMutation.mutate(fields, {
         onSuccess: () => {
           setOpen(false)
@@ -201,11 +200,10 @@ function Manual(props) {
     validationSchema: NewPlazaSchema,
   });
 
-  const changeTab = (_event, newValue) => {
-    setTab(newValue);
-  };
+  const changeTab = (_event, newValue) => setTab(newValue);
 
   const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
+  // console.log({ values })
 
   const addPrueba = (check, id) => {
     let { tests } = values
@@ -252,7 +250,7 @@ function Manual(props) {
                 autoFocus
                 margin="dense"
                 id="name"
-                value={dialogValue.title}
+                value={dialogValue?.title}
                 onChange={(event) =>
                   setDialogValue({
                     ...dialogValue,
@@ -267,7 +265,7 @@ function Manual(props) {
               <TextField
                 margin="dense"
                 id="name"
-                value={dialogValue.year}
+                value={dialogValue?.year}
                 onChange={(event) =>
                   setDialogValue({
                     ...dialogValue,
@@ -333,30 +331,9 @@ function Manual(props) {
 
                   <FormControl fullWidth>
 
-                    {/*
-                    <InputLabel id="demo-simple-select-label">Puesto Superior</InputLabel>
-                      <Select
-                        labelId="demo-simple-select-label"
-                        value={puestoSup}
-                        label="Puesto Superior"
-                        onChange={changePuestoSup}
-                        {...getFieldProps('puestosuperior')}
-                        error={Boolean(touched.puestosuperior && errors.puestosuperior)} >
-                        {
-                          data ?
-                            data.data.map(cate => {
-                              return (
-                                <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
-                              )
-                            })
-                            : <MenuItem>Null</MenuItem>
-                        }
-                      </Select>
-*/}
-
                     <Autocomplete
                       fullWidth
-                      value={valueDialog}
+                      value={dialogValue}
                       onChange={AutoCompleteChange}
                       open={openSugg}
                       onOpen={() => {
@@ -404,8 +381,8 @@ function Manual(props) {
                           InputProps={{
                             ...params.InputProps,
                             onChange: (event) => {
-                              let title = event.target.value;
-                              console.log(title)
+                              // let title = event.target.value;
+                              // console.log('titulo',title)
                               setOptions([]);
                               setDialogValue({
                                 title: event.target.value,
@@ -424,7 +401,6 @@ function Manual(props) {
 
                     />
 
-
                   </FormControl>
 
                 </Stack>