浏览代码

update with mutation nice

amenpunk 2 年之前
父节点
当前提交
98f8287d6c
共有 4 个文件被更改,包括 36 次插入25 次删除
  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 @@
360 360
   background-color: var(--main);
361 361
   color: white;
362 362
 }
363
+.loadingGeneric{
364
+    height: 100vh;
365
+    display: flex;
366
+    align-content: center;
367
+    flex-wrap: nowrap;
368
+    justify-content: center;
369
+    align-items: center;
370
+}

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

@@ -1,7 +1,7 @@
1 1
 import React from "react";
2 2
 import '../../Css/loading.css'
3 3
 
4
-import { Paper, Box } from '@mui/material'
4
+import { Box, Paper } from '@mui/material'
5 5
 
6 6
 export function Loading() {
7 7
 
@@ -12,11 +12,10 @@ export function Loading() {
12 12
 
13 13
   return (
14 14
     <div className="content-section">
15
+      <Paper>
15 16
       <div className="main">
16
-        <Box>
17
-          <Paper sx={{ mb: 2, padding: 2, }}>
17
+        <Box className="loadingGeneric">
18 18
 
19
-            <div className="content-section">
20 19
               <div className="loading_or_content">
21 20
                 <div className="snippet" data-title=".dot-pulse">
22 21
                   <div className="stage">
@@ -24,11 +23,10 @@ export function Loading() {
24 23
                   </div>
25 24
                 </div>
26 25
               </div>
27
-            </div>
28 26
 
29
-          </Paper>
30 27
         </Box>
31 28
       </div>
29
+      </Paper>
32 30
     </div>
33 31
 
34 32
   )

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

@@ -1,4 +1,4 @@
1
-import React, { memo, useMemo, useEffect } from 'react';
1
+import React, { memo, useEffect } from 'react';
2 2
 import { Modal } from 'react-bootstrap'
3 3
 import { useForm, Controller } from "react-hook-form";
4 4
 import { yupResolver } from '@hookform/resolvers/yup';
@@ -49,12 +49,30 @@ function Edit(props) {
49 49
   });
50 50
 
51 51
   const onSubmit = data => {
52
-    console.log("SUBMIT: ",data)
52
+
53
+    let body = {
54
+      ...data,
55
+      fecha : new Date(data.fecha).toISOString()
56
+    }
57
+
58
+    puestoMutation.mutate(body, {
59
+      onSuccess: () => {
60
+        close();
61
+        setOpen(false)
62
+        toast.success("Puesto Actualizado!!")
63
+        queryClient.invalidateQueries('puestos')
64
+      },
65
+      onError:() => {
66
+        close();
67
+        setOpen(false)
68
+        toast.error("Lo sentimos ocurrió error inténtalo más tarde")
69
+      }
70
+    })
71
+
53 72
   }
54 73
 
55
-  const now = useMemo(() => new Date(), [])
56 74
   const auth = useSelector((state) => state.token)
57
-  // const queryClient = useQueryClient()
75
+  const queryClient = useQueryClient()
58 76
   let { visible, toggle } = props
59 77
 
60 78
   const [open, setOpen] = React.useState(false);
@@ -72,7 +90,6 @@ function Edit(props) {
72 90
     }
73 91
     setChecklist(temp.map( test => test.id) )
74 92
     setValue('tests', temp)
75
-    // setValue({...values, tests: temp})
76 93
   };
77 94
 
78 95
   const getCategories = async () => {
@@ -110,7 +127,7 @@ function Edit(props) {
110 127
         reset({...response.data, areadepto : areadeptoplz_id, fecha : new Date(fecha) , tests : temp_test  })
111 128
       })
112 129
       .catch(console.log)
113
-  },[visible])
130
+  },[visible, auth,reset])
114 131
 
115 132
   const changeTab = (_event, newValue) => setTab(newValue);
116 133
 

+ 1 - 13
src/Pages/Puestos.jsx

@@ -88,23 +88,13 @@ export function Puestos() {
88 88
     }
89 89
   }, [edit, del, show])
90 90
 
91
+
91 92
   if(isLoading){
92 93
     return(
93 94
       <Loading/>
94 95
     )
95 96
   }
96 97
 
97
-  /*
98
-  if (isLoading) {
99
-    return (
100
-      <Paper sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh' }}>
101
-        <main id="loading_or_content">
102
-          <Loading />
103
-        </main>
104
-      </Paper>
105
-    )
106
-  }
107
-
108 98
   if (error) {
109 99
     return (
110 100
       <Paper sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh' }}>
@@ -114,8 +104,6 @@ export function Puestos() {
114 104
       </Paper>
115 105
     )
116 106
   }
117
-    */
118
-
119 107
   const total_items = Divide(result.data).length
120 108
 
121 109
   return (