|
@@ -16,10 +16,19 @@ import HighlightOffIcon from '@mui/icons-material/HighlightOff';
|
16
|
16
|
|
17
|
17
|
import NotFound from '../Images/not_found.png';
|
18
|
18
|
|
|
19
|
+
|
19
|
20
|
const NewPlazaSchema = Yup.object().shape({
|
20
|
21
|
nombre : Yup.string().required('El nombre es requerido').min(5).max(20),
|
21
|
22
|
description : Yup.string().required('La description es requerida').min(5).max(20),
|
22
|
|
- salario : Yup.number().required('El salario es requerido')
|
|
23
|
+ salario : Yup.number().required('El salario es requerido'),
|
|
24
|
+ imagen: Yup.mixed().required('El imagen es requerido').test('fileSize', "El archivo es demasiado grande", value => {
|
|
25
|
+ if(!value || value.length <= 0) return false
|
|
26
|
+ return value[0].size < 200000
|
|
27
|
+ }).test('fileType', "El tipo del archivo no es válido", value => {
|
|
28
|
+ let SUPPORTED_FORMATS = ["image/jpg", "image/jpeg", "image/gif", "image/png"];
|
|
29
|
+ if(!value) return false
|
|
30
|
+ return SUPPORTED_FORMATS.includes(value[0].type)
|
|
31
|
+ })
|
23
|
32
|
})
|
24
|
33
|
|
25
|
34
|
let data = [{
|
|
@@ -35,15 +44,12 @@ function* idMaker() {
|
35
|
44
|
yield index++;
|
36
|
45
|
}
|
37
|
46
|
|
38
|
|
-var ID = idMaker(); // "Generator { }"
|
|
47
|
+var ID = idMaker();
|
39
|
48
|
|
40
|
49
|
for ( var _ of new Array(46) ){
|
41
|
|
- data.push({
|
42
|
|
- ...data[0],
|
43
|
|
- id : ID.next().value,
|
44
|
|
- d : _
|
45
|
|
- })
|
|
50
|
+ data.push({ ...data[0], id : ID.next().value, d : _ })
|
46
|
51
|
}
|
|
52
|
+
|
47
|
53
|
function ListMode() {
|
48
|
54
|
|
49
|
55
|
let actions = [
|
|
@@ -68,7 +74,7 @@ function ListMode() {
|
68
|
74
|
|
69
|
75
|
{
|
70
|
76
|
data.length ?
|
71
|
|
- data.slice(0,23).map( (plaza, i) => {
|
|
77
|
+ data.slice( 0,23 ).map( (plaza, i) => {
|
72
|
78
|
return (
|
73
|
79
|
<tr key={plaza.id}>
|
74
|
80
|
<td className="text-center">{ plaza.nombre }</td>
|
|
@@ -152,28 +158,13 @@ function GridMode () {
|
152
|
158
|
|
153
|
159
|
function Manual ( props ) {
|
154
|
160
|
|
155
|
|
- let [ filename, setFilename ] = React.useState(null);
|
156
|
|
-
|
|
161
|
+ let [ filename, setFilename ] = React.useState('');
|
157
|
162
|
let { visible, onClose } = props
|
158
|
|
-
|
159
|
|
- // Create a reference to the hidden file input element
|
160
|
163
|
const hiddenFileInput = React.useRef(null);
|
161
|
164
|
|
162
|
|
- // Programatically click the hidden file input element
|
163
|
|
- // when the Button component is clicked
|
164
|
|
- const handleClick = event => {
|
|
165
|
+ const PickFile = event => {
|
165
|
166
|
hiddenFileInput.current.click();
|
166
|
167
|
};
|
167
|
|
- // Call a function (passed as a prop from the parent component)
|
168
|
|
- // to handle the user-selected file
|
169
|
|
- const handleChange = event => {
|
170
|
|
- const fileUploaded = event.target.files[0];
|
171
|
|
- // console.log( "FILE >> ", fileUploaded )
|
172
|
|
- setFilename( fileUploaded.name )
|
173
|
|
- //props.handleFile(fileUploaded);
|
174
|
|
- };
|
175
|
|
-
|
176
|
|
- const validateEmail = (value) => value === "Edgar";
|
177
|
168
|
|
178
|
169
|
return (
|
179
|
170
|
<Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered show={visible} onHide={onClose}>
|
|
@@ -184,18 +175,21 @@ function Manual ( props ) {
|
184
|
175
|
<Modal.Body className="modal-body">
|
185
|
176
|
|
186
|
177
|
<Formik
|
|
178
|
+
|
187
|
179
|
initialValues={{
|
188
|
180
|
nombre: '',
|
189
|
181
|
description: '',
|
190
|
182
|
salario: '',
|
|
183
|
+ imagen: '',
|
191
|
184
|
}}
|
|
185
|
+
|
192
|
186
|
validationSchema={NewPlazaSchema}
|
193
|
187
|
onSubmit={async (values) => {
|
194
|
188
|
console.log('VALUES >> ',values)
|
195
|
189
|
}} >
|
196
|
190
|
|
197
|
191
|
|
198
|
|
- { ({ errors, touched, validateField, validateForm }) => (
|
|
192
|
+ { ({ errors, touched, validateField, validateForm, setFieldValue }) => (
|
199
|
193
|
<Form>
|
200
|
194
|
<Row>
|
201
|
195
|
|
|
@@ -208,20 +202,28 @@ function Manual ( props ) {
|
208
|
202
|
<Col md="8">
|
209
|
203
|
|
210
|
204
|
<input
|
211
|
|
- value={ filename ? filename : "" }
|
|
205
|
+ value={filename}
|
212
|
206
|
type="text"
|
213
|
207
|
className="file-upload-input"
|
214
|
208
|
disabled=""
|
215
|
|
- placeholder="Ningún archivo seleccionado"/>
|
|
209
|
+ placeholder="Ningún archivo seleccionado" readOnly
|
|
210
|
+ />
|
216
|
211
|
|
217
|
|
- <Button className="btn_add_producto_confirm" style={{ marginLeft : 15 }} onClick={handleClick}>
|
|
212
|
+ <Button className="btn_add_producto_confirm" style={{ marginLeft : 15 }} onClick={PickFile}>
|
218
|
213
|
SUBIR FOTO
|
219
|
214
|
</Button>
|
220
|
215
|
|
|
216
|
+ {errors.imagen && touched.imagen && <div className="error_feedback">{errors.imagen}</div>}
|
221
|
217
|
<input
|
|
218
|
+ multiple={false}
|
222
|
219
|
type="file"
|
223
|
220
|
ref={hiddenFileInput}
|
224
|
|
- onChange={handleChange}
|
|
221
|
+ onChange={(event) => {
|
|
222
|
+ const files = event.target.files;
|
|
223
|
+ let myFiles =Array.from(files);
|
|
224
|
+ setFieldValue("imagen", myFiles);
|
|
225
|
+ setFilename(myFiles[0].name)
|
|
226
|
+ }}
|
225
|
227
|
style={{display: 'none'}}
|
226
|
228
|
/>
|
227
|
229
|
|
|
@@ -233,19 +235,19 @@ function Manual ( props ) {
|
233
|
235
|
<Col md="12">
|
234
|
236
|
|
235
|
237
|
{errors.nombre && touched.nombre && <div className="error_feedback">{errors.nombre}</div>}
|
236
|
|
- <Field name="nombre" placeholder="Nombre de la plaza" validate={validateEmail}/>
|
|
238
|
+ <Field name="nombre" placeholder="Nombre de la plaza"/>
|
237
|
239
|
|
238
|
240
|
{errors.description && touched.description && <div className="error_feedback">{errors.description}</div>}
|
239
|
241
|
<Field name="description">
|
240
|
242
|
{({ field, form, meta }) => {
|
241
|
243
|
return(
|
242
|
|
- <textarea id="description" name="description" defaultValue="" value={field.value} onChange={field.onChange} placeholder="Descripción general de la plaza"></textarea>
|
|
244
|
+ <textarea id="description" name="description" value={field.value} onChange={field.onChange} placeholder="Descripción general de la plaza"></textarea>
|
243
|
245
|
)
|
244
|
246
|
}}
|
245
|
247
|
</Field>
|
246
|
248
|
|
247
|
249
|
{errors.salario && touched.salario && <div className="error_feedback">{errors.salario}</div>}
|
248
|
|
- <Field name="salario" type="number" name="salario" placeholder="Salario"/>
|
|
250
|
+ <Field name="salario" type="number" placeholder="Salario"/>
|
249
|
251
|
|
250
|
252
|
|
251
|
253
|
</Col>
|