Ver código fonte

list puestos creados

amenpunk 3 anos atrás
pai
commit
9ae3acca3a

+ 82 - 0
src/Components/Puestos/GridMode.jsx

@@ -0,0 +1,82 @@
1
+import React from "react";
2
+import NotFound from '../../Images/not_found.png';
3
+import { 
4
+    RemoveRedEye as RemoveRedEyeIcon,
5
+    Edit as EditIcon,
6
+    HighlightOff as HighlightOffIcon,
7
+} from '@mui/icons-material';
8
+
9
+
10
+import { Row, Col } from 'react-bootstrap'
11
+
12
+export function GridMode(props){
13
+
14
+    let { setEdit, setDelete, setShow, setPuesto,data } = props;
15
+
16
+    return(
17
+        <React.Fragment> 
18
+            {
19
+                data.length ? 
20
+                data.slice(23).map( plaza => {
21
+                    return(
22
+                        <Col key={plaza.id} lg="4" md="6" sm="6" xs="12" >
23
+                            <div className="panel">
24
+                                <Row>
25
+                                    <Col md="4">
26
+                                        <div className="img-container">
27
+                                            <img alt="not found" src={NotFound}/>
28
+                                        </div>
29
+                                    </Col>
30
+                                    <Col md="8">
31
+                                        <div className="info_details">
32
+                                            <p>{ plaza.nombre }</p>
33
+                                            <p>{ plaza.description }</p>
34
+                                            <p>{ plaza.salario }</p>
35
+                                        </div>
36
+                                        <div className="btn_interactivos">
37
+
38
+                                            <div className="botones_interactivos">
39
+                                                <span 
40
+                                                    onClick={ () => {
41
+                                                        setPuesto(plaza)
42
+                                                        setShow(true)
43
+                                                    }} 
44
+                                                    tooltip-location="top" 
45
+                                                    tooltip="Ver plaza">
46
+                                                    <RemoveRedEyeIcon className="grid_btn"/>
47
+                                                </span>
48
+                                            </div>
49
+                                            <div className="botones_interactivos">
50
+                                                <span 
51
+                                                    onClick={() => {
52
+                                                        setPuesto(plaza)
53
+                                                        setEdit(true)
54
+                                                    }} 
55
+                                                    tooltip-location="top" 
56
+                                                    tooltip="Editar plaza">
57
+                                                    <EditIcon className="grid_btn"/>
58
+                                                </span>
59
+                                            </div>
60
+                                            <div className="botones_interactivos">
61
+                                                <span 
62
+                                                    onClick={() => {
63
+                                                        setPuesto(plaza)
64
+                                                        setDelete(true)
65
+                                                    }} 
66
+                                                    tooltip-location="top" 
67
+                                                    tooltip="Eliminar plaza">
68
+                                                    <HighlightOffIcon className="grid_btn"/>
69
+                                                </span>
70
+                                            </div>
71
+
72
+                                        </div>
73
+                                    </Col>
74
+                                </Row>
75
+                            </div>
76
+                        </Col>
77
+                    )
78
+                }) : undefined
79
+            }
80
+        </React.Fragment>
81
+    )
82
+}

+ 7 - 7
src/Components/Puestos/ListMode.jsx

@@ -12,7 +12,7 @@ export function ListMode(props) {
12 12
                         <tr >
13 13
                             <th className="text-center">Nombre de la plaza</th>
14 14
                             <th className="text-center">Descripción</th>
15
-                            <th className="text-center">Salario</th>
15
+                            <th className="text-center">Creacion</th>
16 16
                             <th className="text-center">Acciones</th>
17 17
                         </tr>
18 18
                     </thead>
@@ -23,9 +23,9 @@ export function ListMode(props) {
23 23
                                 data.slice( 0,23 ).map( (plaza, i) => {
24 24
                                     return (
25 25
                                         <tr key={plaza.id}>
26
-                                            <td className="text-center">{  plaza.id +  " - " + plaza.nombre }</td>
26
+                                            <td className="text-center">{ plaza.nombre }</td>
27 27
                                             <td className="text-center">{ plaza.description }</td>
28
-                                            <td className="text-center">{ plaza.salario }</td>
28
+                                            <td className="text-center">{ plaza.created }</td>
29 29
                                             <td className="actions_butons_plaza"> 
30 30
                                                 <Button 
31 31
                                                     onClick={() => {
@@ -58,10 +58,10 @@ export function ListMode(props) {
58 58
                     </tbody>
59 59
                     <tfoot>
60 60
                         <tr>
61
-                            <th>Nombre de la plaza</th>
62
-                            <th>Descripción</th>
63
-                            <th>Salario</th>
64
-                            <th>Acciones</th>
61
+                            <th className="text-center">Nombre de la plaza</th>
62
+                            <th className="text-center">Descripción</th>
63
+                            <th className="text-center">Salario</th>
64
+                            <th className="text-center">Acciones</th>
65 65
                         </tr>
66 66
                     </tfoot>
67 67
                 </Table>

+ 66 - 148
src/Pages/Puestos.jsx

@@ -1,26 +1,21 @@
1
-import React, { useState }  from 'react';
1
+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 { 
6
-    ToggleButton, 
7
-    ToggleButtonGroup, 
5
+import {
6
+    ToggleButton,
7
+    ToggleButtonGroup,
8 8
     Box, Paper
9 9
 } from '@mui/material';
10 10
 
11
-import { 
11
+import {
12 12
     ViewList as ViewListIcon,
13 13
     ViewModule as ViewModuleIcon,
14
-    RemoveRedEye as RemoveRedEyeIcon,
15
-    Edit as EditIcon,
16
-    HighlightOff as HighlightOffIcon,
17 14
 } from '@mui/icons-material';
18 15
 
19 16
 import { default as useAuth } from '../Auth/useAuth';
20 17
 import { Service } from '../Utils/HTTP';
21 18
 
22
-
23
-import NotFound from '../Images/not_found.png';
24 19
 import Express from '../Components/Modal/AgregarExpress';
25 20
 import Manual from '../Components/Modal/AgregarManual';
26 21
 
@@ -29,117 +24,39 @@ import Eliminar from '../Components/Modal/EliminarPlaza';
29 24
 import Mostrar from '../Components/Modal/MostrarPlaza';
30 25
 
31 26
 import { ListMode } from '../Components/Puestos/ListMode'
27
+import { GridMode } from '../Components/Puestos/GridMode'
32 28
 
33
-let data = [{
34
-    nombre : 'The standard Lorem Ipsum passage, used since the 1500s',
35
-    description : '"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."',
36
-    salario :  'Q 10,000',
37
-    id :  0,
38
-}]
39
-
40
-function* idMaker() {
41
-    var index = 1;
42
-    while(true)
43
-        yield index++;
44
-}
45 29
 
46 30
 const Success =  () => toast.success('Plaza Agregada!!')
47 31
 
48
-var ID = idMaker(); 
49
-
50
-for ( var _ of new Array(46) ){
51
-    data.push({ ...data[0], id : ID.next().value, d : _ })
52
-}
53
-
54
-function GridMode (props) {
55
-    
56
-    let { setEdit, setDelete, setShow, setPuesto } = props;
57
-
58
-    return(
59
-        <React.Fragment> 
60
-
61
-            {
62
-                data.length ? 
63
-                data.slice(23).map( plaza => {
64
-                    return(
65
-                        <Col key={plaza.id} lg="4" md="6" sm="6" xs="12" >
66
-                            <div className="panel">
67
-                                <Row>
68
-                                    <Col md="4">
69
-                                        <div className="img-container">
70
-                                            <img alt="not found" src={NotFound}/>
71
-                                        </div>
72
-                                    </Col>
73
-                                    <Col md="8">
74
-                                        <div className="info_details">
75
-                                            <p>{ plaza.nombre }</p>
76
-                                            <p>{ plaza.description }</p>
77
-                                            <p>{ plaza.salario }</p>
78
-                                        </div>
79
-                                        <div className="btn_interactivos">
80
-
81
-                                            <div className="botones_interactivos">
82
-                                                <span 
83
-                                                    onClick={ () => {
84
-                                                        setPuesto(plaza)
85
-                                                        setShow(true)
86
-                                                    }} 
87
-                                                    tooltip-location="top" 
88
-                                                    tooltip="Ver plaza">
89
-                                                    <RemoveRedEyeIcon className="grid_btn"/>
90
-                                                </span>
91
-                                            </div>
92
-                                            <div className="botones_interactivos">
93
-                                                <span 
94
-                                                    onClick={() => {
95
-                                                        setPuesto(plaza)
96
-                                                        setEdit(true)
97
-                                                    }} 
98
-                                                    tooltip-location="top" 
99
-                                                    tooltip="Editar plaza">
100
-                                                    <EditIcon className="grid_btn"/>
101
-                                                </span>
102
-                                            </div>
103
-                                            <div className="botones_interactivos">
104
-                                                <span 
105
-                                                    onClick={() => {
106
-                                                        setPuesto(plaza)
107
-                                                        setDelete(true)
108
-                                                    }} 
109
-                                                    tooltip-location="top" 
110
-                                                    tooltip="Eliminar plaza">
111
-                                                    <HighlightOffIcon className="grid_btn"/>
112
-                                                </span>
113
-                                            </div>
114
-
115
-                                        </div>
116
-                                    </Col>
117
-                                </Row>
118
-                            </div>
119
-                        </Col>
120
-                    )
121
-                }) : undefined
122
-            }
123
-        </React.Fragment>
124
-    )
125
-}
126
-
127 32
 export function Puestos() {
33
+
128 34
     const auth = useAuth();
129
-    
130
-    useState(() => {
35
+    const [data, setData] = useState({});
36
+    const token = auth.getToken();
37
+
38
+    useEffect(() => {
131 39
         let rest = new Service("/plaza/getall")
132
-        let token = auth.getToken();
133 40
 
134 41
         rest
135 42
         .get(token)
136 43
         .then(({data}) => {
137
-            console.log('data > ', data)
44
+            let entries = data.map( e => {
45
+                return {
46
+                    nombre : e.nombrepuesto,
47
+                    description : e.notas,
48
+                    id : e.id,
49
+                    created: e.create_day,
50
+                    data: e
51
+                };
52
+            })
53
+            setData(entries)
138 54
         })
139 55
         .catch((error) => {
140 56
             console.log('error fetching data  ', error );
141 57
         })
142
-    },[])
58
+
59
+    },[token])
143 60
 
144 61
     const [alignment, setAlignment] = React.useState('list');
145 62
 
@@ -173,50 +90,51 @@ export function Puestos() {
173 90
         <div className="content-section">
174 91
             <div className="main">
175 92
                 <Box sx={{ width: '100%' }}>
176
-                <Paper sx={{ width: '100%', mb: 2, padding : 2 }}>
177
-
178
-                <Row>
179
-                    <Col md="2" sm="2" xs="2">
180
-                        <div className="breadcrumb-header">
181
-                            <Box sx={{ float : 'left',display: 'flex', flexDirection: 'column', alignItems: 'center', '& > :not(style) + :not(style)': { mt: 2 }, }} >
182
-                                <ToggleButtonGroup size="small" {...control}>
183
-                                    {children}
184
-                                </ToggleButtonGroup>
185
-                            </Box>
186
-                        </div>
187
-                    </Col>
188
-                    <Col md="10" sm='10' xs="10">
189
-                        <div className="add_producto">
190
-                            <div onClick={() => setManual(true) } className="btn_add_producto"> <span >Agregar manual</span> </div>
93
+                    <Paper sx={{ width: '100%', mb: 2, padding : 2 }}>
94
+
95
+                        <Row>
96
+                            <Col md="2" sm="2" xs="2">
97
+                                <div className="breadcrumb-header">
98
+                                    <Box sx={{ float : 'left',display: 'flex', flexDirection: 'column', alignItems: 'center', '& > :not(style) + :not(style)': { mt: 2 }, }} >
99
+                                        <ToggleButtonGroup size="small" {...control}>
100
+                                            {children}
101
+                                        </ToggleButtonGroup>
102
+                                    </Box>
103
+                                </div>
104
+                            </Col>
105
+                            <Col md="10" sm='10' xs="10">
106
+                                <div className="add_producto">
107
+                                    <div onClick={() => setManual(true) } className="btn_add_producto"> <span >Agregar manual</span> </div>
108
+                                </div>
109
+                                <div onClick={() => setExpress(true) } className="add_producto">
110
+                                    <div className="btn_add_producto"> <span >Agregar express</span> </div>
111
+                                </div>
112
+                            </Col>
113
+                        </Row>
114
+                        <div className={`main_productos ${ alignment === 'grid' ? 'activar_vista' : 'desactivar_vista'  }`} id="grid_view">
115
+                            <Row>
116
+                                <GridMode
117
+                                    data={data}
118
+                                    setPuesto={setPuesto}
119
+                                    setEdit={setEdit}
120
+                                    setDelete={setDelete}
121
+                                    setShow={setShow}
122
+                                />
123
+                            </Row>
191 124
                         </div>
192
-                        <div onClick={() => setExpress(true) } className="add_producto">
193
-                            <div className="btn_add_producto"> <span >Agregar express</span> </div>
125
+                        <div className={`main_list_products ${alignment === 'list' ?  'activar_vista' : 'desactivar_vista'}`} id="list_view_products">
126
+                            <Row>
127
+                                <ListMode 
128
+                                    data={data}
129
+                                    setPuesto={setPuesto}
130
+                                    setEdit={setEdit}
131
+                                    setDelete={setDelete}
132
+                                    setShow={setShow}
133
+                                />
134
+                            </Row>
194 135
                         </div>
195
-                    </Col>
196
-                </Row>
197
-                <div className={`main_productos ${ alignment === 'grid' ? 'activar_vista' : 'desactivar_vista'  }`} id="grid_view">
198
-                    <Row>
199
-                        <GridMode
200
-                            setPuesto={setPuesto}
201
-                            setEdit={setEdit}
202
-                            setDelete={setDelete}
203
-                            setShow={setShow}
204
-                        />
205
-                    </Row>
206
-                </div>
207
-                <div className={`main_list_products ${alignment === 'list' ?  'activar_vista' : 'desactivar_vista'}`} id="list_view_products">
208
-                    <Row>
209
-                        <ListMode 
210
-                            data={data}
211
-                            setPuesto={setPuesto}
212
-                            setEdit={setEdit}
213
-                            setDelete={setDelete}
214
-                            setShow={setShow}
215
-                        />
216
-                    </Row>
217
-                </div>
218
-
219
-                </Paper>
136
+
137
+                    </Paper>
220 138
                 </Box>
221 139
 
222 140
             </div>