|
@@ -0,0 +1,149 @@
|
|
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">×</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
|
+}
|