Browse Source

refactor mov modal
;

amenpunk 3 years ago
parent
commit
497bc78dfe

+ 54 - 0
psicoadmin/src/Components/Modal/AgregarExpress.js

1
+import React from 'react';
2
+import * as Yup from 'yup';
3
+import { Formik, Field, Form } from 'formik';
4
+import { Modal } from 'react-bootstrap'
5
+
6
+const ExpressSchema = Yup.object().shape({
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
+})
9
+
10
+export  default function Express (props) {
11
+    let { visible, onClose } = props
12
+    return (
13
+        <Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered  show={visible} onHide={onClose}>
14
+            <Modal.Header>
15
+                <button onClick={onClose} type="button" className="close" data-dismiss="modal">&times;</button>
16
+                <h4 className="modal-title">Agregar plaza express</h4>
17
+            </Modal.Header>
18
+            <Modal.Body>
19
+
20
+                <Formik
21
+                    initialValues={{
22
+                        link : ''
23
+                    }}
24
+                    validationSchema={ExpressSchema}
25
+                    onSubmit={ (values) => {
26
+                        props.setExpress(false)
27
+                        console.log('VALUES Express >> ',values)
28
+                    }} 
29
+                >
30
+                    { ({ errors, touched, validateField, validateForm, setFieldValue   }) =>  (
31
+
32
+                        <Form>
33
+                            <div className="data_product">
34
+                                <div className="row">
35
+                                    <div className="col-md-12">
36
+                                        <Field type="link" name="link" placeholder="Link de la plaza"/>
37
+                                        {errors.link && touched.link && <div className="error_feedback">{errors.link}</div>}
38
+                                    </div>
39
+                                    <div className="add_producto_confirm">
40
+                                        <button className="btn_add_producto_confirm" type="submit">Agregar plaza</button>
41
+                                    </div>
42
+                                </div>
43
+                            </div>
44
+                        </Form>
45
+                    )}
46
+
47
+                </Formik>
48
+
49
+
50
+
51
+            </Modal.Body>
52
+        </Modal>
53
+    )
54
+}

+ 149 - 0
psicoadmin/src/Components/Modal/AgregarManual.js

1
+import React from 'react';
2
+import * as Yup from 'yup';
3
+import { Formik, Field, Form } from 'formik';
4
+import { Row, Col, Modal, Button} from 'react-bootstrap'
5
+
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
+})
21
+
22
+export default function Manual ( props ) {
23
+
24
+    let [ filename, setFilename ] = React.useState('');
25
+    let [ file, setFile ] = React.useState(undefined);
26
+    let [ type, setType ] = React.useState(undefined);
27
+    let [ validType, setValidType ] = React.useState(false);
28
+
29
+    let { visible, onClose } = props
30
+    const hiddenFileInput = React.useRef(null);
31
+
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])
42
+
43
+
44
+    return (
45
+        <Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered  show={visible} onHide={onClose}>
46
+            <Modal.Header>
47
+                <button onClick={onClose}  type="button" className="close" data-dismiss="modal">&times;</button>
48
+                <h4 className="modal-title">Agregar plaza</h4>
49
+            </Modal.Header>
50
+            <Modal.Body className="modal-body">
51
+
52
+                <Formik
53
+
54
+                    initialValues={{
55
+                        nombre: '',
56
+                        description: '',
57
+                        salario: '',
58
+                        imagen: '',
59
+                    }}
60
+
61
+                    validationSchema={NewPlazaSchema}
62
+                    onSubmit={ (values) => {
63
+                        // console.log('VALUES >> ',values)
64
+                        props.setManual(false)
65
+                    }} >
66
+
67
+
68
+                    { ({  errors, touched, validateField, validateForm, setFieldValue  }) => (
69
+                        <Form>
70
+                            <Row>
71
+
72
+                                <Col md="4">
73
+                                    <div className="img-container">
74
+                                        <img alt="agregar plaza manual" src={ validType ? file : NotFound}/>
75
+                                    </div>
76
+                                </Col>
77
+
78
+                                <Col md="8">
79
+
80
+                                    <input 
81
+                                        value={filename} 
82
+                                        type="text" 
83
+                                        className="file-upload-input" 
84
+                                        disabled="" 
85
+                                        placeholder="Ningún archivo seleccionado" readOnly
86
+                                    />
87
+
88
+                                    <Button className="btn_add_producto_confirm" style={{ marginLeft : 15 }} onClick={PickFile}>
89
+                                        SUBIR FOTO
90
+                                    </Button>
91
+
92
+                                    {errors.imagen && touched.imagen && <div className="error_feedback">{errors.imagen}</div>}
93
+                                    <input
94
+                                        multiple={false}
95
+                                        type="file"
96
+                                        ref={hiddenFileInput}
97
+                                        onChange={(event) => {
98
+                                            const files = event.target.files;
99
+                                            console.log('files crud ', files[0])
100
+                                            let myFiles =Array.from(files);
101
+                                            setFieldValue("imagen", myFiles);
102
+                                            setFilename(myFiles[0].name)
103
+                                            setType(myFiles[0].type)
104
+                                            const objectUrl = URL.createObjectURL(files[0])
105
+                                            setFile(objectUrl)
106
+                                        }}
107
+                                        style={{display: 'none'}}
108
+                                    />
109
+
110
+                                </Col>
111
+
112
+                            </Row>
113
+                            <div className="data_product">
114
+                                <Row>
115
+                                    <Col md="12">
116
+
117
+                                        {errors.nombre && touched.nombre && <div className="error_feedback">{errors.nombre}</div>}
118
+                                        <Field name="nombre" placeholder="Nombre de la plaza"/>
119
+
120
+                                        {errors.description && touched.description && <div className="error_feedback">{errors.description}</div>}
121
+                                        <Field name="description">
122
+                                            {({ field, form, meta }) => {
123
+                                                return(
124
+                                                    <textarea id="description" name="description" value={field.value} onChange={field.onChange} placeholder="Descripción general de la plaza"></textarea>
125
+                                                )
126
+                                            }}
127
+                                        </Field>
128
+
129
+                                        {errors.salario && touched.salario && <div className="error_feedback">{errors.salario}</div>}
130
+                                        <Field name="salario" type="number" placeholder="Salario"/>
131
+
132
+
133
+                                    </Col>
134
+                                    <div className="add_producto_confirm">
135
+                                        <button className="btn_add_producto_confirm" type="submit">Agregar plaza</button>
136
+                                    </div>
137
+                                </Row>
138
+                            </div>
139
+                        </Form>
140
+                    )}
141
+
142
+
143
+
144
+
145
+                </Formik>
146
+            </Modal.Body>
147
+        </Modal>
148
+    )
149
+}

+ 7 - 208
psicoadmin/src/Pages/Puestos.js

1
-import React, {  } from 'react';
2
-import { Row, Col, Modal, Button, Table } from 'react-bootstrap'
1
+import React  from 'react';
2
+import { Row, Col, Button, Table } from 'react-bootstrap'
3
 import { Box } from '@mui/material';
3
 import { Box } from '@mui/material';
4
-import { Formik, Field, Form } from 'formik';
5
-import * as Yup from 'yup';
6
 
4
 
7
 import ToggleButton from '@mui/material/ToggleButton';
5
 import ToggleButton from '@mui/material/ToggleButton';
8
 import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
6
 import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
15
 import HighlightOffIcon from '@mui/icons-material/HighlightOff';
13
 import HighlightOffIcon from '@mui/icons-material/HighlightOff';
16
 
14
 
17
 import NotFound from '../Images/not_found.png';
15
 import NotFound from '../Images/not_found.png';
18
-const SUPPORTED_FORMATS = ["image/jpg", "image/jpeg", "image/gif", "image/png"];
19
 
16
 
17
+import Express from '../Components/Modal/AgregarExpress';
18
+import Manual from '../Components/Modal/AgregarManual';
20
 
19
 
21
-const NewPlazaSchema = Yup.object().shape({
22
-    nombre : Yup.string().required('El nombre es requerido').min(5).max(20),
23
-    description : Yup.string().required('La description es requerida').min(5).max(20),
24
-    salario : Yup.number().required('El salario es requerido'),
25
-    imagen:  Yup.mixed().required('El imagen es requerido').test('fileSize', "El archivo es demasiado grande", value => {
26
-        if(!value || value.length <= 0) return false
27
-        return value[0].size < 200000
28
-    }).test('fileType', "El tipo del archivo no es válido", value => {
29
-        if(!value) return false
30
-        return SUPPORTED_FORMATS.includes(value[0].type)
31
-    })
32
-})
33
-
34
-const ExpressSchema = Yup.object().shape({
35
-    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),
36
-})
37
     
20
     
38
 let data = [{
21
 let data = [{
39
     nombre : 'The standard Lorem Ipsum passage, used since the 1500s',
22
     nombre : 'The standard Lorem Ipsum passage, used since the 1500s',
57
 function ListMode() {
40
 function ListMode() {
58
 
41
 
59
     let actions = [
42
     let actions = [
60
-        <Button className="ver_producto">Ver</Button>,
61
-        <Button className="editar_producto">Editar</Button>,
62
-        <Button className="eliminar_producto">Eliminar</Button>,
43
+        <Button onClick={ ()  => console.log('ver producto') } className="ver_producto">Ver</Button>,
44
+        <Button onClick={ ()  => console.log('editar producto') } className="editar_producto">Editar</Button>,
45
+        <Button onClick={ ()  => console.log('eliminar producto') } className="eliminar_producto">Eliminar</Button>,
63
     ]
46
     ]
64
 
47
 
65
     return(
48
     return(
160
     )
143
     )
161
 }
144
 }
162
 
145
 
163
-function Manual ( props ) {
164
-
165
-    let [ filename, setFilename ] = React.useState('');
166
-    let [ file, setFile ] = React.useState(undefined);
167
-    let [ type, setType ] = React.useState(undefined);
168
-    let [ validType, setValidType ] = React.useState(false);
169
-
170
-    let { visible, onClose } = props
171
-    const hiddenFileInput = React.useRef(null);
172
-
173
-    const PickFile = event => {
174
-        hiddenFileInput.current.click();
175
-    };
176
-
177
-    React.useEffect(() => {
178
-
179
-        if( SUPPORTED_FORMATS.includes(type) ){
180
-            setValidType(true)
181
-        }else{
182
-            setValidType(false)
183
-        }
184
-
185
-    }, [type])
186
-
187
-
188
-
189
-    return (
190
-        <Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered  show={visible} onHide={onClose}>
191
-            <Modal.Header>
192
-                <button onClick={onClose}  type="button" className="close" data-dismiss="modal">&times;</button>
193
-                <h4 className="modal-title">Agregar plaza</h4>
194
-            </Modal.Header>
195
-            <Modal.Body className="modal-body">
196
-
197
-                <Formik
198
-
199
-                    initialValues={{
200
-                        nombre: '',
201
-                        description: '',
202
-                        salario: '',
203
-                        imagen: '',
204
-                    }}
205
-
206
-                    validationSchema={NewPlazaSchema}
207
-                    onSubmit={ (values) => {
208
-                        // console.log('VALUES >> ',values)
209
-                        props.setManual(false)
210
-                    }} >
211
-
212
-
213
-                    { ({  errors, touched, validateField, validateForm, setFieldValue  }) => (
214
-                        <Form>
215
-                            <Row>
216
-
217
-                                <Col md="4">
218
-                                    <div className="img-container">
219
-                                        <img alt="agregar plaza manual" src={ validType ? file : NotFound}/>
220
-                                    </div>
221
-                                </Col>
222
-
223
-                                <Col md="8">
224
-
225
-                                    <input 
226
-                                        value={filename} 
227
-                                        type="text" 
228
-                                        className="file-upload-input" 
229
-                                        disabled="" 
230
-                                        placeholder="Ningún archivo seleccionado" readOnly
231
-                                    />
232
-
233
-                                    <Button className="btn_add_producto_confirm" style={{ marginLeft : 15 }} onClick={PickFile}>
234
-                                        SUBIR FOTO
235
-                                    </Button>
236
-
237
-                                    {errors.imagen && touched.imagen && <div className="error_feedback">{errors.imagen}</div>}
238
-                                    <input
239
-                                        multiple={false}
240
-                                        type="file"
241
-                                        ref={hiddenFileInput}
242
-                                        onChange={(event) => {
243
-                                            const files = event.target.files;
244
-                                            console.log('files crud ', files[0])
245
-                                            let myFiles =Array.from(files);
246
-                                            setFieldValue("imagen", myFiles);
247
-                                            setFilename(myFiles[0].name)
248
-                                            setType(myFiles[0].type)
249
-                                            const objectUrl = URL.createObjectURL(files[0])
250
-                                            setFile(objectUrl)
251
-                                        }}
252
-                                        style={{display: 'none'}}
253
-                                    />
254
-
255
-                                </Col>
256
-
257
-                            </Row>
258
-                            <div className="data_product">
259
-                                <Row>
260
-                                    <Col md="12">
261
-
262
-                                        {errors.nombre && touched.nombre && <div className="error_feedback">{errors.nombre}</div>}
263
-                                        <Field name="nombre" placeholder="Nombre de la plaza"/>
264
-
265
-                                        {errors.description && touched.description && <div className="error_feedback">{errors.description}</div>}
266
-                                        <Field name="description">
267
-                                            {({ field, form, meta }) => {
268
-                                                return(
269
-                                                    <textarea id="description" name="description" value={field.value} onChange={field.onChange} placeholder="Descripción general de la plaza"></textarea>
270
-                                                )
271
-                                            }}
272
-                                        </Field>
273
-
274
-                                        {errors.salario && touched.salario && <div className="error_feedback">{errors.salario}</div>}
275
-                                        <Field name="salario" type="number" placeholder="Salario"/>
276
-
277
-
278
-                                    </Col>
279
-                                    <div className="add_producto_confirm">
280
-                                        <button className="btn_add_producto_confirm" type="submit">Agregar plaza</button>
281
-                                    </div>
282
-                                </Row>
283
-                            </div>
284
-                        </Form>
285
-                    )}
286
-
287
-
288
-
289
-
290
-                </Formik>
291
-            </Modal.Body>
292
-        </Modal>
293
-    )
294
-}
295
-
296
-function Express (props) {
297
-    let { visible, onClose } = props
298
-    return (
299
-        <Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered  show={visible} onHide={onClose}>
300
-            <Modal.Header>
301
-                <button onClick={onClose} type="button" className="close" data-dismiss="modal">&times;</button>
302
-                <h4 className="modal-title">Agregar plaza express</h4>
303
-            </Modal.Header>
304
-            <Modal.Body>
305
-
306
-                <Formik
307
-                    initialValues={{
308
-                        link : ''
309
-                    }}
310
-                    validationSchema={ExpressSchema}
311
-                    onSubmit={ (values) => {
312
-                        props.setExpress(false)
313
-                        console.log('VALUES Express >> ',values)
314
-                    }} 
315
-                >
316
-                    { ({ errors, touched, validateField, validateForm, setFieldValue   }) =>  (
317
-
318
-                        <Form>
319
-                            <div className="data_product">
320
-                                <div className="row">
321
-                                    <div className="col-md-12">
322
-                                        {/* <input type="link" name="link" placeholder="Link de la plaza"/> */}
323
-                                        <Field type="link" name="link" placeholder="Link de la plaza"/>
324
-                                        {errors.link && touched.link && <div className="error_feedback">{errors.link}</div>}
325
-                                    </div>
326
-                                    <div className="add_producto_confirm">
327
-                                        <button className="btn_add_producto_confirm" type="submit">Agregar plaza</button>
328
-                                        {/* <div className="btn_add_producto_confirm"> */}
329
-                                        {/*     <span type="submit">Agregar plaza</span> */}
330
-                                        {/* </div> */}
331
-                                    </div>
332
-                                </div>
333
-                            </div>
334
-                        </Form>
335
-                    )}
336
-
337
-                </Formik>
338
-
339
-
340
-
341
-            </Modal.Body>
342
-        </Modal>
343
-    )
344
-}
345
-
346
-
347
 export function Puestos() {
146
 export function Puestos() {
348
 
147
 
349
     const [alignment, setAlignment] = React.useState('list');
148
     const [alignment, setAlignment] = React.useState('list');