|
@@ -1,7 +1,8 @@
|
1
|
1
|
import React, { useState, useCallback } from 'react';
|
2
|
2
|
import { Row, Col } from 'react-bootstrap'
|
3
|
3
|
|
4
|
|
-import toast, { Toaster } from 'react-hot-toast';
|
|
4
|
+import { Toaster } from 'react-hot-toast';
|
|
5
|
+// import toast, { Toaster } from 'react-hot-toast';
|
5
|
6
|
|
6
|
7
|
import {
|
7
|
8
|
ToggleButton, ToggleButtonGroup, Box,
|
|
@@ -12,7 +13,7 @@ import { ViewList as ViewListIcon, ViewModule as ViewModuleIcon, } from '@mui/ic
|
12
|
13
|
|
13
|
14
|
import { default as useAuth } from '../Auth/useAuth';
|
14
|
15
|
import { Service } from '../Utils/HTTP';
|
15
|
|
-// import { Divide } from '../Utils/Paginate';
|
|
16
|
+import { Divide } from '../Utils/Paginate';
|
16
|
17
|
|
17
|
18
|
import Express from '../Components/Modal/AgregarExpress';
|
18
|
19
|
import Manual from '../Components/Modal/AgregarManual';
|
|
@@ -34,81 +35,17 @@ export function Puestos() {
|
34
|
35
|
|
35
|
36
|
const auth = useAuth();
|
36
|
37
|
const token = auth.getToken();
|
|
38
|
+ const [page, setPage] = useState(1);
|
37
|
39
|
|
38
|
|
- const Complete = useCallback((status, message) => {
|
39
|
|
-
|
40
|
|
- if (!status) {
|
41
|
|
- return toast.error(message)
|
42
|
|
- }
|
43
|
|
-
|
44
|
|
- let rest = new Service("/plaza/getall")
|
45
|
|
- rest
|
46
|
|
- .get(token)
|
47
|
|
- .then(({ data }) => {
|
48
|
|
- return data;
|
49
|
|
- // let entries = data.map(e => {
|
50
|
|
- // return {
|
51
|
|
- // nombre: e.nombrepuesto,
|
52
|
|
- // description: e.notas,
|
53
|
|
- // id: e.id,
|
54
|
|
- // created: e.create_day,
|
55
|
|
- // data: e
|
56
|
|
- // };
|
57
|
|
- // })
|
58
|
|
- //setData(Divide(entries))
|
59
|
|
- })
|
60
|
|
- .catch((error) => {
|
61
|
|
- console.log('error fetching data ', error);
|
62
|
|
- })
|
63
|
|
-
|
64
|
|
- toast.success(message)
|
65
|
|
- },[token])
|
66
|
|
-
|
67
|
|
- const getAll = useCallback(async () => {
|
|
40
|
+ const getAll = async () => {
|
68
|
41
|
let rest = new Service("/plaza/getall")
|
69
|
42
|
let response = await rest.getQuery(token);
|
70
|
43
|
return response;
|
71
|
|
- },[token])
|
72
|
|
-
|
73
|
|
- useCallback(() => {
|
74
|
|
- let rest = new Service("/categoria/getAll")
|
75
|
|
- rest
|
76
|
|
- .get(token)
|
77
|
|
- .then(({ data }) => {
|
78
|
|
- console.log(data)
|
79
|
|
- setCategorias(data);
|
80
|
|
- })
|
81
|
|
- .catch((error) => {
|
82
|
|
- console.log('error fetching data ', error);
|
83
|
|
- return error;
|
84
|
|
- })
|
85
|
|
-
|
86
|
|
- },[token])
|
87
|
|
-
|
88
|
|
- const { isLoading, error, data } = useQuery('puestos', getAll);
|
89
|
|
- console.log( isLoading, error, data )
|
90
|
|
-
|
91
|
|
- const [page, setPage] = useState(1);
|
92
|
|
- const [categorias, setCategorias] = useState([]);
|
|
44
|
+ }
|
93
|
45
|
|
|
46
|
+ const { isLoading, error, data : result } = useQuery('puestos', getAll);
|
94
|
47
|
const changePage = useCallback((_, value) => setPage(value),[]);
|
95
|
|
-
|
96
|
|
- // useEffect(() => {
|
97
|
|
- // // let entries = data.map( e => {
|
98
|
|
- // // return {
|
99
|
|
- // // nombre : e.nombrepuesto,
|
100
|
|
- // // description : e.notas,
|
101
|
|
- // // id : e.id,
|
102
|
|
- // // created: e.create_day,
|
103
|
|
- // // data: e
|
104
|
|
- // // };
|
105
|
|
- // // })
|
106
|
|
- // // setData(Divide(entries))
|
107
|
|
- // }, [])
|
108
|
|
-
|
109
|
|
- // const [alignment, setAlignment] = React.useState('list');
|
110
|
48
|
const [alignment, setAlignment] = React.useState('grid');
|
111
|
|
-
|
112
|
49
|
const handleChange = useCallback((_event, newAlignment) => setAlignment(newAlignment),[])
|
113
|
50
|
|
114
|
51
|
const children = [
|
|
@@ -127,15 +64,21 @@ export function Puestos() {
|
127
|
64
|
};
|
128
|
65
|
|
129
|
66
|
let [puesto, setPuesto] = React.useState(false);
|
130
|
|
-
|
131
|
67
|
let [manual, setManual] = React.useState(false);
|
132
|
68
|
let [expres, setExpress] = React.useState(false);
|
133
|
|
-
|
134
|
69
|
let [edit, setEdit] = React.useState(false);
|
135
|
70
|
let [del, setDelete] = React.useState(false);
|
136
|
71
|
let [show, setShow] = React.useState(false);
|
137
|
72
|
|
138
|
|
- if (isLoading) return <Loading />
|
|
73
|
+ if (isLoading){
|
|
74
|
+ return(
|
|
75
|
+ <Paper sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh' }}>
|
|
76
|
+ <main id="loading_or_content">
|
|
77
|
+ <Loading />
|
|
78
|
+ </main>
|
|
79
|
+ </Paper>
|
|
80
|
+ )
|
|
81
|
+ }
|
139
|
82
|
|
140
|
83
|
if (error) {
|
141
|
84
|
return (
|
|
@@ -147,6 +90,8 @@ export function Puestos() {
|
147
|
90
|
)
|
148
|
91
|
}
|
149
|
92
|
|
|
93
|
+ const total_items = Divide(result.data).length
|
|
94
|
+
|
150
|
95
|
return (
|
151
|
96
|
<div className="content-section">
|
152
|
97
|
<div className="main">
|
|
@@ -182,10 +127,8 @@ export function Puestos() {
|
182
|
127
|
<Row>
|
183
|
128
|
<GridMode
|
184
|
129
|
showing={alignment}
|
185
|
|
- data={[]}
|
186
|
|
- // data={data}
|
187
|
|
- index={0}
|
188
|
|
- // index={page - 1}
|
|
130
|
+ data={Divide( result.data )}
|
|
131
|
+ index={page - 1}
|
189
|
132
|
setPuesto={setPuesto}
|
190
|
133
|
setEdit={setEdit}
|
191
|
134
|
setDelete={setDelete}
|
|
@@ -197,10 +140,8 @@ export function Puestos() {
|
197
|
140
|
<Row>
|
198
|
141
|
<ListMode
|
199
|
142
|
showing={alignment}
|
200
|
|
- data={[]}
|
201
|
|
- // data={data}
|
202
|
|
- // index={page - 1}
|
203
|
|
- index={0}
|
|
143
|
+ data={Divide( result.data )}
|
|
144
|
+ index={page - 1}
|
204
|
145
|
setPuesto={setPuesto}
|
205
|
146
|
setEdit={setEdit}
|
206
|
147
|
setDelete={setDelete}
|
|
@@ -219,23 +160,19 @@ export function Puestos() {
|
219
|
160
|
siblingCount={2}
|
220
|
161
|
boundaryCount={2}
|
221
|
162
|
shape='rounded'
|
222
|
|
- // count={data.length}
|
223
|
|
- count={0}
|
|
163
|
+ count={total_items}
|
224
|
164
|
page={page}
|
225
|
165
|
onChange={changePage}
|
226
|
166
|
/>
|
227
|
|
-
|
228
|
|
-
|
229
|
167
|
</div>
|
230
|
|
-
|
231
|
168
|
</Paper>
|
232
|
169
|
</Box>
|
233
|
170
|
</div>
|
234
|
171
|
|
235
|
172
|
<Express setExpress={setExpress} visible={expres} onClose={() => setExpress(false)} />
|
236
|
|
- <Manual categorias={categorias} Complete={Complete} visible={manual} onClose={() => setManual(false)} />
|
|
173
|
+ <Manual visible={manual} onClose={() => setManual(false)} />
|
237
|
174
|
|
238
|
|
- <Editar categorias={categorias} Complete={Complete} puesto={puesto} visible={edit} onClose={() => setEdit(false)} />
|
|
175
|
+ <Editar puesto={puesto} visible={edit} onClose={() => setEdit(false)} />
|
239
|
176
|
<Eliminar puesto={puesto} visible={del} onClose={() => setDelete(false)} />
|
240
|
177
|
<Mostrar puesto={puesto} visible={show} onClose={() => setShow(false)} />
|
241
|
178
|
|