mirror of
https://github.com/HSLdevcom/digitransit-ui
synced 2026-02-22 16:35:47 +01:00
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
import PropTypes from 'prop-types';
|
|
import React from 'react';
|
|
import SettingsToggle from './SettingsToggle';
|
|
import { saveRoutingSettings } from '../../../action/SearchSettingsActions';
|
|
import { addAnalyticsEvent } from '../../../util/analyticsUtils';
|
|
import { settingsShape } from '../../../util/shapes';
|
|
import { useConfigContext } from '../../../configurations/ConfigContext';
|
|
|
|
export default function TransferOptions(
|
|
{ defaultSettings, currentSettings },
|
|
{ executeAction },
|
|
) {
|
|
const { transferPenaltyHigh } = useConfigContext();
|
|
const avoidTransfers =
|
|
currentSettings.transferPenalty !== defaultSettings.transferPenalty;
|
|
|
|
const onToggle = () => {
|
|
executeAction(saveRoutingSettings, {
|
|
transferPenalty: avoidTransfers
|
|
? defaultSettings.transferPenalty
|
|
: transferPenaltyHigh,
|
|
});
|
|
addAnalyticsEvent({
|
|
category: 'ItinerarySettings',
|
|
action: 'changeNumberOfTransfers',
|
|
name: avoidTransfers,
|
|
});
|
|
};
|
|
|
|
return (
|
|
<SettingsToggle
|
|
id="settings-toggle-transfers"
|
|
labelId="avoid-transfers"
|
|
toggled={avoidTransfers}
|
|
onToggle={onToggle}
|
|
/>
|
|
);
|
|
}
|
|
|
|
TransferOptions.propTypes = {
|
|
defaultSettings: settingsShape.isRequired,
|
|
currentSettings: settingsShape.isRequired,
|
|
};
|
|
|
|
TransferOptions.contextTypes = {
|
|
executeAction: PropTypes.func.isRequired,
|
|
};
|