@opentripplanner/trip-details 1.5.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__mocks__/custom-messages.yml +7 -0
- package/esm/index.js +258 -126
- package/esm/index.js.map +1 -1
- package/esm/styled.js +30 -18
- package/esm/styled.js.map +1 -1
- package/esm/trip-detail.js +0 -9
- package/esm/trip-detail.js.map +1 -1
- package/esm/types.js +2 -0
- package/esm/types.js.map +1 -0
- package/i18n/en-US.yml +44 -0
- package/i18n/fr.yml +32 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +241 -122
- package/lib/index.js.map +1 -1
- package/lib/styled.d.ts +23 -0
- package/lib/styled.d.ts.map +1 -0
- package/lib/styled.js +40 -19
- package/lib/styled.js.map +1 -1
- package/lib/trip-detail.d.ts +18 -0
- package/lib/trip-detail.d.ts.map +1 -0
- package/lib/trip-detail.js +0 -12
- package/lib/trip-detail.js.map +1 -1
- package/lib/types.d.ts +67 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/package.json +11 -8
- package/src/TripDetails.story.tsx +273 -0
- package/src/__unpublished__/external-types.d.ts +22 -0
- package/src/__unpublished__/messages.d.ts +2 -0
- package/src/index.tsx +404 -0
- package/src/{styled.js → styled.ts} +6 -0
- package/src/{trip-detail.js → trip-detail.tsx} +17 -18
- package/src/types.ts +74 -0
- package/tsconfig.json +15 -0
- package/tsconfig.tsbuildinfo +4432 -0
- package/src/TripDetails.story.js +0 -147
- package/src/index.js +0 -262
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import flatten from "flat";
|
|
2
|
+
import React, { ReactElement } from "react";
|
|
3
|
+
import {
|
|
4
|
+
ComponentMeta,
|
|
5
|
+
ComponentStory,
|
|
6
|
+
Parameters,
|
|
7
|
+
StoryContext
|
|
8
|
+
} from "@storybook/react";
|
|
9
|
+
import styled from "styled-components";
|
|
10
|
+
// The below eslint-disable is due to https://github.com/storybookjs/storybook/issues/13408
|
|
11
|
+
// eslint-disable-next-line import/no-named-as-default
|
|
12
|
+
import TripDetails from ".";
|
|
13
|
+
import * as TripDetailsClasses from "./styled";
|
|
14
|
+
import {
|
|
15
|
+
CaloriesDetailsProps,
|
|
16
|
+
DepartureDetailsProps,
|
|
17
|
+
FareDetailsProps,
|
|
18
|
+
TripDetailsProps
|
|
19
|
+
} from "./types";
|
|
20
|
+
|
|
21
|
+
import customMessages from "../__mocks__/custom-messages.yml";
|
|
22
|
+
|
|
23
|
+
// import mock itinaries. These are all trip plan outputs from OTP.
|
|
24
|
+
const bikeOnlyItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/bike-only.json");
|
|
25
|
+
const bikeRentalItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/bike-rental.json");
|
|
26
|
+
const bikeRentalTransitBikeRentalItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/bike-rental-transit-bike-rental.json");
|
|
27
|
+
const bikeTransitBikeItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/bike-transit-bike.json");
|
|
28
|
+
const eScooterRentalItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/e-scooter-rental.json");
|
|
29
|
+
const eScooterRentalTransiteScooterRentalItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/e-scooter-transit-e-scooter.json");
|
|
30
|
+
const parkAndRideItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/park-and-ride.json");
|
|
31
|
+
const tncTransitTncItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/tnc-transit-tnc.json");
|
|
32
|
+
const walkInterlinedTransitItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-interlined-transit-walk.json");
|
|
33
|
+
const walkOnlyItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-only.json");
|
|
34
|
+
const walkTransitWalkItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-transit-walk.json");
|
|
35
|
+
const walkTransitWalkTransitWalkItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-transit-walk-transit-walk.json");
|
|
36
|
+
const fareComponentsItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/fare-components.json");
|
|
37
|
+
|
|
38
|
+
// Change currency code on one of the itineraries for illustration.
|
|
39
|
+
// (other currency fields in the itinerary object are not used for display).
|
|
40
|
+
const itinCurrency =
|
|
41
|
+
walkTransitWalkTransitWalkItinerary.fare.fare.regular.currency;
|
|
42
|
+
itinCurrency.currencyCode = "EUR";
|
|
43
|
+
|
|
44
|
+
const StyledTripDetails = styled(TripDetails)`
|
|
45
|
+
${TripDetailsClasses.TripDetailsHeader} {
|
|
46
|
+
background-color: pink;
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
const longDateFormat = "MMMM D, YYYY";
|
|
51
|
+
|
|
52
|
+
const englishFareKeyMap = {
|
|
53
|
+
regular: "Transit Fare",
|
|
54
|
+
student: "Student Fare",
|
|
55
|
+
senior: "Senior Fare",
|
|
56
|
+
tram: "Tram Fare",
|
|
57
|
+
special: "Special Fare",
|
|
58
|
+
youth: "Youth Fare",
|
|
59
|
+
electronicRegular: "Orca Fare",
|
|
60
|
+
electronicYouth: "Orca Youth Fare",
|
|
61
|
+
electronicSpecial: "Orca Special Fare",
|
|
62
|
+
electronicSenior: "Orca Senior Fare"
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const frenchFareKeyMap = {
|
|
66
|
+
regular: "Tarif en transports",
|
|
67
|
+
student: "Tarif étudiants",
|
|
68
|
+
senior: "Tarif séniors",
|
|
69
|
+
tram: "Tarif tram",
|
|
70
|
+
special: "Tarif spécial",
|
|
71
|
+
youth: "Tarif jeunes",
|
|
72
|
+
electronicRegular: "Tarif Orca",
|
|
73
|
+
electronicYouth: "Tarif Orca jeunes",
|
|
74
|
+
electronicSpecial: "Tarif Orca spécial",
|
|
75
|
+
electronicSenior: "Tarif Orca séniors"
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// Custom slots for expandable detail sections.
|
|
79
|
+
const CustomDepartureDetails = ({
|
|
80
|
+
departureDate
|
|
81
|
+
}: DepartureDetailsProps): ReactElement => (
|
|
82
|
+
<>
|
|
83
|
+
Custom messages about {departureDate.format(longDateFormat)} can be
|
|
84
|
+
constructed dynamically using any markup.
|
|
85
|
+
</>
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const CustomFareDetails = ({
|
|
89
|
+
maxTNCFare,
|
|
90
|
+
minTNCFare,
|
|
91
|
+
transitFares
|
|
92
|
+
}: FareDetailsProps): ReactElement => (
|
|
93
|
+
<>
|
|
94
|
+
Custom details about fares (transitFares: {JSON.stringify(transitFares)}{" "}
|
|
95
|
+
(cents), minTNCFare: {minTNCFare} and maxTNCFare: {maxTNCFare} can be
|
|
96
|
+
constructed dynamically using any markup.
|
|
97
|
+
</>
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const CustomCaloriesDetails = ({
|
|
101
|
+
bikeSeconds,
|
|
102
|
+
calories,
|
|
103
|
+
walkSeconds
|
|
104
|
+
}: CaloriesDetailsProps): ReactElement => (
|
|
105
|
+
<>
|
|
106
|
+
Custom message about {calories} calories burned,
|
|
107
|
+
{walkSeconds} seconds and {bikeSeconds} seconds.
|
|
108
|
+
</>
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Create a template component for each TripDetails story.
|
|
113
|
+
* A Component argument is passed. Once bound,
|
|
114
|
+
* the Component to render should not change.
|
|
115
|
+
* @param Component The component to render.
|
|
116
|
+
*/
|
|
117
|
+
function createTripDetailsTemplate(
|
|
118
|
+
Component: typeof TripDetails = TripDetails
|
|
119
|
+
): ComponentStory<typeof TripDetails> {
|
|
120
|
+
const TripDetailsTemplate = (
|
|
121
|
+
{
|
|
122
|
+
CaloriesDetails,
|
|
123
|
+
defaultFare,
|
|
124
|
+
DepartureDetails,
|
|
125
|
+
FareDetails,
|
|
126
|
+
itinerary
|
|
127
|
+
}: TripDetailsProps,
|
|
128
|
+
{ globals, parameters }: StoryContext
|
|
129
|
+
): ReactElement => {
|
|
130
|
+
const { locale } = globals;
|
|
131
|
+
const { useCustomFareKeyMap } = parameters;
|
|
132
|
+
const fareKeyNameMap = useCustomFareKeyMap
|
|
133
|
+
? locale === "en-US"
|
|
134
|
+
? englishFareKeyMap
|
|
135
|
+
: frenchFareKeyMap
|
|
136
|
+
: {};
|
|
137
|
+
return (
|
|
138
|
+
<Component
|
|
139
|
+
CaloriesDetails={CaloriesDetails}
|
|
140
|
+
defaultFare={defaultFare}
|
|
141
|
+
DepartureDetails={DepartureDetails}
|
|
142
|
+
FareDetails={FareDetails}
|
|
143
|
+
fareKeyNameMap={fareKeyNameMap}
|
|
144
|
+
itinerary={itinerary}
|
|
145
|
+
/>
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
return TripDetailsTemplate;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Helper to simplify story declaration.
|
|
153
|
+
*/
|
|
154
|
+
function makeStory(
|
|
155
|
+
args: TripDetailsProps,
|
|
156
|
+
parameters: Parameters,
|
|
157
|
+
Component?: typeof TripDetails
|
|
158
|
+
): ComponentStory<typeof TripDetails> {
|
|
159
|
+
const BoundTripDetails = createTripDetailsTemplate(Component).bind({});
|
|
160
|
+
BoundTripDetails.args = args;
|
|
161
|
+
BoundTripDetails.parameters = parameters;
|
|
162
|
+
return BoundTripDetails;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export default {
|
|
166
|
+
args: {
|
|
167
|
+
defaultFareKey: "regular"
|
|
168
|
+
},
|
|
169
|
+
component: TripDetails,
|
|
170
|
+
parameters: {
|
|
171
|
+
// Hide all controls
|
|
172
|
+
// (there are no args that the user can interactively change for this component).
|
|
173
|
+
controls: {
|
|
174
|
+
hideNoControlsWarning: true,
|
|
175
|
+
include: []
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
title: "TripDetails"
|
|
179
|
+
} as ComponentMeta<typeof TripDetails>;
|
|
180
|
+
|
|
181
|
+
export const WalkOnlyItinerary = makeStory({
|
|
182
|
+
itinerary: walkOnlyItinerary
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
export const BikeOnlyItinerary = makeStory({
|
|
186
|
+
itinerary: bikeOnlyItinerary
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
export const WalkTransitWalkItinerary = makeStory({
|
|
190
|
+
itinerary: walkTransitWalkItinerary
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
export const StyledWalkTransitWalkItinerary = makeStory(
|
|
194
|
+
{
|
|
195
|
+
itinerary: walkTransitWalkItinerary
|
|
196
|
+
},
|
|
197
|
+
null,
|
|
198
|
+
StyledTripDetails
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
export const BikeTransitBikeItinerary = makeStory({
|
|
202
|
+
itinerary: bikeTransitBikeItinerary
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
export const WalkInterlinedTransitItinerary = makeStory(
|
|
206
|
+
{
|
|
207
|
+
defaultFareKey: "electronicRegular",
|
|
208
|
+
itinerary: walkInterlinedTransitItinerary
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
useCustomFareKeyMap: true
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
export const WalkTransitTransferItinerary = makeStory({
|
|
216
|
+
itinerary: walkTransitWalkTransitWalkItinerary
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
export const BikeRentalItinerary = makeStory({
|
|
220
|
+
itinerary: bikeRentalItinerary
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
export const EScooterRentalItinerary = makeStory({
|
|
224
|
+
itinerary: eScooterRentalItinerary
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
export const ParkAndRideItinerary = makeStory({
|
|
228
|
+
itinerary: parkAndRideItinerary
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
export const BikeRentalTransitItinerary = makeStory({
|
|
232
|
+
itinerary: bikeRentalTransitBikeRentalItinerary
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
export const EScooterRentalTransitItinerary = makeStory({
|
|
236
|
+
itinerary: eScooterRentalTransiteScooterRentalItinerary
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
export const TncTransitItinerary = makeStory(
|
|
240
|
+
{
|
|
241
|
+
itinerary: tncTransitTncItinerary
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
useCustomFareKeyMap: true
|
|
245
|
+
}
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
const flattenedMessages = flatten(customMessages);
|
|
249
|
+
export const TncTransitItineraryWithCustomMessagesAndDetails = makeStory(
|
|
250
|
+
{
|
|
251
|
+
CaloriesDetails: CustomCaloriesDetails,
|
|
252
|
+
defaultFareKey: "electronicRegular",
|
|
253
|
+
DepartureDetails: CustomDepartureDetails,
|
|
254
|
+
FareDetails: CustomFareDetails,
|
|
255
|
+
itinerary: tncTransitTncItinerary
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
// For illustration purposes,
|
|
259
|
+
// override a subset of localized strings with custom messages.
|
|
260
|
+
reactIntl: {
|
|
261
|
+
messages: {
|
|
262
|
+
"en-US": flattenedMessages,
|
|
263
|
+
fr: flattenedMessages
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
useCustomFareKeyMap: true
|
|
267
|
+
},
|
|
268
|
+
StyledTripDetails
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
export const FlexItinerary = makeStory({
|
|
272
|
+
itinerary: fareComponentsItinerary
|
|
273
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Type declarations for dependencies that don't export types.
|
|
2
|
+
|
|
3
|
+
// Package velocity-react does not export types
|
|
4
|
+
// and does not exist in the @types repository.
|
|
5
|
+
declare module "velocity-react" {
|
|
6
|
+
// Important! imports must be within modules.
|
|
7
|
+
import { ReactElement } from "react";
|
|
8
|
+
|
|
9
|
+
interface TransitionInfo {
|
|
10
|
+
animation: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface VelocityTransitionGroupProps {
|
|
14
|
+
enter?: TransitionInfo;
|
|
15
|
+
leave?: TransitionInfo;
|
|
16
|
+
children?: ReactElement;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export declare function VelocityTransitionGroup(
|
|
20
|
+
props: VelocityTransitionGroupProps
|
|
21
|
+
): ReactElement;
|
|
22
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import flatten from "flat";
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3
|
+
// @ts-ignore FIXME: Create TypeScript types for core-utils packages.
|
|
4
|
+
import coreUtils from "@opentripplanner/core-utils";
|
|
5
|
+
import { FlexBookingInfo } from "@opentripplanner/types";
|
|
6
|
+
import React, { ReactElement } from "react";
|
|
7
|
+
import { FormattedMessage, FormattedNumber } from "react-intl";
|
|
8
|
+
import { CalendarAlt } from "@styled-icons/fa-solid/CalendarAlt";
|
|
9
|
+
import { HandPaper } from "@styled-icons/fa-solid/HandPaper";
|
|
10
|
+
import { Heartbeat } from "@styled-icons/fa-solid/Heartbeat";
|
|
11
|
+
import { MoneyBillAlt } from "@styled-icons/fa-solid/MoneyBillAlt";
|
|
12
|
+
import { PhoneVolume } from "@styled-icons/fa-solid/PhoneVolume";
|
|
13
|
+
import { Route } from "@styled-icons/fa-solid/Route";
|
|
14
|
+
|
|
15
|
+
import * as S from "./styled";
|
|
16
|
+
import TripDetail from "./trip-detail";
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
CaloriesDetailsProps,
|
|
20
|
+
TransitFareProps,
|
|
21
|
+
TripDetailsProps
|
|
22
|
+
} from "./types";
|
|
23
|
+
|
|
24
|
+
// Load the default messages.
|
|
25
|
+
import defaultEnglishMessages from "../i18n/en-US.yml";
|
|
26
|
+
|
|
27
|
+
// HACK: We should flatten the messages loaded above because
|
|
28
|
+
// the YAML loaders behave differently between webpack and our version of jest:
|
|
29
|
+
// - the yaml loader for webpack returns a nested object,
|
|
30
|
+
// - the yaml loader for jest returns messages with flattened ids.
|
|
31
|
+
const defaultMessages: Record<string, string> = flatten(defaultEnglishMessages);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Format text bold (used with FormattedMessage).
|
|
35
|
+
*/
|
|
36
|
+
// TODO: Find a better place for this utility.
|
|
37
|
+
function boldText(contents: ReactElement): ReactElement {
|
|
38
|
+
return <strong>{contents}</strong>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Render formatted fare.
|
|
43
|
+
* @param currencyCode The ISO currency code to use (USD, GBP, EUR).
|
|
44
|
+
* @param fare The fare value, in currency units, to be shown.
|
|
45
|
+
* @returns The formatted fare value according to the selected locale.
|
|
46
|
+
*/
|
|
47
|
+
function renderFare(currencyCode: string, fare: number): ReactElement {
|
|
48
|
+
return (
|
|
49
|
+
<FormattedNumber
|
|
50
|
+
currency={currencyCode}
|
|
51
|
+
// For dollars in locales such as 'fr',
|
|
52
|
+
// this will limit the display to just the dollar sign
|
|
53
|
+
// (otherwise it will render e.g. '2,50 $US' instead of '2,50 $').
|
|
54
|
+
currencyDisplay="narrowSymbol"
|
|
55
|
+
value={fare}
|
|
56
|
+
// eslint-disable-next-line react/style-prop-object
|
|
57
|
+
style="currency"
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Helper function to specify the link to dietary table.
|
|
64
|
+
*/
|
|
65
|
+
function dietaryLink(contents: ReactElement): ReactElement {
|
|
66
|
+
return (
|
|
67
|
+
<a
|
|
68
|
+
href="https://health.gov/dietaryguidelines/dga2005/document/html/chapter3.htm#table4"
|
|
69
|
+
rel="noopener noreferrer"
|
|
70
|
+
target="_blank"
|
|
71
|
+
>
|
|
72
|
+
{contents}
|
|
73
|
+
</a>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Helper function that assembles values for flex pickup/dropoff messages.
|
|
79
|
+
*/
|
|
80
|
+
function getFlexMessageValues(info: FlexBookingInfo) {
|
|
81
|
+
return {
|
|
82
|
+
hasLeadTime: coreUtils.itinerary.isAdvanceBookingRequired(info),
|
|
83
|
+
hasPhone: !!info?.contactInfo?.phoneNumber,
|
|
84
|
+
leadDays: info.latestBookingTime.daysPrior,
|
|
85
|
+
phoneNumber: info?.contactInfo?.phoneNumber
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Default rendering if no component is provided for the CaloriesDetails
|
|
91
|
+
* slot in the TripDetails component.
|
|
92
|
+
*/
|
|
93
|
+
function DefaultCaloriesDetails({
|
|
94
|
+
bikeSeconds,
|
|
95
|
+
calories,
|
|
96
|
+
walkSeconds
|
|
97
|
+
}: CaloriesDetailsProps): ReactElement {
|
|
98
|
+
return (
|
|
99
|
+
<FormattedMessage
|
|
100
|
+
defaultMessage={defaultMessages["otpUi.TripDetails.caloriesDescription"]}
|
|
101
|
+
description="Text describing how the calories relate to the walking and biking duration of a trip."
|
|
102
|
+
id="otpUi.TripDetails.caloriesDescription"
|
|
103
|
+
values={{
|
|
104
|
+
bikeMinutes: Math.round(bikeSeconds / 60),
|
|
105
|
+
calories: Math.round(calories),
|
|
106
|
+
dietaryLink,
|
|
107
|
+
strong: boldText,
|
|
108
|
+
walkMinutes: Math.round(walkSeconds / 60)
|
|
109
|
+
}}
|
|
110
|
+
/>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Helper component that renders a transit fare entry.
|
|
116
|
+
*/
|
|
117
|
+
const TransitFare = ({
|
|
118
|
+
fareKey,
|
|
119
|
+
fareNameFallback,
|
|
120
|
+
fareKeyNameMap,
|
|
121
|
+
transitFares
|
|
122
|
+
}: TransitFareProps): ReactElement => {
|
|
123
|
+
const currentFare = transitFares[fareKey];
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<span>
|
|
127
|
+
<FormattedMessage
|
|
128
|
+
defaultMessage={defaultMessages["otpUi.TripDetails.transitFareEntry"]}
|
|
129
|
+
description="Text showing the price of tickets on public transportation."
|
|
130
|
+
id="otpUi.TripDetails.transitFareEntry"
|
|
131
|
+
values={{
|
|
132
|
+
name: fareKeyNameMap[fareKey] || fareNameFallback || fareKey,
|
|
133
|
+
strong: boldText,
|
|
134
|
+
value: renderFare(
|
|
135
|
+
currentFare.currency.currencyCode,
|
|
136
|
+
currentFare.cents / 100
|
|
137
|
+
)
|
|
138
|
+
}}
|
|
139
|
+
/>
|
|
140
|
+
</span>
|
|
141
|
+
);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Renders trip details such as departure instructions, fare amount, and calories spent.
|
|
146
|
+
*/
|
|
147
|
+
export function TripDetails({
|
|
148
|
+
CaloriesDetails = DefaultCaloriesDetails,
|
|
149
|
+
className = "",
|
|
150
|
+
DepartureDetails = null,
|
|
151
|
+
defaultFareKey = "regular",
|
|
152
|
+
FareDetails = null,
|
|
153
|
+
fareKeyNameMap = {},
|
|
154
|
+
itinerary
|
|
155
|
+
}: TripDetailsProps): ReactElement {
|
|
156
|
+
// process the transit fare
|
|
157
|
+
const fareResult = coreUtils.itinerary.calculateTncFares(itinerary);
|
|
158
|
+
const { maxTNCFare, minTNCFare, tncCurrencyCode } = fareResult;
|
|
159
|
+
const transitFares = itinerary?.fare?.fare;
|
|
160
|
+
|
|
161
|
+
let companies = "";
|
|
162
|
+
itinerary.legs.forEach(leg => {
|
|
163
|
+
if (leg.tncData) {
|
|
164
|
+
companies = leg.tncData.company;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
let fare;
|
|
168
|
+
|
|
169
|
+
const fareKeys = transitFares && Object.keys(transitFares).sort();
|
|
170
|
+
|
|
171
|
+
if (transitFares && fareKeys.length > 0) {
|
|
172
|
+
let defaultFare = defaultFareKey;
|
|
173
|
+
if (!transitFares[defaultFareKey]) {
|
|
174
|
+
defaultFare = "regular";
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Depending on if there are additional fares to display either render a <span> or a <details>
|
|
178
|
+
const TransitFareWrapper =
|
|
179
|
+
transitFares && fareKeys.length > 1 ? S.TransitFare : S.TransitFareSingle;
|
|
180
|
+
|
|
181
|
+
fare = (
|
|
182
|
+
<S.Fare>
|
|
183
|
+
<TransitFareWrapper>
|
|
184
|
+
<summary style={{ display: fareKeys.length > 1 ? "list-item" : "" }}>
|
|
185
|
+
<TransitFare
|
|
186
|
+
fareNameFallback={
|
|
187
|
+
<FormattedMessage
|
|
188
|
+
defaultMessage={
|
|
189
|
+
defaultMessages["otpUi.TripDetails.transitFare"]
|
|
190
|
+
}
|
|
191
|
+
description="Text showing the price of tickets on public transportation."
|
|
192
|
+
id="otpUi.TripDetails.transitFare"
|
|
193
|
+
/>
|
|
194
|
+
}
|
|
195
|
+
fareKey={defaultFare}
|
|
196
|
+
fareKeyNameMap={fareKeyNameMap}
|
|
197
|
+
transitFares={transitFares}
|
|
198
|
+
/>
|
|
199
|
+
</summary>
|
|
200
|
+
{fareKeys.map(fareKey => {
|
|
201
|
+
// Don't show the default fare twice!
|
|
202
|
+
if (fareKey === defaultFare) {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
return (
|
|
206
|
+
<TransitFare
|
|
207
|
+
fareKey={fareKey}
|
|
208
|
+
key={fareKey}
|
|
209
|
+
fareKeyNameMap={fareKeyNameMap}
|
|
210
|
+
transitFares={transitFares}
|
|
211
|
+
/>
|
|
212
|
+
);
|
|
213
|
+
})}
|
|
214
|
+
</TransitFareWrapper>
|
|
215
|
+
{minTNCFare !== 0 && (
|
|
216
|
+
<S.TNCFare>
|
|
217
|
+
<br />
|
|
218
|
+
<FormattedMessage
|
|
219
|
+
defaultMessage={defaultMessages["otpUi.TripDetails.tncFare"]}
|
|
220
|
+
description="Text showing the price paid to transportation network companies."
|
|
221
|
+
id="otpUi.TripDetails.tncFare"
|
|
222
|
+
values={{
|
|
223
|
+
companies: (
|
|
224
|
+
// S.TNCFareCompanies capitalizes the TNC company ID (e.g. "COMPANY")
|
|
225
|
+
// after it is converted to lowercase, so it renders as "Company".
|
|
226
|
+
<S.TNCFareCompanies>
|
|
227
|
+
{companies.toLowerCase()}
|
|
228
|
+
</S.TNCFareCompanies>
|
|
229
|
+
),
|
|
230
|
+
maxTNCFare: renderFare(tncCurrencyCode, maxTNCFare),
|
|
231
|
+
minTNCFare: renderFare(tncCurrencyCode, minTNCFare),
|
|
232
|
+
strong: boldText
|
|
233
|
+
}}
|
|
234
|
+
/>
|
|
235
|
+
</S.TNCFare>
|
|
236
|
+
)}
|
|
237
|
+
</S.Fare>
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const departureDate = new Date(itinerary.startTime);
|
|
242
|
+
|
|
243
|
+
// Compute calories burned.
|
|
244
|
+
const {
|
|
245
|
+
bikeDuration,
|
|
246
|
+
caloriesBurned,
|
|
247
|
+
walkDuration
|
|
248
|
+
} = coreUtils.itinerary.calculatePhysicalActivity(itinerary);
|
|
249
|
+
|
|
250
|
+
// Parse flex info and generate appropriate strings
|
|
251
|
+
const containsFlex = itinerary.legs.some(coreUtils.itinerary.isFlex);
|
|
252
|
+
const pickupBookingInfo = itinerary.legs
|
|
253
|
+
.map(leg => leg.pickupBookingInfo)
|
|
254
|
+
.filter(info => !!info);
|
|
255
|
+
const dropOffBookingInfo = itinerary.legs
|
|
256
|
+
.map(leg => leg.dropOffBookingInfo)
|
|
257
|
+
.filter(info => !!info);
|
|
258
|
+
|
|
259
|
+
return (
|
|
260
|
+
<S.TripDetails className={className}>
|
|
261
|
+
<S.TripDetailsHeader>
|
|
262
|
+
<FormattedMessage
|
|
263
|
+
defaultMessage={defaultMessages["otpUi.TripDetails.title"]}
|
|
264
|
+
description="Title (heading) text of the component."
|
|
265
|
+
id="otpUi.TripDetails.title"
|
|
266
|
+
/>
|
|
267
|
+
</S.TripDetailsHeader>
|
|
268
|
+
<S.TripDetailsBody>
|
|
269
|
+
<TripDetail
|
|
270
|
+
// Any custom description for the Departure message needs to be handled by the slot.
|
|
271
|
+
description={
|
|
272
|
+
DepartureDetails && (
|
|
273
|
+
<DepartureDetails departureDate={departureDate} />
|
|
274
|
+
)
|
|
275
|
+
}
|
|
276
|
+
icon={<CalendarAlt size={17} />}
|
|
277
|
+
summary={
|
|
278
|
+
<S.Timing>
|
|
279
|
+
<FormattedMessage
|
|
280
|
+
defaultMessage={defaultMessages["otpUi.TripDetails.departure"]}
|
|
281
|
+
description="Text showing the departure date/time for a trip."
|
|
282
|
+
id="otpUi.TripDetails.departure"
|
|
283
|
+
values={{
|
|
284
|
+
departureDate,
|
|
285
|
+
strong: boldText
|
|
286
|
+
}}
|
|
287
|
+
/>
|
|
288
|
+
</S.Timing>
|
|
289
|
+
}
|
|
290
|
+
/>
|
|
291
|
+
{fare && (
|
|
292
|
+
<TripDetail
|
|
293
|
+
// Any custom description for the transit fare needs to be handled by the slot.
|
|
294
|
+
description={
|
|
295
|
+
FareDetails && (
|
|
296
|
+
<FareDetails
|
|
297
|
+
maxTNCFare={maxTNCFare}
|
|
298
|
+
minTNCFare={minTNCFare}
|
|
299
|
+
transitFares={transitFares}
|
|
300
|
+
/>
|
|
301
|
+
)
|
|
302
|
+
}
|
|
303
|
+
icon={<MoneyBillAlt size={17} />}
|
|
304
|
+
summary={fare}
|
|
305
|
+
/>
|
|
306
|
+
)}
|
|
307
|
+
{caloriesBurned > 0 && (
|
|
308
|
+
<TripDetail
|
|
309
|
+
icon={<Heartbeat size={17} />}
|
|
310
|
+
summary={
|
|
311
|
+
<S.CaloriesSummary>
|
|
312
|
+
<FormattedMessage
|
|
313
|
+
defaultMessage={defaultMessages["otpUi.TripDetails.calories"]}
|
|
314
|
+
description="Text showing the number of calories for the walking and biking legs of a trip."
|
|
315
|
+
id="otpUi.TripDetails.calories"
|
|
316
|
+
values={{
|
|
317
|
+
calories: caloriesBurned,
|
|
318
|
+
strong: boldText
|
|
319
|
+
}}
|
|
320
|
+
/>
|
|
321
|
+
</S.CaloriesSummary>
|
|
322
|
+
}
|
|
323
|
+
description={
|
|
324
|
+
CaloriesDetails && (
|
|
325
|
+
<CaloriesDetails
|
|
326
|
+
bikeSeconds={bikeDuration}
|
|
327
|
+
calories={caloriesBurned}
|
|
328
|
+
walkSeconds={walkDuration}
|
|
329
|
+
/>
|
|
330
|
+
)
|
|
331
|
+
}
|
|
332
|
+
/>
|
|
333
|
+
)}
|
|
334
|
+
{containsFlex && (
|
|
335
|
+
<TripDetail
|
|
336
|
+
summary={
|
|
337
|
+
<S.FlexSummary>
|
|
338
|
+
<FormattedMessage
|
|
339
|
+
defaultMessage={
|
|
340
|
+
defaultMessages["otpUi.TripDetails.tripIncludesFlex"]
|
|
341
|
+
}
|
|
342
|
+
description="Text stating that portions of the trip include a flex (on-demand) transit service."
|
|
343
|
+
id="otpUi.TripDetails.tripIncludesFlex"
|
|
344
|
+
/>
|
|
345
|
+
</S.FlexSummary>
|
|
346
|
+
}
|
|
347
|
+
icon={<Route size={17} />}
|
|
348
|
+
/>
|
|
349
|
+
)}
|
|
350
|
+
{pickupBookingInfo &&
|
|
351
|
+
pickupBookingInfo.map(info => (
|
|
352
|
+
<TripDetail
|
|
353
|
+
key={info.pickupMessage}
|
|
354
|
+
icon={<PhoneVolume size={17} />}
|
|
355
|
+
summary={
|
|
356
|
+
<S.FlexPickupSummary>
|
|
357
|
+
<FormattedMessage
|
|
358
|
+
defaultMessage={
|
|
359
|
+
defaultMessages["otpUi.TripDetails.flexPickupMessage"]
|
|
360
|
+
}
|
|
361
|
+
description="Instructions for booking and boarding the flex (on-demand) transit service."
|
|
362
|
+
id="otpUi.TripDetails.flexPickupMessage"
|
|
363
|
+
values={getFlexMessageValues(info)}
|
|
364
|
+
/>
|
|
365
|
+
</S.FlexPickupSummary>
|
|
366
|
+
}
|
|
367
|
+
description={info.pickupMessage}
|
|
368
|
+
/>
|
|
369
|
+
))}
|
|
370
|
+
{dropOffBookingInfo &&
|
|
371
|
+
dropOffBookingInfo.map(info => (
|
|
372
|
+
<TripDetail
|
|
373
|
+
description={info.dropOffMessage}
|
|
374
|
+
icon={
|
|
375
|
+
coreUtils.itinerary.isAdvanceBookingRequired(info) ? (
|
|
376
|
+
<PhoneVolume size={17} />
|
|
377
|
+
) : (
|
|
378
|
+
<HandPaper size={17} />
|
|
379
|
+
)
|
|
380
|
+
}
|
|
381
|
+
key={info.dropOffMessage}
|
|
382
|
+
summary={
|
|
383
|
+
<S.FlexDropOffSummary>
|
|
384
|
+
<FormattedMessage
|
|
385
|
+
defaultMessage={
|
|
386
|
+
defaultMessages["otpUi.TripDetails.flexDropOffMessage"]
|
|
387
|
+
}
|
|
388
|
+
description="Instructions for getting off the flex (on-demand) transit service."
|
|
389
|
+
id="otpUi.TripDetails.flexDropOffMessage"
|
|
390
|
+
values={getFlexMessageValues(info)}
|
|
391
|
+
/>
|
|
392
|
+
</S.FlexDropOffSummary>
|
|
393
|
+
}
|
|
394
|
+
/>
|
|
395
|
+
))}
|
|
396
|
+
</S.TripDetailsBody>
|
|
397
|
+
</S.TripDetails>
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export default TripDetails;
|
|
402
|
+
|
|
403
|
+
// Rename styled components for export
|
|
404
|
+
export { S as Styled };
|