UNPKG

@kiwicom/smart-faq

Version:

Smart FAQ

203 lines (168 loc) 7.46 kB
"use strict"; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.UnwrappedGuaranteeNeededResolver = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf3 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _idx = _interopRequireDefault(require("idx")); var React = _interopRequireWildcard(require("react")); var _reactRelay = require("react-relay"); var _trackers = require("../helpers/analytics/trackers"); var _GuaranteeChatInfo = require("../context/GuaranteeChatInfo"); var _tracker = require("../cuckoo/tracker"); // @flow var GuaranteeNeededResolver = /*#__PURE__*/ function (_React$Component) { (0, _inherits2.default)(GuaranteeNeededResolver, _React$Component); function GuaranteeNeededResolver() { var _getPrototypeOf2; var _this; (0, _classCallCheck2.default)(this, GuaranteeNeededResolver); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = (0, _possibleConstructorReturn2.default)(this, (_getPrototypeOf2 = (0, _getPrototypeOf3.default)(GuaranteeNeededResolver)).call.apply(_getPrototypeOf2, [this].concat(args))); (0, _defineProperty2.default)((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)), "updateBookingInfo", function () { var _this$props = _this.props, booking = _this$props.booking, guaranteeChatBookingInfo = _this$props.guaranteeChatBookingInfo, onSetBookingInfo = _this$props.onSetBookingInfo; var bid = booking && parseInt(booking.databaseId, 10); if (bid === (0, _idx.default)(guaranteeChatBookingInfo, function (_) { return _.bid; })) { return; } var status = booking && booking.status; var departureCity = (0, _idx.default)(booking, function (_) { return _.upcomingLeg.departure.airport.city.name; }); var arrivalCity = (0, _idx.default)(booking, function (_) { return _.upcomingLeg.arrival.airport.city.name; }); var departureAirport = (0, _idx.default)(booking, function (_) { return _.upcomingLeg.departure.airport.code; }); var arrivalAirport = (0, _idx.default)(booking, function (_) { return _.upcomingLeg.arrival.airport.code; }); var phone = (0, _idx.default)(booking, function (_) { return _.contactDetails.phone; }); var email = (0, _idx.default)(booking, function (_) { return _.contactDetails.email; }); var firstName = (0, _idx.default)(booking, function (_) { return _.contactDetails.passenger.firstname; }); var lastName = (0, _idx.default)(booking, function (_) { return _.contactDetails.passenger.lastname; }); onSetBookingInfo({ bid: bid, status: status, departureCity: departureCity, departureAirport: departureAirport, arrivalCity: arrivalCity, arrivalAirport: arrivalAirport, phone: phone, email: email, firstName: firstName, lastName: lastName }); }); (0, _defineProperty2.default)((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)), "shouldShowGuaranteeChat", function () { var _this$props2 = _this.props, booking = _this$props2.booking, eventSource = _this$props2.eventSource; var forceGuaranteeChat = typeof window !== 'undefined' && window.GuaranteeChatForce; var showGuaranteeChat = (0, _idx.default)(booking, function (_) { return _.customerSupport.hasGuaranteeChat; }) || forceGuaranteeChat || false; if (showGuaranteeChat !== _this.props.showGuaranteeChat) { if (showGuaranteeChat) { (0, _trackers.simpleTracker)('smartFAQBookingOverview', { action: 'chatEnabled', where: eventSource }); (0, _tracker.track)('GuaranteeChat', 'chatEnabled', { where: eventSource }); } _this.props.toggleGuaranteeChat(Boolean(showGuaranteeChat)); } }); return _this; } (0, _createClass2.default)(GuaranteeNeededResolver, [{ key: "componentDidMount", value: function componentDidMount() { this.shouldShowGuaranteeChat(); this.updateBookingInfo(); } }, { key: "componentDidUpdate", value: function componentDidUpdate() { this.shouldShowGuaranteeChat(); this.updateBookingInfo(); } }, { key: "componentWillUnmount", value: function componentWillUnmount() { var _this$props3 = this.props, showGuaranteeChat = _this$props3.showGuaranteeChat, toggleGuaranteeChat = _this$props3.toggleGuaranteeChat; showGuaranteeChat && toggleGuaranteeChat(false); } }, { key: "render", value: function render() { return null; } }]); return GuaranteeNeededResolver; }(React.Component); var WrappedGuaranteeNeededResolver = function WrappedGuaranteeNeededResolver(_ref) { var booking = _ref.booking, eventSource = _ref.eventSource; return React.createElement(_GuaranteeChatInfo.GuaranteeChatContext.Consumer, null, function (_ref2) { var showGuaranteeChat = _ref2.showGuaranteeChat, enableChat = _ref2.enableChat, toggleGuaranteeChat = _ref2.toggleGuaranteeChat, onSetBookingInfo = _ref2.onSetBookingInfo, guaranteeChatBookingInfo = _ref2.guaranteeChatBookingInfo; if (!enableChat) { // do not process upcomingLeg info at all if chat is disabled return null; } return React.createElement(GuaranteeNeededResolver, { booking: booking, eventSource: eventSource, showGuaranteeChat: showGuaranteeChat, toggleGuaranteeChat: toggleGuaranteeChat, onSetBookingInfo: onSetBookingInfo, guaranteeChatBookingInfo: guaranteeChatBookingInfo }); }); }; var UnwrappedGuaranteeNeededResolver = GuaranteeNeededResolver; exports.UnwrappedGuaranteeNeededResolver = UnwrappedGuaranteeNeededResolver; var _default = (0, _reactRelay.createFragmentContainer)(WrappedGuaranteeNeededResolver, { booking: function booking() { var node = require("./__generated__/GuaranteeNeededResolver_booking.graphql"); if (node.hash && node.hash !== "1fceb95b60fd22b4afe55402fb876261") { console.error("The definition of 'GuaranteeNeededResolver_booking' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."); } return require("./__generated__/GuaranteeNeededResolver_booking.graphql"); } }); exports.default = _default;