Skip to content

Commit b51e20c

Browse files
feat(trip-details): make use of enhanced fare display
1 parent 60078f5 commit b51e20c

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

lib/components/narrative/connected-trip-details.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const TripDetails = styled(TripDetailsBase)`
1313

1414
const mapStateToProps = (state, ownProps) => {
1515
return {
16+
defaultFare: state.otp.config.itinerary?.defaultFare || undefined,
17+
keyMap: state.otp.config.itinerary?.fareKeyMap || {},
1618
longDateFormat: coreUtils.time.getLongDateFormat(state.otp.config),
1719
messages: state.otp.config.language.tripDetails,
1820
routingType: state.otp.currentQuery.routingType,

lib/components/narrative/default/default-itinerary.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ const ITINERARY_ATTRIBUTES = [
102102
{
103103
id: 'cost',
104104
order: 2,
105-
render: (itinerary, options) => {
105+
render: (itinerary, options, defaultFare = 'regular') => {
106106
return (
107107
<FormattedNumber
108108
currency={options.currency}
109109
currencyDisplay='narrowSymbol'
110110
style='currency'
111-
value={getTotalFare(itinerary, options.configCosts) / 100}
111+
value={getTotalFare(itinerary, options.configCosts, defaultFare) / 100}
112112
/>
113113
)
114114
}
@@ -166,6 +166,7 @@ class DefaultItinerary extends NarrativeItinerary {
166166
active,
167167
configCosts,
168168
currency,
169+
defaultFare,
169170
expanded,
170171
itinerary,
171172
LegIcon,
@@ -214,7 +215,7 @@ class DefaultItinerary extends NarrativeItinerary {
214215
options.currency = currency
215216
return (
216217
<li className={`${attribute.id}${isSelected ? ' main' : ''}`} key={attribute.id}>
217-
{attribute.render(itinerary, options)}
218+
{attribute.render(itinerary, options, defaultFare)}
218219
</li>
219220
)
220221
})
@@ -245,7 +246,8 @@ const mapStateToProps = (state, ownProps) => {
245246
// The configured (ambient) currency is needed for rendering the cost
246247
// of itineraries whether they include a fare or not, in which case
247248
// we show $0.00 or its equivalent in the configured currency and selected locale.
248-
currency: state.otp.config.localization?.currency || 'USD'
249+
currency: state.otp.config.localization?.currency || 'USD',
250+
defaultFare: state.otp.config.itinerary?.defaultFare
249251
}
250252
}
251253

lib/components/narrative/line-itin/itin-summary.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,15 @@ export class ItinerarySummary extends Component {
8787
}
8888

8989
render () {
90-
const { currency, itinerary } = this.props
90+
const { currency, defaultFare, itinerary } = this.props
9191
const { LegIcon } = this.context
9292

9393
const {
9494
maxTNCFare,
9595
minTNCFare,
96-
transitFare
96+
transitFares
9797
} = coreUtils.itinerary.calculateFares(itinerary)
98+
const transitFare = transitFares[defaultFare]?.transitFare
9899
// TODO: support non-USD
99100
const minTotalFare = minTNCFare * 100 + transitFare
100101
const maxTotalFare = maxTNCFare * 100 + transitFare
@@ -210,7 +211,8 @@ function getRouteColorForBadge (leg) {
210211

211212
const mapStateToProps = (state, ownProps) => {
212213
return {
213-
currency: state.otp.config.localization?.currency || 'USD'
214+
currency: state.otp.config.localization?.currency || 'USD',
215+
defaultFare: state.otp.config.itinerary?.defaultFare
214216
}
215217
}
216218
export default connect(mapStateToProps)(ItinerarySummary)

lib/components/narrative/tabbed-itineraries.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,16 @@ class TabButton extends Component {
118118
}
119119

120120
render () {
121-
const {currency, index, isActive, itinerary} = this.props
121+
const {currency, defaultFare, index, isActive, itinerary} = this.props
122122
const classNames = ['tab-button', 'clear-button-formatting']
123123
const { caloriesBurned } = calculatePhysicalActivity(itinerary)
124124
const {
125125
maxTNCFare,
126126
minTNCFare,
127-
transitFare
127+
transitFares
128128
} = calculateFares(itinerary)
129129
// TODO: support non-USD
130+
const transitFare = transitFares[defaultFare]?.transitFare
130131
const minTotalFare = minTNCFare * 100 + transitFare
131132
if (isActive) classNames.push('selected')
132133
return (
@@ -207,6 +208,7 @@ const mapStateToProps = (state, ownProps) => {
207208
activeStep: activeSearch && activeSearch.activeStep,
208209
companies: state.otp.currentQuery.companies,
209210
currency,
211+
defaultFare: state.otp.config.itinerary?.defaultFare,
210212
pending,
211213
// swap out realtime itineraries with non-realtime depending on boolean
212214
realtimeEffects,

lib/util/state.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ function calculateItineraryCost (itinerary, config = {}) {
330330
// If config contains values to override defaults, apply those.
331331
const configWeights = config.itinerary && config.itinerary.weights
332332
if (configWeights) Object.assign(weights, configWeights)
333-
return getTotalFare(itinerary, config.itinerary?.costs) * weights.fareFactor +
333+
return getTotalFare(itinerary, config.itinerary?.costs, config.itinerary?.defaultFare) * weights.fareFactor +
334334
itinerary.duration * weights.durationFactor +
335335
itinerary.walkDistance * weights.walkReluctance +
336336
getDriveTime(itinerary) * weights.driveReluctance +
@@ -369,9 +369,10 @@ const DEFAULT_COSTS = {
369369
* FIXME: Move to otp-ui?
370370
* TODO: Add GBFS fares
371371
*/
372-
export function getTotalFare (itinerary, configCosts = {}) {
372+
export function getTotalFare (itinerary, configCosts = {}, defaultFare = 'regular') {
373373
// Get transit/TNC fares.
374-
const {maxTNCFare, transitFare} = calculateFares(itinerary)
374+
const {maxTNCFare, transitFares} = calculateFares(itinerary)
375+
const transitFare = transitFares[defaultFare]?.transitFare
375376
// Start with default cost values.
376377
const costs = DEFAULT_COSTS
377378
// If config contains values to override defaults, apply those.

0 commit comments

Comments
 (0)