import React from 'react'; import { Modal, Button, ListGroup } from "react-bootstrap"; import PropTypes from 'prop-types'; import { FaWaze } from "react-icons/fa"; import { gasTypes } from "../config"; import { capitalizeFirstLetter} from "../helpers"; class GasStation extends React.Component { /** * Méthode permettant de convertir un type de carburant en un nom lisible * @param {string} gasType * @return {mixed} */ renderGasType = (gasType) => { for( let i = 0 ; i < gasTypes.length ; i +=1 ) { if ( gasTypes[i].type === gasType) { return gasTypes[i].name; } } return (null); } /** * Méthode permettant de générer la liste des prix * return {string} */ renderPrices = () => { const { selectedGasType, selectedGasStation, } = this.props; return ( {selectedGasStation.prices ? selectedGasStation.prices.map(price => { return ( {`${this.renderGasType(price.gasType)} : ${price.price} € `} ); }) : (null)} ) } render () { const { showModal, hideModal, selectedGasStation, } = this.props; return ( {`${selectedGasStation.address} - ${capitalizeFirstLetter(selectedGasStation.city)}`} {this.renderPrices()} ); } } GasStation.defaultProps = { selectedGasStation: { address: null, city: null, prices: [] } }; GasStation.propTypes = { selectedGasType: PropTypes.string.isRequired, showModal: PropTypes.bool.isRequired, hideModal: PropTypes.func.isRequired, selectedGasStation: PropTypes.shape({ address: PropTypes.string, city: PropTypes.string, prices: PropTypes.array }), }; export default GasStation;