diff --git a/src/App.js b/src/App.js index 5e376c3..4d286dc 100644 --- a/src/App.js +++ b/src/App.js @@ -105,8 +105,8 @@ class Application extends React.Component { { const { - selectedGasType, - selectedGasStation, + gasType, + station, } = this.props; return ( - {selectedGasStation.prices ? selectedGasStation.prices.map(price => { + {station.prices ? station.prices.map(price => { return ( - + {`${this.renderGasType(price.gasType)} : ${price.price} € `} ); @@ -45,11 +45,25 @@ class GasStation extends React.Component { ) } + /** + * 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)}`; + } + render () { const { showModal, hideModal, - selectedGasStation, } = this.props; return ( @@ -62,7 +76,7 @@ class GasStation extends React.Component { > - {`${lowerCaseString(selectedGasStation.address)} - ${capitalizeFirstLetter(selectedGasStation.city)}`} + {this.renderFormatTitle()} @@ -79,7 +93,7 @@ class GasStation extends React.Component { } GasStation.defaultProps = { - selectedGasStation: { + station: { address: null, city: null, prices: [] @@ -87,10 +101,11 @@ GasStation.defaultProps = { }; GasStation.propTypes = { - selectedGasType: PropTypes.string.isRequired, + gasType: PropTypes.string.isRequired, showModal: PropTypes.bool.isRequired, hideModal: PropTypes.func.isRequired, - selectedGasStation: PropTypes.shape({ + station: PropTypes.shape({ + name: PropTypes.string, address: PropTypes.string, city: PropTypes.string, prices: PropTypes.array