Explorar o código

update with mutation nice

amenpunk %!s(int64=3) %!d(string=hai) anos
pai
achega
98f8287d6c
Modificáronse 4 ficheiros con 36 adicións e 25 borrados
  1. 8 0
      src/App.css
  2. 4 6
      src/Components/Generics/loading.jsx
  3. 23 6
      src/Components/Modal/EditPlaza.js
  4. 1 13
      src/Pages/Puestos.jsx

+ 8 - 0
src/App.css

@@ -360,3 +360,11 @@
   background-color: var(--main);
   color: white;
 }
+.loadingGeneric{
+    height: 100vh;
+    display: flex;
+    align-content: center;
+    flex-wrap: nowrap;
+    justify-content: center;
+    align-items: center;
+}

+ 4 - 6
src/Components/Generics/loading.jsx

@@ -1,7 +1,7 @@
 import React from "react";
 import '../../Css/loading.css'
 
-import { Paper, Box } from '@mui/material'
+import { Box, Paper } from '@mui/material'
 
 export function Loading() {
 
@@ -12,11 +12,10 @@ export function Loading() {
 
   return (
     <div className="content-section">
+      <Paper>
       <div className="main">
-        <Box>
-          <Paper sx={{ mb: 2, padding: 2, }}>
+        <Box className="loadingGeneric">
 
-            <div className="content-section">
               <div className="loading_or_content">
                 <div className="snippet" data-title=".dot-pulse">
                   <div className="stage">
@@ -24,11 +23,10 @@ export function Loading() {
                   </div>
                 </div>
               </div>
-            </div>
 
-          </Paper>
         </Box>
       </div>
+      </Paper>
     </div>
 
   )

+ 23 - 6
src/Components/Modal/EditPlaza.js

@@ -1,4 +1,4 @@
-import React, { memo, useMemo, useEffect } from 'react';
+import React, { memo, useEffect } from 'react';
 import { Modal } from 'react-bootstrap'
 import { useForm, Controller } from "react-hook-form";
 import { yupResolver } from '@hookform/resolvers/yup';
@@ -49,12 +49,30 @@ function Edit(props) {
   });
 
   const onSubmit = data => {
-    console.log("SUBMIT: ",data)
+
+    let body = {
+      ...data,
+      fecha : new Date(data.fecha).toISOString()
+    }
+
+    puestoMutation.mutate(body, {
+      onSuccess: () => {
+        close();
+        setOpen(false)
+        toast.success("Puesto Actualizado!!")
+        queryClient.invalidateQueries('puestos')
+      },
+      onError:() => {
+        close();
+        setOpen(false)
+        toast.error("Lo sentimos ocurrió error inténtalo más tarde")
+      }
+    })
+
   }
 
-  const now = useMemo(() => new Date(), [])
   const auth = useSelector((state) => state.token)
-  // const queryClient = useQueryClient()
+  const queryClient = useQueryClient()
   let { visible, toggle } = props
 
   const [open, setOpen] = React.useState(false);
@@ -72,7 +90,6 @@ function Edit(props) {
     }
     setChecklist(temp.map( test => test.id) )
     setValue('tests', temp)
-    // setValue({...values, tests: temp})
   };
 
   const getCategories = async () => {
@@ -110,7 +127,7 @@ function Edit(props) {
         reset({...response.data, areadepto : areadeptoplz_id, fecha : new Date(fecha) , tests : temp_test  })
       })
       .catch(console.log)
-  },[visible])
+  },[visible, auth,reset])
 
   const changeTab = (_event, newValue) => setTab(newValue);
 

+ 1 - 13
src/Pages/Puestos.jsx

@@ -88,23 +88,13 @@ export function Puestos() {
     }
   }, [edit, del, show])
 
+
   if(isLoading){
     return(
       <Loading/>
     )
   }
 
-  /*
-  if (isLoading) {
-    return (
-      <Paper sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh' }}>
-        <main id="loading_or_content">
-          <Loading />
-        </main>
-      </Paper>
-    )
-  }
-
   if (error) {
     return (
       <Paper sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh' }}>
@@ -114,8 +104,6 @@ export function Puestos() {
       </Paper>
     )
   }
-    */
-
   const total_items = Divide(result.data).length
 
   return (