@kiwicom/smart-faq
Version:
363 lines (264 loc) • 18.5 kB
JavaScript
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.symbol.replace");
require("core-js/modules/es.array.concat");
require("core-js/modules/es.array.includes");
require("core-js/modules/es.array.index-of");
require("core-js/modules/es.array.iterator");
require("core-js/modules/es.array.reduce");
require("core-js/modules/es.date.to-string");
require("core-js/modules/es.map");
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.keys");
require("core-js/modules/es.object.set-prototype-of");
require("core-js/modules/es.object.to-string");
require("core-js/modules/es.reflect.construct");
require("core-js/modules/es.regexp.constructor");
require("core-js/modules/es.regexp.exec");
require("core-js/modules/es.regexp.to-string");
require("core-js/modules/es.string.includes");
require("core-js/modules/es.string.iterator");
require("core-js/modules/es.string.match");
require("core-js/modules/es.string.replace");
require("core-js/modules/es.weak-map");
require("core-js/modules/web.dom-collections.iterator");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _style = _interopRequireDefault(require("styled-jsx/style"));
var React = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _Text = _interopRequireDefault(require("@kiwicom/orbit-components/lib/Text"));
var _AccountCircle = _interopRequireDefault(require("@kiwicom/orbit-components/lib/icons/AccountCircle"));
var _Trip = _interopRequireDefault(require("@kiwicom/orbit-components/lib/icons/Trip"));
var _Search = _interopRequireDefault(require("@kiwicom/orbit-components/lib/icons/Search"));
var _reactRouterDom = require("react-router-dom");
var _CloseButton = _interopRequireDefault(require("../common/buttons/CloseButton"));
var _User = require("../context/User");
var _SearchState = require("../context/SearchState");
var _SelectedBooking = require("../context/SelectedBooking");
var _BackButtonMobile = _interopRequireDefault(require("./BackButtonMobile"));
var _MobileNearestBooking = _interopRequireDefault(require("./MobileNearestBooking"));
var _MobileSelectedBooking = _interopRequireDefault(require("./MobileSelectedBooking"));
var _MobileUserDetail = _interopRequireDefault(require("./MobileUserDetail"));
var _SearchBar = _interopRequireDefault(require("../../shared/StaticFAQ/SearchBar"));
var _UrlHelpers = require("../helpers/UrlHelpers");
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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 _wrapRegExp(re, groups) { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, groups); }; var _RegExp = _wrapNativeSuper(RegExp); var _super = RegExp.prototype; var _groups = new WeakMap(); function BabelRegExp(re, groups) { var _this = _RegExp.call(this, re); _groups.set(_this, groups); return _this; } _inherits(BabelRegExp, _RegExp); BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) result.groups = buildGroups(result, this); return result; }; BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if (typeof substitution === "string") { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { return "$" + groups[name]; })); } else if (typeof substitution === "function") { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = []; args.push.apply(args, arguments); if (_typeof(args[args.length - 1]) !== "object") { args.push(buildGroups(args, _this)); } return substitution.apply(this, args); }); } else { return _super[Symbol.replace].call(this, str, substitution); } }; function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { groups[name] = result[g[name]]; return groups; }, Object.create(null)); } return _wrapRegExp.apply(this, arguments); }
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
function _construct(Parent, args, Class) { if (isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
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 MobileBookingPage = function MobileBookingPage(props
/*: MobileBookingPageProps*/
) {
var bookingPage = props.bookingPage,
selectedBooking = props.selectedBooking;
if (bookingPage === 'SINGLE_BOOKING') {
if (selectedBooking) {
return React.createElement(_MobileSelectedBooking.default, {
bookingId: selectedBooking
});
}
return React.createElement(_MobileNearestBooking.default, null);
}
return null;
};
var MobileBookingSummary = function MobileBookingSummary() {
return React.createElement("div", null, React.createElement(_SelectedBooking.SelectedBooking.Consumer, null, function (_ref) {
var bookingPage = _ref.bookingPage,
selectedBooking = _ref.selectedBooking;
return React.createElement(MobileBookingPage, {
bookingPage: bookingPage,
selectedBooking: selectedBooking
});
}));
};
var MobileBookingHeaderStyle = new String(".MobileBookingHeader.jsx-3529113770{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;background-color:#f5f7f9;box-shadow:inset 0 1px 0 0 #e8edf1;}.option.jsx-3529113770{-webkit-flex:1;-ms-flex:1;flex:1;padding:19px;text-align:center;background-color:#fff;border:1px solid #eaeaea;outline:none;}.option.help.jsx-3529113770{display:none;}.option.active.jsx-3529113770{background-color:#f5f7f9;}.openedContent.jsx-3529113770{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;background-color:#f5f7f9;box-shadow:inset 0 1px 0 0 #e8edf1;padding:8px 16px;}.openedContent.hidden.jsx-3529113770{display:none;}@media screen and (max-height:480px){.option.help.jsx-3529113770{-webkit-flex:7;-ms-flex:7;flex:7;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}}");
MobileBookingHeaderStyle.__hash = "3529113770";
/*:: type Props = {|
...ContextRouter,
|};*/
/*:: type State = {
activeTab: 'search' | 'summary' | 'account' | null,
};*/
var MobileBookingHeader =
/*#__PURE__*/
function (_React$Component) {
_inherits(MobileBookingHeader, _React$Component);
function MobileBookingHeader() {
var _getPrototypeOf2;
var _this;
_classCallCheck(this, MobileBookingHeader);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(MobileBookingHeader)).call.apply(_getPrototypeOf2, [this].concat(args)));
_defineProperty(_assertThisInitialized(_this), "state", {
activeTab: null
});
_defineProperty(_assertThisInitialized(_this), "contextEnableSearch", function () {});
_defineProperty(_assertThisInitialized(_this), "contextDisableSearch", function () {});
_defineProperty(_assertThisInitialized(_this), "contextToggleSearch", function () {});
_defineProperty(_assertThisInitialized(_this), "toggleSearch", function () {
if (_this.isSearchActive()) {
_this.setState({
activeTab: null
});
_this.contextDisableSearch();
} else {
_this.setState({
activeTab: 'search'
});
_this.contextEnableSearch();
}
});
_defineProperty(_assertThisInitialized(_this), "toggleSummary", function () {
_this.setState(function (prevState) {
return {
activeTab: prevState.activeTab === 'summary' ? null : 'summary'
};
});
_this.contextDisableSearch();
});
_defineProperty(_assertThisInitialized(_this), "toggleAccount", function () {
_this.setState(function (prevState) {
return {
activeTab: prevState.activeTab === 'account' ? null : 'account'
};
});
_this.contextDisableSearch();
});
_defineProperty(_assertThisInitialized(_this), "goBack", function () {
var history = _this.props.history;
var pathname = history.location.pathname;
if (pathname.includes('article')) {
var _ref2, _pathname$match, _pathname$match$group;
var url = (_ref2 = (_pathname$match = pathname.match(_wrapRegExp(/(.*)?=article/, {
url: 1
}))) === null || _pathname$match === void 0 ? void 0 : (_pathname$match$group = _pathname$match.groups) === null || _pathname$match$group === void 0 ? void 0 : _pathname$match$group.url) !== null && _ref2 !== void 0 ? _ref2 : '';
return history.push(url);
} else if (pathname.includes('faq')) {
return history.push('/faq');
}
throw new Error("Couldn't go back. This should not happen");
});
return _this;
}
_createClass(MobileBookingHeader, [{
key: "componentDidMount",
value: function componentDidMount() {
this.contextToggleSearch();
}
}, {
key: "isSearchActive",
value: function isSearchActive() {
return this.state.activeTab === 'search';
}
}, {
key: "render",
value: function render() {
var _this2 = this;
var activeTab = this.state.activeTab;
return React.createElement(React.Fragment, null, React.createElement(_SelectedBooking.SelectedBooking.Consumer, null, function (_ref3) {
var closeAllBooking = _ref3.closeAllBooking;
return React.createElement(_SearchState.SearchState.Consumer, null, function (_ref4) {
var _this2$props$match$pa;
var disableSearch = _ref4.disableSearch,
enableSearch = _ref4.enableSearch,
toggleSearch = _ref4.toggleSearch;
_this2.contextEnableSearch = enableSearch;
_this2.contextDisableSearch = disableSearch;
_this2.contextToggleSearch = toggleSearch;
var location = _this2.props.history.location;
var currentpath = location && location.pathname;
var isArticle = currentpath.includes('article/');
var hasCategory = (_this2$props$match$pa = _this2.props.match.params.categoryId) !== null && _this2$props$match$pa !== void 0 ? _this2$props$match$pa : null;
var buttonEvent = function buttonEvent(eventHandler) {
return function () {
eventHandler();
closeAllBooking();
};
};
return React.createElement("div", {
className: "jsx-".concat(MobileBookingHeaderStyle.__hash) + " " + "MobileBookingHeader"
}, isArticle || hasCategory ? React.createElement("div", {
onClick: buttonEvent(_this2.goBack),
onKeyUp: buttonEvent(_this2.goBack),
role: "button",
tabIndex: "-1",
className: "jsx-".concat(MobileBookingHeaderStyle.__hash) + " " + "option"
}, React.createElement(_BackButtonMobile.default, null)) : null, React.createElement("div", {
className: "jsx-".concat(MobileBookingHeaderStyle.__hash) + " " + "option help"
}, React.createElement(_Text.default, {
type: "primary",
weight: "bold"
}, "Help")), React.createElement("div", {
onClick: buttonEvent(_this2.toggleSearch),
onKeyDown: buttonEvent(_this2.toggleSearch),
role: "button",
tabIndex: "0",
"data-cy": "search-button",
className: "jsx-".concat(MobileBookingHeaderStyle.__hash) + " " + ((_this2.isSearchActive() ? 'option active' : 'option') || "")
}, React.createElement(_Search.default, {
size: "medium",
customColor: "#45505d"
})), React.createElement("div", {
onClick: buttonEvent(_this2.toggleSummary),
onKeyDown: buttonEvent(_this2.toggleSummary),
role: "button",
tabIndex: "0",
"data-cy": "trip-button",
className: "jsx-".concat(MobileBookingHeaderStyle.__hash) + " " + ((activeTab === 'summary' ? 'option active' : 'option') || "")
}, React.createElement(_Trip.default, {
size: "medium",
customColor: "#45505d"
})), React.createElement(_User.UserContext.Consumer, null, function (_ref5) {
var simpleToken = _ref5.simpleToken;
return !simpleToken && React.createElement("div", {
onClick: buttonEvent(_this2.toggleAccount),
onKeyDown: buttonEvent(_this2.toggleAccount),
role: "button",
tabIndex: "0",
className: "jsx-".concat(MobileBookingHeaderStyle.__hash) + " " + ((activeTab === 'account' ? 'option active' : 'option') || "")
}, React.createElement(_AccountCircle.default, {
size: "medium",
customColor: "#45505d"
}));
}), !_UrlHelpers.isWebView && React.createElement(_CloseButton.default, {
isMobile: true
}));
});
}), activeTab === 'search' && React.createElement("div", {
className: "jsx-".concat(MobileBookingHeaderStyle.__hash) + " " + "openedContent"
}, React.createElement(_SearchBar.default, null)), React.createElement("div", {
className: "jsx-".concat(MobileBookingHeaderStyle.__hash) + " " + ((0, _classnames.default)('openedContent', {
hidden: activeTab !== 'summary'
}) || "")
}, React.createElement(MobileBookingSummary, null)), activeTab === 'account' && React.createElement("div", {
className: "jsx-".concat(MobileBookingHeaderStyle.__hash) + " " + "openedContent"
}, React.createElement(_MobileUserDetail.default, null)), React.createElement(_style.default, {
styleId: MobileBookingHeaderStyle.__hash,
css: MobileBookingHeaderStyle
}));
}
}]);
return MobileBookingHeader;
}(React.Component);
var _default = (0, _reactRouterDom.withRouter)(MobileBookingHeader);
exports.default = _default;
;