瀏覽代碼

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
   background-color: var(--main);
360
   background-color: var(--main);
361
   color: white;
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
 import React from "react";
1
 import React from "react";
2
 import '../../Css/loading.css'
2
 import '../../Css/loading.css'
3
 
3
 
4
-import { Paper, Box } from '@mui/material'
4
+import { Box, Paper } from '@mui/material'
5
 
5
 
6
 export function Loading() {
6
 export function Loading() {
7
 
7
 
12
 
12
 
13
   return (
13
   return (
14
     <div className="content-section">
14
     <div className="content-section">
15
+      <Paper>
15
       <div className="main">
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
               <div className="loading_or_content">
19
               <div className="loading_or_content">
21
                 <div className="snippet" data-title=".dot-pulse">
20
                 <div className="snippet" data-title=".dot-pulse">
22
                   <div className="stage">
21
                   <div className="stage">
24
                   </div>
23
                   </div>
25
                 </div>
24
                 </div>
26
               </div>
25
               </div>
27
-            </div>
28
 
26
 
29
-          </Paper>
30
         </Box>
27
         </Box>
31
       </div>
28
       </div>
29
+      </Paper>
32
     </div>
30
     </div>
33
 
31
 
34
   )
32
   )

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

1
-import React, { memo, useMemo, useEffect } from 'react';
1
+import React, { memo, useEffect } from 'react';
2
 import { Modal } from 'react-bootstrap'
2
 import { Modal } from 'react-bootstrap'
3
 import { useForm, Controller } from "react-hook-form";
3
 import { useForm, Controller } from "react-hook-form";
4
 import { yupResolver } from '@hookform/resolvers/yup';
4
 import { yupResolver } from '@hookform/resolvers/yup';
49
   });
49
   });
50
 
50
 
51
   const onSubmit = data => {
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
   const auth = useSelector((state) => state.token)
74
   const auth = useSelector((state) => state.token)
57
-  // const queryClient = useQueryClient()
75
+  const queryClient = useQueryClient()
58
   let { visible, toggle } = props
76
   let { visible, toggle } = props
59
 
77
 
60
   const [open, setOpen] = React.useState(false);
78
   const [open, setOpen] = React.useState(false);
72
     }
90
     }
73
     setChecklist(temp.map( test => test.id) )
91
     setChecklist(temp.map( test => test.id) )
74
     setValue('tests', temp)
92
     setValue('tests', temp)
75
-    // setValue({...values, tests: temp})
76
   };
93
   };
77
 
94
 
78
   const getCategories = async () => {
95
   const getCategories = async () => {
110
         reset({...response.data, areadepto : areadeptoplz_id, fecha : new Date(fecha) , tests : temp_test  })
127
         reset({...response.data, areadepto : areadeptoplz_id, fecha : new Date(fecha) , tests : temp_test  })
111
       })
128
       })
112
       .catch(console.log)
129
       .catch(console.log)
113
-  },[visible])
130
+  },[visible, auth,reset])
114
 
131
 
115
   const changeTab = (_event, newValue) => setTab(newValue);
132
   const changeTab = (_event, newValue) => setTab(newValue);
116
 
133
 

+ 1 - 13
src/Pages/Puestos.jsx

88
     }
88
     }
89
   }, [edit, del, show])
89
   }, [edit, del, show])
90
 
90
 
91
+
91
   if(isLoading){
92
   if(isLoading){
92
     return(
93
     return(
93
       <Loading/>
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
   if (error) {
98
   if (error) {
109
     return (
99
     return (
110
       <Paper sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh' }}>
100
       <Paper sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh' }}>
114
       </Paper>
104
       </Paper>
115
     )
105
     )
116
   }
106
   }
117
-    */
118
-
119
   const total_items = Divide(result.data).length
107
   const total_items = Divide(result.data).length
120
 
108
 
121
   return (
109
   return (