import React from 'react'; import { Modal, Button, ListGroup } from "react-bootstrap"; import PropTypes from 'prop-types'; import { FaWaze } from "react-icons/fa"; import { GiPositionMarker } from "react-icons/gi"; import { gasTypes } from "../config"; import { capitalizeFirstLetter, lowerCaseString } 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 { gasType, station, } = this.props; return ( {station.prices ? station.prices.map(price => { return ( {`${this.renderGasType(price.gasType)} : ${price.price.toString().replace('.', ',')} € `} ); }) : (null)} ) } /** * Méthode permettant de formater le titre de la modale en fonction des infos reçues * @return {string} */ renderFormatTitle = () => { const { station, } = this.props; if ( station.name ) { return station.name; } return `${lowerCaseString(station.address)} - ${capitalizeFirstLetter(station.city)}`; } renderAddress = () => { const { station, } = this.props; return (

{lowerCaseString(station.address)} {' - '} {capitalizeFirstLetter(station.city)}

); } render () { const { showModal, hideModal, } = this.props; return ( {this.renderFormatTitle()} {this.renderAddress()} {this.renderPrices()} ); } } GasStation.defaultProps = { station: { address: null, city: null, prices: [] } }; GasStation.propTypes = { gasType: PropTypes.string.isRequired, showModal: PropTypes.bool.isRequired, hideModal: PropTypes.func.isRequired, station: PropTypes.shape({ name: PropTypes.string, address: PropTypes.string, city: PropTypes.string, prices: PropTypes.array }), }; export default GasStation;