import React, {
Component,
} from 'react';
import {
Row,
Col,
FormGroup,
Label,
Input,
} from 'reactstrap';
import {
FaFileImage,
} from 'react-icons/fa';
class VegetableMain extends Component {
constructor(props) {
super(props);
this.state = {
Vegetable: {
name: '',
lat: 0,
lng: 0,
description: '',
Pictures: [],
},
imagePreviewUrl: '',
};
this.handleChange = this.handleChange.bind(this);
}
componentWillReceiveProps(nextProps) {
console.log(nextProps)
if (nextProps.Vegetable) {
this.setState({
Vegetable: nextProps.Vegetable
});
}
if (nextProps.imagePreviewUrl) {
this.setState({
imagePreviewUrl: nextProps.imagePreviewUrl
});
}
}
handleChange(event) {
const target = event.target;
const value = target.type === 'checkbox' ? target.checked : target.value;
const name = target.name;
this.setState(prevState => ({
Vegetable: {
...prevState.Vegetable,
[name]: value,
},
}));
this.props.updateValue(name, value)
}
onImageChange(e) {
e.preventDefault();
const reader = new FileReader();
const file = e.target.files[0];
reader.onloadend = () => {
this.props.changeMainPicture(file, reader);
};
reader.readAsDataURL(file);
}
render() {
const {
imagePreviewUrl,
} = this.state;
let $imagePreview = null;
if (imagePreviewUrl) {
$imagePreview = ();
} else if (this.state.Vegetable.mainPicture) {
$imagePreview = (
);
} else {
$imagePreview = (