import React from 'react'; import PropTypes from 'prop-types'; import { Container, Row, Col, ListGroup, ListGroupItem, Badge, } from 'reactstrap'; import { NotificationContainer, NotificationManager, } from 'react-notifications'; import Api from '../Components/Api'; import MapItem from '../Components/Map'; import Vegetables from '../Components/Vegetables'; class RouterMap extends React.Component { constructor(props) { super(props); const { changeBackground, } = this.props; this.state = { types: [], selectedType: {}, selectedVegetable: {}, }; this.getVegetablesTypes = this.getVegetablesTypes.bind(this); this.selectType = this.selectType.bind(this); this.selectVegetable = this.selectVegetable.bind(this); this.getVegetablesTypes(); changeBackground('map'); } getVegetablesTypes() { Api.get('types') .then((res) => { this.setState({ types: res.data.rows, }); }) .catch(() => { NotificationManager.error('Erreur lors de la récupération des catégories'); }); } selectType(type) { this.setState({ selectedType: type, }); } selectVegetable(vegetable) { this.setState({ selectedVegetable: vegetable, }); } render() { const { selectedType, selectedVegetable, types, } = this.state; const { history, } = this.props; return (
{ types.map(type => ( this.selectType(type)} > {type.name} {type.Vegetables.length} )) }
); } } RouterMap.propTypes = { changeBackground: PropTypes.func.isRequired, history: PropTypes.shape().isRequired, }; export default RouterMap;