Преглед на файлове

grid and list mode modal

amenpunk преди 3 години
родител
ревизия
3c85b1a473

+ 137 - 30
psicoadmin/src/Components/Modal/EditPlaza.js

@@ -1,10 +1,44 @@
1 1
 import React from 'react';
2
-import { Modal } from 'react-bootstrap'
2
+import * as Yup from 'yup';
3
+import { Modal, Row, Col, Button } from 'react-bootstrap'
4
+import { Formik, Field, Form } from 'formik';
5
+
3 6
 import NotFound from '../../Images/not_found.png';
7
+const SUPPORTED_FORMATS = ["image/jpg", "image/jpeg", "image/gif", "image/png"];
8
+
9
+const NewPlazaSchema = Yup.object().shape({
10
+    nombre : Yup.string().required('El nombre es requerido').min(5).max(20),
11
+    description : Yup.string().required('La description es requerida').min(5).max(20),
12
+    salario : Yup.number().required('El salario es requerido'),
13
+    imagen:  Yup.mixed().required('El imagen es requerido').test('fileSize', "El archivo es demasiado grande", value => {
14
+        if(!value || value.length <= 0) return false
15
+        return value[0].size < 200000
16
+    }).test('fileType', "El tipo del archivo no es válido", value => {
17
+        if(!value) return false
18
+        return SUPPORTED_FORMATS.includes(value[0].type)
19
+    })
20
+})
4 21
 
5 22
 export default function Edit(props) {
6 23
 
7
-    let { visible, onClose } = props
24
+    let { visible, onClose, puesto } = props
25
+
26
+    let [ filename, setFilename ] = React.useState('');
27
+    let [ file, setFile ] = React.useState(undefined);
28
+    let [ type, setType ] = React.useState(undefined);
29
+    let [ validType, setValidType ] = React.useState(false);
30
+
31
+    const hiddenFileInput = React.useRef(null);
32
+    const PickFile = event => hiddenFileInput.current.click();
33
+
34
+    React.useEffect(() => {
35
+        if( SUPPORTED_FORMATS.includes(type) ){
36
+            setValidType(true)
37
+        }else{
38
+            setValidType(false)
39
+        }
40
+
41
+    }, [type])
8 42
 
9 43
     return(
10 44
         <Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered  show={visible} onHide={onClose}>
@@ -12,34 +46,107 @@ export default function Edit(props) {
12 46
                 <button onClick={onClose} type="button" className="close" data-dismiss="modal">&times;</button>
13 47
                 <h4 className="modal-title">Editar plaza</h4>
14 48
             </Modal.Header>
15
-            <Modal.Body classNameName="modal-body">
16
-
17
-                <div className="row">
18
-                    <div className="col-md-4">
19
-                        <div className="img-container">
20
-                            <img alt='not found version' src={NotFound} />
21
-                        </div>
22
-                    </div>
23
-                    <div className="col-md-8">
24
-                        <div className="custom-file-upload">
25
-                            <input type="file" id="file" name="myfiles[]" multiple disabled />
26
-                        </div>
27
-                    </div>
28
-                </div>
29
-                <div className="data_product">
30
-                    <div className="row">
31
-                        <div className="col-md-12">
32
-                            <input type="text" name="nombre" placeholder="Nombre de la plaza"/>
33
-                            <textarea placeholder="Descripción"></textarea>
34
-                            <input type="number" name="sku" placeholder="3500"/>
35
-                        </div>
36
-                    </div>
37
-                    <div className="add_producto_confirm">
38
-                        <div className="btn_add_producto_confirm">
39
-                            <a href="/" type="submit">Actualizar plaza</a>
40
-                        </div>
41
-                    </div> 
42
-                </div>
49
+
50
+           <Modal.Body classNameName="modal-body">
51
+                <Formik
52
+
53
+                    initialValues={{
54
+                        nombre: puesto.id +" - "+  puesto.nombre,
55
+                        description: puesto.description,
56
+                        salario: puesto.salario,
57
+                        imagen: '',
58
+                    }}
59
+
60
+                    validationSchema={NewPlazaSchema}
61
+                    onSubmit={ (values) => {
62
+                        // console.log('VALUES >> ',values)
63
+                        props.setManual(false)
64
+                    }} >
65
+
66
+
67
+                    { ({  errors, touched, validateField, validateForm, setFieldValue  }) => (
68
+                        <Form>
69
+                            <Row>
70
+
71
+                                <Col md="4">
72
+                                    <div className="img-container">
73
+                                        <img alt="agregar plaza manual" src={ validType ? file : NotFound}/>
74
+                                    </div>
75
+                                </Col>
76
+
77
+                                <Col md="8">
78
+
79
+                                    <input 
80
+                                        value={filename} 
81
+                                        type="text" 
82
+                                        className="file-upload-input" 
83
+                                        disabled="" 
84
+                                        placeholder="Ningún archivo seleccionado" readOnly
85
+                                    />
86
+
87
+                                    <Button className="btn_add_producto_confirm" style={{ marginLeft : 15 }} onClick={PickFile}>
88
+                                        SUBIR FOTO
89
+                                    </Button>
90
+
91
+                                    {errors.imagen && touched.imagen && <div className="error_feedback">{errors.imagen}</div>}
92
+                                    <input
93
+                                        multiple={false}
94
+                                        type="file"
95
+                                        ref={hiddenFileInput}
96
+                                        onChange={(event) => {
97
+                                            const files = event.target.files;
98
+                                            console.log('files crud ', files[0])
99
+                                            let myFiles =Array.from(files);
100
+                                            setFieldValue("imagen", myFiles);
101
+                                            setFilename(myFiles[0].name)
102
+                                            setType(myFiles[0].type)
103
+                                            const objectUrl = URL.createObjectURL(files[0])
104
+                                            setFile(objectUrl)
105
+                                        }}
106
+                                        style={{display: 'none'}}
107
+                                    />
108
+
109
+                                </Col>
110
+
111
+                            </Row>
112
+                            <div className="data_product">
113
+                                <Row>
114
+                                    <Col md="12">
115
+
116
+                                        {errors.nombre && touched.nombre && <div className="error_feedback">{errors.nombre}</div>}
117
+                                        <Field  name="nombre" placeholder="Nombre de la plaza"/>
118
+
119
+                                        {errors.description && touched.description && <div className="error_feedback">{errors.description}</div>}
120
+                                        <Field name="description">
121
+                                            {({ field, form, meta }) => {
122
+                                                return(
123
+                                                    <textarea id="description" name="description" value={field.value} onChange={field.onChange} placeholder="Descripción general de la plaza"></textarea>
124
+                                                )
125
+                                            }}
126
+                                        </Field>
127
+
128
+                                        {errors.salario && touched.salario && <div className="error_feedback">{errors.salario}</div>}
129
+                                        <Field name="salario" type="text" placeholder="Salario"/>
130
+
131
+
132
+                                    </Col>
133
+
134
+
135
+                                    <div className="add_producto_confirm">
136
+                                        <div className="btn_add_producto_confirm">
137
+                                            <span href="/" type="submit">Actualizar plaza</span>
138
+                                        </div>
139
+                                    </div>
140
+
141
+                                </Row>
142
+                            </div>
143
+                        </Form>
144
+                    )}
145
+
146
+
147
+
148
+
149
+                </Formik>
43 150
 
44 151
             </Modal.Body>
45 152
         </Modal>

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

@@ -3,7 +3,7 @@ import { Modal, Row, Col } from 'react-bootstrap'
3 3
 
4 4
 export default function Eliminar(props) {
5 5
 
6
-    let { visible, onClose } = props
6
+    let { visible, onClose, puesto } = props
7 7
 
8 8
     return(
9 9
         <Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered  show={visible} onHide={onClose}>
@@ -26,7 +26,7 @@ export default function Eliminar(props) {
26 26
                     <Col md="6">
27 27
                         <div class="delet_producto_confirm">
28 28
                             <div class="btn_delete_producto_confirm">
29
-                                <a href="/" type="submit">Eliminar</a>
29
+                                <a  href="/" onClick={() => console.log('ID >> ',puesto.id)} type="submit">Eliminar</a>
30 30
                             </div>
31 31
                         </div>
32 32
                     </Col>

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

@@ -4,7 +4,7 @@ import NotFound from '../../Images/not_found.png';
4 4
 
5 5
 export default function Mostrar(props) {
6 6
 
7
-    let { visible, onClose } = props
7
+    let { visible, onClose, puesto } = props
8 8
 
9 9
     return(
10 10
         <Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered  show={visible} onHide={onClose}>
@@ -22,9 +22,9 @@ export default function Mostrar(props) {
22 22
                             </div>
23 23
                         </div>
24 24
                         <div class="col-md-8">
25
-                            <input type="text" name="nombre" placeholder="Nombre de la plaza" readOnly/>
26
-                            <input type="text" name="descript" placeholder="Descripción" readOnly/>
27
-                            <input type="number" name="sku" placeholder="3500" readOnly/>
25
+                            <input value={puesto.id + " - "+ puesto.nombre} type="text" name="nombre" placeholder="Nombre de la plaza" readOnly/>
26
+                            <input value={puesto.description} type="text" name="descript" placeholder="Descripción" readOnly/>
27
+                            <input value={puesto.salario} type="text" name="sku" placeholder="3500" readOnly/>
28 28
                         </div>
29 29
                     </div>
30 30
                 </div>

+ 40 - 23
psicoadmin/src/Pages/Puestos.js

@@ -114,25 +114,7 @@ function ListMode(props) {
114 114
 
115 115
 function GridMode (props) {
116 116
     
117
-    let { setEdit, setDelete, setShow } = props;
118
-
119
-    let buttons = [
120
-        <div className="botones_interactivos">
121
-            <span onClick={ () => setShow(true) } tooltip-location="top" tooltip="Ver plaza">
122
-                <RemoveRedEyeIcon className="grid_btn"/>
123
-            </span>
124
-        </div>,
125
-        <div className="botones_interactivos">
126
-            <span onClick={ () => setEdit(true) } tooltip-location="top" tooltip="Editar plaza">
127
-                <EditIcon className="grid_btn"/>
128
-            </span>
129
-        </div>,
130
-        <div className="botones_interactivos">
131
-            <span onClick={() => setDelete(true)} tooltip-location="top" tooltip="Eliminar plaza">
132
-                <HighlightOffIcon className="grid_btn"/>
133
-            </span>
134
-        </div>
135
-    ]
117
+    let { setEdit, setDelete, setShow, setPuesto } = props;
136 118
 
137 119
     return(
138 120
         <React.Fragment> 
@@ -155,7 +137,41 @@ function GridMode (props) {
155 137
                                             <p>{ plaza.salario }</p>
156 138
                                         </div>
157 139
                                         <div className="btn_interactivos">
158
-                                            { buttons }
140
+
141
+                                            <div className="botones_interactivos">
142
+                                                <span 
143
+                                                    onClick={ () => {
144
+                                                        setPuesto(plaza)
145
+                                                        setShow(true)
146
+                                                    }} 
147
+                                                    tooltip-location="top" 
148
+                                                    tooltip="Ver plaza">
149
+                                                    <RemoveRedEyeIcon className="grid_btn"/>
150
+                                                </span>
151
+                                            </div>
152
+                                            <div className="botones_interactivos">
153
+                                                <span 
154
+                                                    onClick={() => {
155
+                                                        setPuesto(plaza)
156
+                                                        setEdit(true)
157
+                                                    }} 
158
+                                                    tooltip-location="top" 
159
+                                                    tooltip="Editar plaza">
160
+                                                    <EditIcon className="grid_btn"/>
161
+                                                </span>
162
+                                            </div>
163
+                                            <div className="botones_interactivos">
164
+                                                <span 
165
+                                                    onClick={() => {
166
+                                                        setPuesto(plaza)
167
+                                                        setDelete(true)
168
+                                                    }} 
169
+                                                    tooltip-location="top" 
170
+                                                    tooltip="Eliminar plaza">
171
+                                                    <HighlightOffIcon className="grid_btn"/>
172
+                                                </span>
173
+                                            </div>
174
+
159 175
                                         </div>
160 176
                                     </Col>
161 177
                                 </Row>
@@ -228,6 +244,7 @@ export function Puestos() {
228 244
                 <div className={`main_productos ${ alignment === 'grid' ? 'activar_vista' : 'desactivar_vista'  }`} id="grid_view">
229 245
                     <Row>
230 246
                         <GridMode
247
+                            setPuesto={setPuesto}
231 248
                             setEdit={setEdit}
232 249
                             setDelete={setDelete}
233 250
                             setShow={setShow}
@@ -249,9 +266,9 @@ export function Puestos() {
249 266
             <Express setExpress={setExpress} visible={expres} onClose={() => setExpress(false) } />
250 267
             <Manual setManual={setManual} visible={manual}  onClose={() => setManual(false) } />
251 268
 
252
-            <Editar visible={edit} onClose={() => setEdit(false)} />
253
-            <Eliminar visible={del} onClose={() => setDelete(false)} />
254
-            <Mostrar visible={show} onClose={() => setShow(false)} />
269
+            <Editar  puesto={puesto} visible={edit} onClose={() => setEdit(false)} />
270
+            <Eliminar puesto={puesto} visible={del} onClose={() => setDelete(false)} />
271
+            <Mostrar puesto={puesto} visible={show} onClose={() => setShow(false)} />
255 272
 
256 273
         </div>
257 274
     )