UNPKG

@kiwicom/smart-faq

Version:

220 lines (163 loc) 12.6 kB
"use strict"; require("core-js/modules/es.symbol"); require("core-js/modules/es.symbol.description"); require("core-js/modules/es.symbol.iterator"); require("core-js/modules/es.array.concat"); require("core-js/modules/es.array.iterator"); require("core-js/modules/es.function.name"); require("core-js/modules/es.object.get-own-property-descriptor"); require("core-js/modules/es.object.get-prototype-of"); require("core-js/modules/es.object.set-prototype-of"); require("core-js/modules/es.object.to-string"); require("core-js/modules/es.parse-int"); require("core-js/modules/es.string.iterator"); require("core-js/modules/web.dom-collections.iterator"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.UnwrappedGuaranteeNeededResolver = void 0; var React = _interopRequireWildcard(require("react")); var _reactRelay = require("react-relay"); var _context = _interopRequireDefault(require("@kiwicom/nitro/lib/services/log/context")); var _GuaranteeChatInfo = require("../context/GuaranteeChatInfo"); var _events = require("../../const/events"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var GuaranteeNeededResolver = /*#__PURE__*/ function (_React$Component) { _inherits(GuaranteeNeededResolver, _React$Component); function GuaranteeNeededResolver() { var _getPrototypeOf2; var _this; _classCallCheck(this, GuaranteeNeededResolver); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(GuaranteeNeededResolver)).call.apply(_getPrototypeOf2, [this].concat(args))); _defineProperty(_assertThisInitialized(_this), "updateBookingInfo", function () { var _booking$upcomingLeg, _booking$upcomingLeg$, _booking$upcomingLeg$2, _booking$upcomingLeg$3, _booking$upcomingLeg2, _booking$upcomingLeg3, _booking$upcomingLeg4, _booking$upcomingLeg5, _booking$upcomingLeg6, _booking$upcomingLeg7, _booking$upcomingLeg8, _booking$upcomingLeg9, _booking$upcomingLeg10, _booking$upcomingLeg11, _booking$contactDetai, _booking$contactDetai2, _booking$contactDetai3, _booking$contactDetai4, _booking$contactDetai5, _booking$contactDetai6; 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 === (guaranteeChatBookingInfo === null || guaranteeChatBookingInfo === void 0 ? void 0 : guaranteeChatBookingInfo.bid)) return; var status = booking && booking.status; var departureCity = booking === null || booking === void 0 ? void 0 : (_booking$upcomingLeg = booking.upcomingLeg) === null || _booking$upcomingLeg === void 0 ? void 0 : (_booking$upcomingLeg$ = _booking$upcomingLeg.departure) === null || _booking$upcomingLeg$ === void 0 ? void 0 : (_booking$upcomingLeg$2 = _booking$upcomingLeg$.airport) === null || _booking$upcomingLeg$2 === void 0 ? void 0 : (_booking$upcomingLeg$3 = _booking$upcomingLeg$2.city) === null || _booking$upcomingLeg$3 === void 0 ? void 0 : _booking$upcomingLeg$3.name; var arrivalCity = booking === null || booking === void 0 ? void 0 : (_booking$upcomingLeg2 = booking.upcomingLeg) === null || _booking$upcomingLeg2 === void 0 ? void 0 : (_booking$upcomingLeg3 = _booking$upcomingLeg2.arrival) === null || _booking$upcomingLeg3 === void 0 ? void 0 : (_booking$upcomingLeg4 = _booking$upcomingLeg3.airport) === null || _booking$upcomingLeg4 === void 0 ? void 0 : (_booking$upcomingLeg5 = _booking$upcomingLeg4.city) === null || _booking$upcomingLeg5 === void 0 ? void 0 : _booking$upcomingLeg5.name; var departureAirport = booking === null || booking === void 0 ? void 0 : (_booking$upcomingLeg6 = booking.upcomingLeg) === null || _booking$upcomingLeg6 === void 0 ? void 0 : (_booking$upcomingLeg7 = _booking$upcomingLeg6.departure) === null || _booking$upcomingLeg7 === void 0 ? void 0 : (_booking$upcomingLeg8 = _booking$upcomingLeg7.airport) === null || _booking$upcomingLeg8 === void 0 ? void 0 : _booking$upcomingLeg8.code; var arrivalAirport = booking === null || booking === void 0 ? void 0 : (_booking$upcomingLeg9 = booking.upcomingLeg) === null || _booking$upcomingLeg9 === void 0 ? void 0 : (_booking$upcomingLeg10 = _booking$upcomingLeg9.arrival) === null || _booking$upcomingLeg10 === void 0 ? void 0 : (_booking$upcomingLeg11 = _booking$upcomingLeg10.airport) === null || _booking$upcomingLeg11 === void 0 ? void 0 : _booking$upcomingLeg11.code; var phone = booking === null || booking === void 0 ? void 0 : (_booking$contactDetai = booking.contactDetails) === null || _booking$contactDetai === void 0 ? void 0 : _booking$contactDetai.phone; var email = booking === null || booking === void 0 ? void 0 : (_booking$contactDetai2 = booking.contactDetails) === null || _booking$contactDetai2 === void 0 ? void 0 : _booking$contactDetai2.email; var firstName = booking === null || booking === void 0 ? void 0 : (_booking$contactDetai3 = booking.contactDetails) === null || _booking$contactDetai3 === void 0 ? void 0 : (_booking$contactDetai4 = _booking$contactDetai3.passenger) === null || _booking$contactDetai4 === void 0 ? void 0 : _booking$contactDetai4.firstname; var lastName = booking === null || booking === void 0 ? void 0 : (_booking$contactDetai5 = booking.contactDetails) === null || _booking$contactDetai5 === void 0 ? void 0 : (_booking$contactDetai6 = _booking$contactDetai5.passenger) === null || _booking$contactDetai6 === void 0 ? void 0 : _booking$contactDetai6.lastname; onSetBookingInfo({ bid: bid, status: status, departureCity: departureCity, departureAirport: departureAirport, arrivalCity: arrivalCity, arrivalAirport: arrivalAirport, phone: phone, email: email, firstName: firstName, lastName: lastName }); }); _defineProperty(_assertThisInitialized(_this), "shouldShowGuaranteeChat", function () { var _ref, _booking$customerSupp; var _this$props2 = _this.props, booking = _this$props2.booking, eventSource = _this$props2.eventSource, log = _this$props2.log; var forceGuaranteeChat = typeof window !== 'undefined' && !!window.GuaranteeChatForce; var showGuaranteeChat = (_ref = booking === null || booking === void 0 ? void 0 : (_booking$customerSupp = booking.customerSupport) === null || _booking$customerSupp === void 0 ? void 0 : _booking$customerSupp.hasGuaranteeChat) !== null && _ref !== void 0 ? _ref : forceGuaranteeChat; if (showGuaranteeChat !== _this.props.showGuaranteeChat) { if (showGuaranteeChat) { log(_events.events.GUARANTEE_CHAT_ENABLED, { where: eventSource }); } _this.props.toggleGuaranteeChat(Boolean(showGuaranteeChat)); } }); return _this; } _createClass(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; if (showGuaranteeChat) { toggleGuaranteeChat(false); } } }, { key: "render", value: function render() { return null; } }]); return GuaranteeNeededResolver; }(React.Component); var WrappedGuaranteeNeededResolver = function WrappedGuaranteeNeededResolver(_ref2) { var booking = _ref2.booking, eventSource = _ref2.eventSource; var _React$useContext = React.useContext(_GuaranteeChatInfo.GuaranteeChatContext), showGuaranteeChat = _React$useContext.showGuaranteeChat, enableChat = _React$useContext.enableChat, toggleGuaranteeChat = _React$useContext.toggleGuaranteeChat, onSetBookingInfo = _React$useContext.onSetBookingInfo, guaranteeChatBookingInfo = _React$useContext.guaranteeChatBookingInfo; var _React$useContext2 = React.useContext(_context.default), log = _React$useContext2.log; if (!enableChat) { // do not process upcomingLeg info at all if chat is disabled return null; } return React.createElement(GuaranteeNeededResolver, { log: log, 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;