|
@@ -2,7 +2,13 @@ import React, { useState, useEffect } from 'react';
|
2
|
2
|
import { Row, Col } from 'react-bootstrap'
|
3
|
3
|
import toast, { Toaster } from 'react-hot-toast';
|
4
|
4
|
|
5
|
|
-import { ToggleButton, ToggleButtonGroup, Box, Paper } from '@mui/material';
|
|
5
|
+import {
|
|
6
|
+ ToggleButton,
|
|
7
|
+ ToggleButtonGroup,
|
|
8
|
+ Box,
|
|
9
|
+ Paper,
|
|
10
|
+ Pagination,
|
|
11
|
+} from '@mui/material';
|
6
|
12
|
|
7
|
13
|
import { ViewList as ViewListIcon, ViewModule as ViewModuleIcon, } from '@mui/icons-material';
|
8
|
14
|
|
|
@@ -24,11 +30,29 @@ import { Add as AddIcon, } from '@mui/icons-material/'
|
24
|
30
|
const Success = () => toast.success('Plaza Agregada!!')
|
25
|
31
|
const Error = () => toast.error('Ups creo que ocurrio un error, intentalo nuevamente')
|
26
|
32
|
|
|
33
|
+function Divide(arregloOriginal){
|
|
34
|
+ const LONGITUD_PEDAZOS = 9;
|
|
35
|
+ let arregloDeArreglos = [];
|
|
36
|
+ for (let i = 0; i < arregloOriginal.length; i += LONGITUD_PEDAZOS) {
|
|
37
|
+ let pedazo = arregloOriginal.slice(i, i + LONGITUD_PEDAZOS);
|
|
38
|
+ arregloDeArreglos.push(pedazo);
|
|
39
|
+ }
|
|
40
|
+ return arregloDeArreglos
|
|
41
|
+}
|
|
42
|
+
|
27
|
43
|
export function Puestos() {
|
28
|
44
|
|
29
|
45
|
const auth = useAuth();
|
30
|
|
- const [data, setData] = useState({});
|
|
46
|
+ const [data, setData] = useState([]);
|
|
47
|
+ const [page, setPage] = useState(1);
|
31
|
48
|
const token = auth.getToken();
|
|
49
|
+
|
|
50
|
+ const changePage = ( _ , value) => {
|
|
51
|
+ let page_numer = value;
|
|
52
|
+ // let divided = Divide(data)
|
|
53
|
+ setPage(page_numer);
|
|
54
|
+ // setData(divided)
|
|
55
|
+ };
|
32
|
56
|
|
33
|
57
|
useEffect(() => {
|
34
|
58
|
|
|
@@ -46,7 +70,7 @@ export function Puestos() {
|
46
|
70
|
data: e
|
47
|
71
|
};
|
48
|
72
|
})
|
49
|
|
- setData(entries)
|
|
73
|
+ setData(Divide(entries))
|
50
|
74
|
})
|
51
|
75
|
.catch((error) => {
|
52
|
76
|
console.log('error fetching data ', error );
|
|
@@ -54,12 +78,10 @@ export function Puestos() {
|
54
|
78
|
|
55
|
79
|
},[token])
|
56
|
80
|
|
57
|
|
- const [alignment, setAlignment] = React.useState('list');
|
|
81
|
+ // const [alignment, setAlignment] = React.useState('list');
|
|
82
|
+ const [alignment, setAlignment] = React.useState('grid');
|
58
|
83
|
|
59
|
|
- const handleChange = (_event, newAlignment) => {
|
60
|
|
- console.log("new alignment :: ", newAlignment );
|
61
|
|
- setAlignment(newAlignment)
|
62
|
|
- } ;
|
|
84
|
+ const handleChange = (_event, newAlignment) => setAlignment(newAlignment)
|
63
|
85
|
|
64
|
86
|
const children = [
|
65
|
87
|
<ToggleButton value="list" key="list">
|
|
@@ -78,7 +100,7 @@ export function Puestos() {
|
78
|
100
|
|
79
|
101
|
let [puesto, setPuesto] = React.useState(false);
|
80
|
102
|
|
81
|
|
- let [manual, setManual] = React.useState(true);
|
|
103
|
+ let [manual, setManual] = React.useState(false);
|
82
|
104
|
let [expres, setExpress] = React.useState(false);
|
83
|
105
|
|
84
|
106
|
let [edit, setEdit] = React.useState(false);
|
|
@@ -89,7 +111,7 @@ export function Puestos() {
|
89
|
111
|
<div className="content-section">
|
90
|
112
|
<div className="main">
|
91
|
113
|
<Box sx={{ width: '100%' }}>
|
92
|
|
- <Paper sx={{ width: '100%', mb: 2, padding : 2, height: '95vh' }}>
|
|
114
|
+ <Paper sx={{ width: '100%', mb: 2, padding : 2, height: '100%', minHeight:'95vh' }}>
|
93
|
115
|
|
94
|
116
|
<Row style={{paddingBottom : 15}}>
|
95
|
117
|
<Col md="2" sm="2" xs="2">
|
|
@@ -118,6 +140,7 @@ export function Puestos() {
|
118
|
140
|
<Row>
|
119
|
141
|
<GridMode
|
120
|
142
|
data={data}
|
|
143
|
+ index={page - 1}
|
121
|
144
|
setPuesto={setPuesto}
|
122
|
145
|
setEdit={setEdit}
|
123
|
146
|
setDelete={setDelete}
|
|
@@ -129,6 +152,7 @@ export function Puestos() {
|
129
|
152
|
<Row>
|
130
|
153
|
<ListMode
|
131
|
154
|
data={data}
|
|
155
|
+ index={page -1}
|
132
|
156
|
setPuesto={setPuesto}
|
133
|
157
|
setEdit={setEdit}
|
134
|
158
|
setDelete={setDelete}
|
|
@@ -137,6 +161,21 @@ export function Puestos() {
|
137
|
161
|
</Row>
|
138
|
162
|
</div>
|
139
|
163
|
|
|
164
|
+ <Pagination
|
|
165
|
+ sx={{
|
|
166
|
+ "& ul" :{
|
|
167
|
+ "padding-top" : "20px",
|
|
168
|
+ "justify-content": "center"
|
|
169
|
+ }
|
|
170
|
+ }}
|
|
171
|
+ siblingCount={2}
|
|
172
|
+ boundaryCount={2}
|
|
173
|
+ shape='rounded'
|
|
174
|
+ count={data.length}
|
|
175
|
+ page={page}
|
|
176
|
+ onChange={changePage}
|
|
177
|
+ />
|
|
178
|
+
|
140
|
179
|
</Paper>
|
141
|
180
|
</Box>
|
142
|
181
|
|