|
1 | 1 | import React from 'react'; |
2 | 2 | import PropTypes from 'prop-types'; |
3 | | -import { FormattedMessage } from 'react-intl'; |
| 3 | +import { useIntl } from 'react-intl'; |
4 | 4 | import { legShape } from '../../util/shapes'; |
5 | 5 | import TransitLeg from './TransitLeg'; |
6 | | -import Icon from '../Icon'; |
| 6 | +import CallAgencyDisclaimer from './CallAgencyDisclaimer'; |
| 7 | +import RouteNumberContainer from '../RouteNumber'; |
| 8 | +import withBreakpoint from '../../util/withBreakpoint'; |
| 9 | +import { isLocalCallAgency } from '../../util/legUtils'; |
| 10 | +import { useConfigContext } from '../../configurations/ConfigContext'; |
7 | 11 |
|
8 | | -const CallAgencyLeg = ({ leg, ...props }) => { |
| 12 | +const CallAgencyLeg = ({ leg, breakpoint, ...props }) => { |
| 13 | + const intl = useIntl(); |
| 14 | + const config = useConfigContext(); |
9 | 15 | const modeClassName = 'call'; |
| 16 | + const { route } = leg; |
| 17 | + const mobile = breakpoint === 'small' || breakpoint === 'medium'; |
| 18 | + const notification = |
| 19 | + config.showRouteDescNotification && |
| 20 | + route.desc?.length && |
| 21 | + config.flex.infoLanguage === config.language // No translations available in the data at the moment |
| 22 | + ? { content: route.desc, link: route.url } |
| 23 | + : { |
| 24 | + content: intl.formatMessage({ id: 'call-agency-disclaimer' }), |
| 25 | + link: '', |
| 26 | + }; |
| 27 | + const key = `callAgencyNotification-${route.gtfsId}`; |
| 28 | + const routeNumber = ( |
| 29 | + <RouteNumberContainer |
| 30 | + route={leg.route} |
| 31 | + className={`line ${modeClassName}`} |
| 32 | + mode={modeClassName} |
| 33 | + vertical |
| 34 | + withBar |
| 35 | + isTransitLeg |
| 36 | + text={leg.route && leg.route.shortName} |
| 37 | + appendClass={isLocalCallAgency(leg, config) ? 'call-local' : ''} |
| 38 | + /> |
| 39 | + ); |
10 | 40 | return ( |
11 | | - <TransitLeg mode={modeClassName} leg={leg} {...props}> |
12 | | - <div className="itinerary-transit-leg-route call"> |
13 | | - <Icon img="icon_call" className="call-icon" /> |
14 | | - <span className="warning-message"> |
15 | | - <FormattedMessage |
16 | | - id="warning-call-agency" |
17 | | - values={{ |
18 | | - routeName: ( |
19 | | - <span className="route-name">{leg.route.longName}</span> |
20 | | - ), |
21 | | - }} |
22 | | - defaultMessage="Only on demand: {routeName}, which needs to be booked in advance." |
23 | | - /> |
24 | | - <div className="itinerary-warning-agency-container" /> |
25 | | - {leg.route.agency.phone && ( |
26 | | - <div className="call-button"> |
27 | | - <a href={`tel:${leg.route.agency.phone}`}> |
28 | | - <FormattedMessage |
29 | | - id="call-number" |
30 | | - defaultMessage="Call" |
31 | | - values={{ number: leg.route.agency.phone }} |
32 | | - /> |
33 | | - </a> |
34 | | - </div> |
35 | | - )} |
36 | | - </span> |
37 | | - </div> |
| 41 | + <TransitLeg |
| 42 | + mode={modeClassName} |
| 43 | + leg={leg} |
| 44 | + mobile={mobile} |
| 45 | + omitDivider |
| 46 | + {...props} |
| 47 | + > |
| 48 | + <CallAgencyDisclaimer |
| 49 | + key={key} |
| 50 | + text={notification.content} |
| 51 | + routeNumber={routeNumber} |
| 52 | + pickupBookingInfo={leg.pickupBookingInfo} |
| 53 | + agency={route.agency} |
| 54 | + route={route} |
| 55 | + mobile={mobile} |
| 56 | + header={intl.formatMessage({ id: 'on-demand-service' })} |
| 57 | + href={leg.pickupBookingInfo.contactInfo?.bookingUrl} |
| 58 | + linkText={intl.formatMessage({ id: 'open-app' })} |
| 59 | + /> |
38 | 60 | </TransitLeg> |
39 | 61 | ); |
40 | 62 | }; |
41 | 63 |
|
42 | 64 | CallAgencyLeg.propTypes = { |
43 | 65 | leg: legShape.isRequired, |
44 | 66 | index: PropTypes.number.isRequired, |
| 67 | + showRouteDescNotification: PropTypes.bool, |
| 68 | + breakpoint: PropTypes.string, |
| 69 | +}; |
| 70 | + |
| 71 | +CallAgencyLeg.defaultProps = { |
| 72 | + showRouteDescNotification: false, |
| 73 | + breakpoint: undefined, |
45 | 74 | }; |
46 | 75 |
|
47 | | -export default CallAgencyLeg; |
| 76 | +export { CallAgencyLeg as Component }; |
| 77 | +export default withBreakpoint(CallAgencyLeg); |
0 commit comments