Browse Source

useQuery start config

amenpunk 2 years ago
parent
commit
42f3d96e1d

+ 7 - 0
src/App.css

240
     z-index : 999;
240
     z-index : 999;
241
 }
241
 }
242
 
242
 
243
+#loading_or_content{
244
+    display: grid;
245
+    min-height:100vh;
246
+    place-content:center;
247
+}
248
+
249
+

+ 8 - 6
src/App.js

6
 import { Container } from 'react-bootstrap'
6
 import { Container } from 'react-bootstrap'
7
 import { AuthProvider } from './Auth/AuthProvider'
7
 import { AuthProvider } from './Auth/AuthProvider'
8
 import { QueryClient, QueryClientProvider } from 'react-query'
8
 import { QueryClient, QueryClientProvider } from 'react-query'
9
+import { ReactQueryDevtools } from 'react-query/devtools'
9
 
10
 
10
 import Routes from './Components/Routes'
11
 import Routes from './Components/Routes'
11
 const queryClient = new QueryClient()
12
 const queryClient = new QueryClient()
12
 
13
 
13
-const GATEWAY =  {
14
-    dev : {
15
-        API : 'http://localhost:8000',
14
+const GATEWAY = {
15
+    dev: {
16
+        API: 'http://localhost:8000',
16
     },
17
     },
17
-    pro : {
18
-        API : '',
18
+    pro: {
19
+        API: '',
19
     }
20
     }
20
 }
21
 }
21
 
22
 
28
                 <AuthProvider>
29
                 <AuthProvider>
29
                     <API_GATEWAY.Provider value={GATEWAY.dev}>
30
                     <API_GATEWAY.Provider value={GATEWAY.dev}>
30
                         <Container fluid>
31
                         <Container fluid>
31
-                            <Routes/>
32
+                            <Routes />
32
                         </Container>
33
                         </Container>
33
                     </API_GATEWAY.Provider>
34
                     </API_GATEWAY.Provider>
34
                 </AuthProvider>
35
                 </AuthProvider>
35
             </Router>
36
             </Router>
37
+            <ReactQueryDevtools initialIsOpen={false} />
36
         </QueryClientProvider>
38
         </QueryClientProvider>
37
     );
39
     );
38
 }
40
 }

+ 21 - 0
src/Components/Generics/Error.jsx

1
+import { Col, Row } from 'react-bootstrap'
2
+
3
+import RoboError from '../../Images/robo_error.png'
4
+import PriorityHighIcon from '@mui/icons-material/PriorityHigh';
5
+
6
+export function ErrorMessage() {
7
+    return (
8
+        <div>
9
+            <Row className="row" style={{flexDirection:'row'}}>
10
+                <Col md="6">
11
+                    <img src={RoboError} alt="robo error" />
12
+                </Col>
13
+                <Col md="6">
14
+                    <h1>Upss... <PriorityHighIcon fontSize="large" style={{ fontSize:95 }} /></h1>
15
+                    <h3>Algo salió mal..</h3>
16
+                    <p>Lo sentimos porfavor intentalo  nuevamente</p>
17
+                </Col>
18
+            </Row>
19
+        </div>
20
+    )
21
+}

+ 24 - 0
src/Components/Generics/loading.jsx

1
+import React from "react";
2
+import '../../Css/loading.css'
3
+
4
+export function Loading( props ) {
5
+
6
+    let { type } = props
7
+
8
+    let types = [
9
+        "dot-elastic","dot-flashing", "dot-collision", "dot-revolution", "dot-carousel", "dot-fire",
10
+        "dot-spin","dot-falling", "dot-stretching"
11
+    ];
12
+
13
+    console.log(type, types)
14
+
15
+    return(
16
+        <div className="loading_or_content">
17
+            <div className="snippet" data-title=".dot-pulse">
18
+                <div className="stage">
19
+                    <div className="dot-pulse"></div>
20
+                </div>
21
+            </div>
22
+        </div>
23
+    )
24
+}

+ 3 - 1
src/Components/Modal/AgregarExpress.js

7
     link : Yup.string().required('El enlace es requerido').url("Debes agregar un enlace válido, recurda iniciar con http o https ").min(5).max(190),
7
     link : Yup.string().required('El enlace es requerido').url("Debes agregar un enlace válido, recurda iniciar con http o https ").min(5).max(190),
8
 })
8
 })
9
 
9
 
10
-export  default function Express (props) {
10
+function Express (props) {
11
 
11
 
12
     let { visible, onClose, success } = props
12
     let { visible, onClose, success } = props
13
 
13
 
52
         </Modal>
52
         </Modal>
53
     )
53
     )
54
 }
54
 }
55
+
56
+export default React.memo(Express)

+ 47 - 46
src/Components/Modal/AgregarManual.js

1
-import React from 'react';
1
+import React, { memo } from 'react';
2
 import * as Yup from 'yup';
2
 import * as Yup from 'yup';
3
 import { useFormik, Form, FormikProvider } from 'formik';
3
 import { useFormik, Form, FormikProvider } from 'formik';
4
 import { Modal } from 'react-bootstrap'
4
 import { Modal } from 'react-bootstrap'
5
 
5
 
6
 import DateFnsUtils from '@date-io/date-fns';
6
 import DateFnsUtils from '@date-io/date-fns';
7
-import { DesktopDatePicker,LocalizationProvider } from '@mui/lab';
7
+import { DesktopDatePicker, LocalizationProvider } from '@mui/lab';
8
 
8
 
9
-import {  
10
-    Button, Stack, TextField, MenuItem,FormControl, InputLabel, Select,
9
+import {
10
+    Button, Stack, TextField, MenuItem, FormControl, InputLabel, Select,
11
     Backdrop, CircularProgress
11
     Backdrop, CircularProgress
12
 } from '@mui/material';
12
 } from '@mui/material';
13
 
13
 
14
 import { Service } from '../../Utils/HTTP';
14
 import { Service } from '../../Utils/HTTP';
15
-import  useAuth from '../../Auth/useAuth';
15
+import useAuth from '../../Auth/useAuth';
16
 
16
 
17
 
17
 
18
-export default function Manual ( props ) {
18
+function Manual(props) {
19
 
19
 
20
     const NewPlazaSchema = Yup.object().shape({
20
     const NewPlazaSchema = Yup.object().shape({
21
-        nombrepuesto : Yup.string().required('El nombre es requerido').min(5, "El nombre del  puesto debe ser mayor a 5 caracteres").max(100),
22
-        puestosuperior : Yup.number("El puesto superior debe ser un número").required("El puesto es requerido"),
23
-        aredepto : Yup.number().required('Escoge alguna área'),
24
-        fecha : Yup.date("Ingresa una fecha válida"),
25
-        notas : Yup.string("Ingresa una nota válida").min(5).max(150),
21
+        nombrepuesto: Yup.string().required('El nombre es requerido').min(5, "El nombre del  puesto debe ser mayor a 5 caracteres").max(100),
22
+        puestosuperior: Yup.number("El puesto superior debe ser un número").required("El puesto es requerido"),
23
+        aredepto: Yup.number().required('Escoge alguna área'),
24
+        fecha: Yup.date("Ingresa una fecha válida"),
25
+        notas: Yup.string("Ingresa una nota válida").min(5).max(150),
26
     })
26
     })
27
-    
27
+
28
     const [departamento, setDepartamento] = React.useState('');
28
     const [departamento, setDepartamento] = React.useState('');
29
     const [open, setOpen] = React.useState(false);
29
     const [open, setOpen] = React.useState(false);
30
     const handleClose = () => false
30
     const handleClose = () => false
38
     const auth = useAuth();
38
     const auth = useAuth();
39
     const token = auth.getToken();
39
     const token = auth.getToken();
40
 
40
 
41
-    let { visible, onClose, Complete, categorias  } = props
41
+    let { visible, onClose, Complete, categorias } = props
42
 
42
 
43
     const formik = useFormik({
43
     const formik = useFormik({
44
         initialValues: {
44
         initialValues: {
48
             fecha: date,
48
             fecha: date,
49
             notas: "",
49
             notas: "",
50
         },
50
         },
51
-        onSubmit: ( fields, { resetForm } ) => {
51
+        onSubmit: (fields, { resetForm }) => {
52
 
52
 
53
             setOpen(true)
53
             setOpen(true)
54
-            fields['fecha'] =  new Date(fields.fecha).toISOString();
54
+            fields['fecha'] = new Date(fields.fecha).toISOString();
55
             fields['areadeptoplz_id'] = 1;
55
             fields['areadeptoplz_id'] = 1;
56
             fields['id'] = -1;
56
             fields['id'] = -1;
57
 
57
 
58
             let Rest = new Service('/plaza/save');
58
             let Rest = new Service('/plaza/save');
59
 
59
 
60
             Rest
60
             Rest
61
-            .post( fields, token )
62
-            .then( _ => {
63
-                resetForm();
64
-                Complete(true, "Puesto agregado exitosamente");
65
-                onClose();
66
-                setOpen(false)
67
-            })
68
-            .catch(err => {
69
-                console.error(err)
70
-                Complete(false,"Ocurrio un error intentalo nuevamente");
71
-                setOpen(false)
72
-            })
61
+                .post(fields, token)
62
+                .then(_ => {
63
+                    resetForm();
64
+                    Complete(true, "Puesto agregado exitosamente");
65
+                    onClose();
66
+                    setOpen(false)
67
+                })
68
+                .catch(err => {
69
+                    console.error(err)
70
+                    Complete(false, "Ocurrio un error intentalo nuevamente");
71
+                    setOpen(false)
72
+                })
73
 
73
 
74
         },
74
         },
75
         validationSchema: NewPlazaSchema,
75
         validationSchema: NewPlazaSchema,
76
     });
76
     });
77
 
77
 
78
-    const { errors, touched, handleSubmit, getFieldProps} = formik;
78
+    const { errors, touched, handleSubmit, getFieldProps } = formik;
79
 
79
 
80
     return (
80
     return (
81
 
81
 
82
         <Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered show={visible} onHide={onClose}>
82
         <Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered show={visible} onHide={onClose}>
83
             <Modal.Header>
83
             <Modal.Header>
84
-                <button onClick={onClose}  type="button" className="close" data-dismiss="modal">&times;</button>
85
-                <h4 className="modal-title" style={{color : '#252525'}}>Agregar plaza</h4>
84
+                <button onClick={onClose} type="button" className="close" data-dismiss="modal">&times;</button>
85
+                <h4 className="modal-title" style={{ color: '#252525' }}>Agregar plaza</h4>
86
             </Modal.Header>
86
             </Modal.Header>
87
             <Modal.Body className="modal-body">
87
             <Modal.Body className="modal-body">
88
 
88
 
89
-                <FormikProvider style={{ padding : 25 }} value={formik}>
89
+                <FormikProvider style={{ padding: 25 }} value={formik}>
90
                     <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
90
                     <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
91
                         <Stack spacing={3}>
91
                         <Stack spacing={3}>
92
 
92
 
120
                                         {...getFieldProps('aredepto')}
120
                                         {...getFieldProps('aredepto')}
121
                                         error={Boolean(touched.aredepto && errors.aredepto)} >
121
                                         error={Boolean(touched.aredepto && errors.aredepto)} >
122
                                         {
122
                                         {
123
-                                        categorias ?
124
-                                            categorias.map( cate => {
125
-                                                return (
126
-                                                    <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
127
-                                                )
128
-                                            })
129
-                                            : <MenuItem>Null</MenuItem>
130
-                                    }
123
+                                            categorias ?
124
+                                                categorias.map(cate => {
125
+                                                    return (
126
+                                                        <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
127
+                                                    )
128
+                                                })
129
+                                                : <MenuItem>Null</MenuItem>
130
+                                        }
131
                                     </Select>
131
                                     </Select>
132
                                 </FormControl>
132
                                 </FormControl>
133
 
133
 
134
 
134
 
135
-                                <LocalizationProvider 
135
+                                <LocalizationProvider
136
                                     dateAdapter={DateFnsUtils}>
136
                                     dateAdapter={DateFnsUtils}>
137
                                     <DesktopDatePicker
137
                                     <DesktopDatePicker
138
                                         label="Fecha Creación"
138
                                         label="Fecha Creación"
141
                                         {...getFieldProps('fecha')}
141
                                         {...getFieldProps('fecha')}
142
                                         value={date}
142
                                         value={date}
143
                                         onChange={setDate}
143
                                         onChange={setDate}
144
-                                        renderInput={(params) => 
145
-                                            <TextField 
144
+                                        renderInput={(params) =>
145
+                                            <TextField
146
                                                 disabled={true}
146
                                                 disabled={true}
147
                                                 label="Fecha Creación"
147
                                                 label="Fecha Creación"
148
                                                 fullWidth
148
                                                 fullWidth
149
-                                                {...params} 
149
+                                                {...params}
150
                                             />}
150
                                             />}
151
                                     />
151
                                     />
152
                                 </LocalizationProvider>
152
                                 </LocalizationProvider>
165
                                     {...getFieldProps('notas')}
165
                                     {...getFieldProps('notas')}
166
                                     error={Boolean(touched.notas && errors.notas)}
166
                                     error={Boolean(touched.notas && errors.notas)}
167
                                     helperText={touched.notas && errors.notas}
167
                                     helperText={touched.notas && errors.notas}
168
-                                    />
168
+                                />
169
                             </Stack>
169
                             </Stack>
170
                         </Stack>
170
                         </Stack>
171
 
171
 
173
                         <Modal.Footer>
173
                         <Modal.Footer>
174
                             <Button
174
                             <Button
175
                                 type="submit"
175
                                 type="submit"
176
-                                className="registerBtn" 
176
+                                className="registerBtn"
177
                                 variant="contained"
177
                                 variant="contained"
178
                                 sx={{ mt: 1, mr: 1 }} >
178
                                 sx={{ mt: 1, mr: 1 }} >
179
                                 {'Guardar'}
179
                                 {'Guardar'}
187
                 sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
187
                 sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
188
                 open={open}
188
                 open={open}
189
                 onClick={handleClose} >
189
                 onClick={handleClose} >
190
-            <CircularProgress color="inherit" />
190
+                <CircularProgress color="inherit" />
191
             </Backdrop>
191
             </Backdrop>
192
 
192
 
193
         </Modal>
193
         </Modal>
194
     )
194
     )
195
 }
195
 }
196
+export default memo(Manual);

+ 5 - 2
src/Components/Modal/EditPlaza.js

1
-import React, { useEffect } from 'react';
1
+import React, { useEffect, memo } from 'react';
2
 import * as Yup from 'yup';
2
 import * as Yup from 'yup';
3
 import { useFormik, Form, FormikProvider } from 'formik';
3
 import { useFormik, Form, FormikProvider } from 'formik';
4
 import { Modal } from 'react-bootstrap'
4
 import { Modal } from 'react-bootstrap'
14
 import { Service } from '../../Utils/HTTP';
14
 import { Service } from '../../Utils/HTTP';
15
 import  useAuth from '../../Auth/useAuth';
15
 import  useAuth from '../../Auth/useAuth';
16
 
16
 
17
-export default function Edit(props) {
17
+function Edit(props) {
18
 
18
 
19
     const NewPlazaSchema = Yup.object().shape({
19
     const NewPlazaSchema = Yup.object().shape({
20
         id: Yup.number(),
20
         id: Yup.number(),
207
         </Modal>
207
         </Modal>
208
     )
208
     )
209
 }
209
 }
210
+
211
+
212
+export default memo(Edit);

+ 5 - 2
src/Components/Modal/EliminarPlaza.js

1
-import React from 'react';
1
+import React, { memo } from 'react';
2
 import { Modal, Row, Col } from 'react-bootstrap'
2
 import { Modal, Row, Col } from 'react-bootstrap'
3
 
3
 
4
-export default function Eliminar(props) {
4
+export function Eliminar(props) {
5
 
5
 
6
     let { visible, onClose, puesto } = props
6
     let { visible, onClose, puesto } = props
7
 
7
 
35
         </Modal>
35
         </Modal>
36
     )
36
     )
37
 }
37
 }
38
+
39
+
40
+export default memo(Eliminar);

+ 4 - 2
src/Components/Modal/MostrarPlaza.js

1
-import React from 'react';
1
+import React, {memo} from 'react';
2
 import { Modal, Col, Row } from 'react-bootstrap'
2
 import { Modal, Col, Row } from 'react-bootstrap'
3
 import QA from '../../Images/puesto.jpg'
3
 import QA from '../../Images/puesto.jpg'
4
 
4
 
5
-export default function Mostrar(props) {
5
+function Mostrar(props) {
6
 
6
 
7
     let { visible, onClose, puesto } = props
7
     let { visible, onClose, puesto } = props
8
 
8
 
41
         </Modal>
41
         </Modal>
42
     )
42
     )
43
 }
43
 }
44
+
45
+export default memo(Mostrar);

File diff suppressed because it is too large
+ 1178 - 0
src/Css/loading.css


BIN
src/Images/robo_error.png


+ 133 - 107
src/Pages/Puestos.jsx

1
-import React, { useState, useEffect }  from 'react';
1
+import React, { useState, useCallback } from 'react';
2
 import { Row, Col } from 'react-bootstrap'
2
 import { Row, Col } from 'react-bootstrap'
3
 
3
 
4
 import toast, { Toaster } from 'react-hot-toast';
4
 import toast, { Toaster } from 'react-hot-toast';
5
 
5
 
6
-import { 
6
+import {
7
     ToggleButton, ToggleButtonGroup, Box,
7
     ToggleButton, ToggleButtonGroup, Box,
8
     Paper, Pagination,
8
     Paper, Pagination,
9
 } from '@mui/material';
9
 } from '@mui/material';
12
 
12
 
13
 import { default as useAuth } from '../Auth/useAuth';
13
 import { default as useAuth } from '../Auth/useAuth';
14
 import { Service } from '../Utils/HTTP';
14
 import { Service } from '../Utils/HTTP';
15
-import { Divide } from '../Utils/Paginate';
15
+// import { Divide } from '../Utils/Paginate';
16
 
16
 
17
 import Express from '../Components/Modal/AgregarExpress';
17
 import Express from '../Components/Modal/AgregarExpress';
18
 import Manual from '../Components/Modal/AgregarManual';
18
 import Manual from '../Components/Modal/AgregarManual';
25
 import { GridMode } from '../Components/Puestos/GridMode'
25
 import { GridMode } from '../Components/Puestos/GridMode'
26
 import { Add as AddIcon, } from '@mui/icons-material/'
26
 import { Add as AddIcon, } from '@mui/icons-material/'
27
 
27
 
28
+import { Loading } from '../Components/Generics/loading'
29
+import { ErrorMessage } from '../Components/Generics/Error'
30
+
31
+import { useQuery } from 'react-query';
28
 
32
 
29
 export function Puestos() {
33
 export function Puestos() {
30
 
34
 
31
-    const Complete =  (status, message) => {
32
-        console.log(status, message);
35
+    const auth = useAuth();
36
+    const token = auth.getToken();
33
 
37
 
34
-        if(!status){
38
+    const Complete = useCallback((status, message) => {
39
+
40
+        if (!status) {
35
             return toast.error(message)
41
             return toast.error(message)
36
         }
42
         }
37
 
43
 
38
         let rest = new Service("/plaza/getall")
44
         let rest = new Service("/plaza/getall")
39
         rest
45
         rest
40
             .get(token)
46
             .get(token)
41
-            .then(({data}) => {
42
-                let entries = data.map( e => {
43
-                    return {
44
-                        nombre : e.nombrepuesto,
45
-                        description : e.notas,
46
-                        id : e.id,
47
-                        created: e.create_day,
48
-                        data: e
49
-                    };
50
-                })
51
-                setData(Divide(entries))
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))
52
             })
59
             })
53
             .catch((error) => {
60
             .catch((error) => {
54
-                console.log('error fetching data  ', error );
61
+                console.log('error fetching data  ', error);
55
             })
62
             })
56
 
63
 
57
         toast.success(message)
64
         toast.success(message)
58
-    } 
59
-
60
-    const auth = useAuth();
61
-
62
-    const [data, setData] = useState([]);
63
-    const [page, setPage] = useState(1);
64
-    const [categorias, setCategorias] = useState([]);
65
-
66
-    const token = auth.getToken();
67
-
68
-    const changePage = ( _ , value) => setPage(value);
69
-
70
-    useEffect(() => {
65
+    },[token])
71
 
66
 
67
+    const getAll = useCallback(async () => {
72
         let rest = new Service("/plaza/getall")
68
         let rest = new Service("/plaza/getall")
69
+        let response =  await rest.getQuery(token); 
70
+        return response;
71
+    },[token])
72
+
73
+    useCallback(() => {
74
+        let rest = new Service("/categoria/getAll")
73
         rest
75
         rest
74
             .get(token)
76
             .get(token)
75
-            .then(({data}) => {
76
-                let entries = data.map( e => {
77
-                    return {
78
-                        nombre : e.nombrepuesto,
79
-                        description : e.notas,
80
-                        id : e.id,
81
-                        created: e.create_day,
82
-                        data: e
83
-                    };
84
-                })
85
-                setData(Divide(entries))
86
-            })
87
-            .catch((error) => {
88
-                console.log('error fetching data  ', error );
89
-            })
90
-    
91
-        rest = new Service("/categoria/getAll")
92
-        rest
93
-            .get(token)
94
-            .then(({data}) => {
95
-                setCategorias(data)
77
+            .then(({ data }) => {
78
+                console.log(data)
79
+                setCategorias(data);
96
             })
80
             })
97
             .catch((error) => {
81
             .catch((error) => {
98
-                console.log('error fetching data  ', error );
82
+                console.log('error fetching data  ', error);
83
+                return error;
99
             })
84
             })
100
 
85
 
101
-
102
     },[token])
86
     },[token])
103
 
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([]);
93
+
94
+    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
+
104
     // const [alignment, setAlignment] = React.useState('list');
109
     // const [alignment, setAlignment] = React.useState('list');
105
     const [alignment, setAlignment] = React.useState('grid');
110
     const [alignment, setAlignment] = React.useState('grid');
106
 
111
 
107
-    const handleChange = (_event, newAlignment) => setAlignment(newAlignment)
112
+    const handleChange = useCallback((_event, newAlignment) => setAlignment(newAlignment),[])
108
 
113
 
109
     const children = [
114
     const children = [
110
         <ToggleButton value="list" key="list">
115
         <ToggleButton value="list" key="list">
111
             <ViewListIcon />
116
             <ViewListIcon />
112
         </ToggleButton>,
117
         </ToggleButton>,
113
         <ToggleButton value="grid" key="grid">
118
         <ToggleButton value="grid" key="grid">
114
-            <ViewModuleIcon/>
119
+            <ViewModuleIcon />
115
         </ToggleButton>,
120
         </ToggleButton>,
116
     ];
121
     ];
117
 
122
 
130
     let [del, setDelete] = React.useState(false);
135
     let [del, setDelete] = React.useState(false);
131
     let [show, setShow] = React.useState(false);
136
     let [show, setShow] = React.useState(false);
132
 
137
 
138
+    if (isLoading) return <Loading />
139
+
140
+    if (error) {
141
+        return (
142
+            <Paper sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh' }}>
143
+                <main id="loading_or_content">
144
+                    <ErrorMessage/>
145
+                </main>
146
+            </Paper>
147
+        )
148
+    }
149
+
133
     return (
150
     return (
134
         <div className="content-section">
151
         <div className="content-section">
135
             <div className="main">
152
             <div className="main">
136
                 <Box sx={{}}>
153
                 <Box sx={{}}>
137
-                    <Paper sx={{ mb: 2, padding : 2, height: '100%', minHeight:'95vh' }}>
154
+                    <Paper sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh' }}>
138
 
155
 
139
-                        <Row style={{paddingBottom : 15}}>
156
+                        <Row style={{ paddingBottom: 15 }}>
140
                             <Col md="2" sm="2" xs="2">
157
                             <Col md="2" sm="2" xs="2">
141
                                 <div className="breadcrumb-header">
158
                                 <div className="breadcrumb-header">
142
-                                    <Box sx={{ float : 'left',display: 'flex', flexDirection: 'column', alignItems: 'center', '& > :not(style) + :not(style)': { mt: 2 }, }} >
159
+                                    <Box sx={{ float: 'left', display: 'flex', flexDirection: 'column', alignItems: 'center', '& > :not(style) + :not(style)': { mt: 2 }, }} >
143
                                         <ToggleButtonGroup size="small" {...control}>
160
                                         <ToggleButtonGroup size="small" {...control}>
144
                                             {children}
161
                                             {children}
145
                                         </ToggleButtonGroup>
162
                                         </ToggleButtonGroup>
148
                             </Col>
165
                             </Col>
149
                             <Col md="10" sm='10' xs="10">
166
                             <Col md="10" sm='10' xs="10">
150
                                 <div className="add_producto">
167
                                 <div className="add_producto">
151
-                                    <div onClick={() => setManual(true) } className="btn_add_producto"> 
152
-                                        <span className="btn_plaza_common" >Agregar manual <AddIcon fontSize="small"/></span> 
168
+                                    <div onClick={() => setManual(true)} className="btn_add_producto">
169
+                                        <span className="btn_plaza_common" >Agregar manual <AddIcon fontSize="small" /></span>
153
                                     </div>
170
                                     </div>
154
                                 </div>
171
                                 </div>
155
-                                <div onClick={() => setExpress(true) } className="add_producto">
156
-                                    <div className="btn_add_producto"> 
157
-                                        <span className="btn_plaza_common">Agregar express <AddIcon fontSize="small"/></span> 
172
+                                <div onClick={() => setExpress(true)} className="add_producto">
173
+                                    <div className="btn_add_producto">
174
+                                        <span className="btn_plaza_common">Agregar express <AddIcon fontSize="small" /></span>
158
                                     </div>
175
                                     </div>
159
                                 </div>
176
                                 </div>
160
                             </Col>
177
                             </Col>
161
                         </Row>
178
                         </Row>
162
-                        <div className={`main_productos ${ alignment === 'grid' ? 'activar_vista' : 'desactivar_vista'  }`} id="grid_view">
163
-                            <Row>
164
-                                <GridMode
165
-                                    showing={alignment}
166
-                                    data={data}
167
-                                    index={page - 1}
168
-                                    setPuesto={setPuesto}
169
-                                    setEdit={setEdit}
170
-                                    setDelete={setDelete}
171
-                                    setShow={setShow}
179
+
180
+                        <div >
181
+                            <div className={`main_productos ${alignment === 'grid' ? 'activar_vista' : 'desactivar_vista'}`} id="grid_view">
182
+                                <Row>
183
+                                    <GridMode
184
+                                        showing={alignment}
185
+                                        data={[]}
186
+                                        // data={data}
187
+                                        index={0}
188
+                                        // index={page - 1}
189
+                                        setPuesto={setPuesto}
190
+                                        setEdit={setEdit}
191
+                                        setDelete={setDelete}
192
+                                        setShow={setShow}
172
                                     />
193
                                     />
173
-                            </Row>
174
-                        </div>
175
-                        <div className={`main_list_products ${alignment === 'list' ?  'activar_vista' : 'desactivar_vista'}`} id="list_view_products">
176
-                            <Row>
177
-                                <ListMode 
178
-                                    showing={alignment}
179
-                                    data={data}
180
-                                    index={page - 1}
181
-                                    setPuesto={setPuesto}
182
-                                    setEdit={setEdit}
183
-                                    setDelete={setDelete}
184
-                                    setShow={setShow}
194
+                                </Row>
195
+                            </div>
196
+                            <div className={`main_list_products ${alignment === 'list' ? 'activar_vista' : 'desactivar_vista'}`} id="list_view_products">
197
+                                <Row>
198
+                                    <ListMode
199
+                                        showing={alignment}
200
+                                        data={[]}
201
+                                        // data={data}
202
+                                        // index={page - 1}
203
+                                        index={0}
204
+                                        setPuesto={setPuesto}
205
+                                        setEdit={setEdit}
206
+                                        setDelete={setDelete}
207
+                                        setShow={setShow}
185
                                     />
208
                                     />
186
-                            </Row>
187
-                        </div>
188
-
189
-                        <Pagination 
190
-                            sx={{
191
-                                "& ul" :{
192
-                                    paddingTop: "20px",
193
-                                    justifyContent: "center"
194
-                                }
195
-                            }}
196
-                            siblingCount={2} 
197
-                            boundaryCount={2}
198
-                            shape='rounded' 
199
-                            count={data.length} 
200
-                            page={page} 
201
-                            onChange={changePage} 
209
+                                </Row>
210
+                            </div>
211
+
212
+                            <Pagination
213
+                                sx={{
214
+                                    "& ul": {
215
+                                        paddingTop: "20px",
216
+                                        justifyContent: "center"
217
+                                    }
218
+                                }}
219
+                                siblingCount={2}
220
+                                boundaryCount={2}
221
+                                shape='rounded'
222
+                                // count={data.length}
223
+                                count={0}
224
+                                page={page}
225
+                                onChange={changePage}
202
                             />
226
                             />
203
 
227
 
228
+
229
+                        </div>
230
+
204
                     </Paper>
231
                     </Paper>
205
                 </Box>
232
                 </Box>
206
-
207
             </div>
233
             </div>
208
 
234
 
209
-            <Express setExpress={setExpress} visible={expres} onClose={() => setExpress(false) } />
210
-            <Manual categorias={categorias} Complete={Complete} visible={manual} onClose={() => setManual(false)}/>
235
+            <Express setExpress={setExpress} visible={expres} onClose={() => setExpress(false)} />
236
+            <Manual categorias={categorias} Complete={Complete} visible={manual} onClose={() => setManual(false)} />
211
 
237
 
212
             <Editar categorias={categorias} Complete={Complete} puesto={puesto} visible={edit} onClose={() => setEdit(false)} />
238
             <Editar categorias={categorias} Complete={Complete} puesto={puesto} visible={edit} onClose={() => setEdit(false)} />
213
             <Eliminar puesto={puesto} visible={del} onClose={() => setDelete(false)} />
239
             <Eliminar puesto={puesto} visible={del} onClose={() => setDelete(false)} />
214
-            <Mostrar  puesto={puesto} visible={show} onClose={() => setShow(false)} />
240
+            <Mostrar puesto={puesto} visible={show} onClose={() => setShow(false)} />
215
 
241
 
216
-            <Toaster  position="bottom-right" reverseOrder={false} />
242
+            <Toaster position="bottom-right" reverseOrder={false} />
217
 
243
 
218
         </div>
244
         </div>
219
     )
245
     )

+ 11 - 1
src/Utils/HTTP.js

10
         // this.api =  'http://psicoadmin.ditca.org:8081/user?user=patrik&password=12345'
10
         // this.api =  'http://psicoadmin.ditca.org:8081/user?user=patrik&password=12345'
11
     }
11
     }
12
 
12
 
13
+
14
+    async getQuery(token){
15
+        return await axios.get(this.url, {
16
+            headers: {
17
+                'Authorization': `Bearer ${token}`
18
+            }
19
+        })
20
+    }
21
+
13
     async get(token){
22
     async get(token){
14
         return axios.get(this.url, {
23
         return axios.get(this.url, {
15
             headers: {
24
             headers: {
20
             return res;
29
             return res;
21
         })
30
         })
22
         .catch((error) => {
31
         .catch((error) => {
23
-            return error;
32
+            console.log("ERROR :: ", error)
33
+            return new Error("GG");
24
         })
34
         })
25
     }
35
     }
26
 
36