UNPKG

@mopinion/survey

Version:

Collect customer feedback with the Mopinion survey library

124 lines (123 loc) 8.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = CustomPage; var _preact = require("preact"); var _hooks = require("preact/hooks"); var _elements = require("../../elements"); var _utils = require("../../../utils"); var _ConfigStore = require("../stores/ConfigStore"); var _FormStore = require("../stores/FormStore"); var _BlockStore = require("../stores/BlockStore"); var _SvgIcon = _interopRequireDefault(require("./SvgIcon")); var _excluded = ["isFirstPage", "isLastPage"]; function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; } var customPageBlockMap = { text: _elements.PlainText, icon: _SvgIcon["default"], link: _elements.Link, img: 'img' }; function CustomPage(_ref) { var _config$properties, _config$properties2, _customPageElements$f, _customPageElements$f2; var isFirstPage = _ref.isFirstPage, isLastPage = _ref.isLastPage, props = _objectWithoutProperties(_ref, _excluded); var blockState = (0, _BlockStore.useBlockStore)(); var config = (0, _ConfigStore.useConfigStore)(); var _useFormProps = (0, _ConfigStore.useFormProps)(), webView = _useFormProps.webView; var _useFormStore = (0, _FormStore.useFormStore)(), actions = _useFormStore.actions; var customPageElements = (isFirstPage ? (_config$properties = config.properties) === null || _config$properties === void 0 || (_config$properties = _config$properties.introPage) === null || _config$properties === void 0 ? void 0 : _config$properties.elements : (_config$properties2 = config.properties) === null || _config$properties2 === void 0 || (_config$properties2 = _config$properties2.thanksPage) === null || _config$properties2 === void 0 ? void 0 : _config$properties2.elements) || {}; var elementKeysArr = customPageElements && _typeof(customPageElements) === 'object' ? Object.keys(customPageElements) : []; var panelLength = elementKeysArr.filter(function (key) { var _customPageElements$k; return (_customPageElements$k = customPageElements[key]) === null || _customPageElements$k === void 0 ? void 0 : _customPageElements$k.show_as_panels; }).length; var findTextBlocksKey = Object.keys(customPageElements).length ? Object.keys(customPageElements).filter(function (el) { return customPageElements[el].type === 'text'; })[0] : null; var firstTextBlockId = (_customPageElements$f = (_customPageElements$f2 = customPageElements[findTextBlocksKey]) === null || _customPageElements$f2 === void 0 ? void 0 : _customPageElements$f2.genID) !== null && _customPageElements$f !== void 0 ? _customPageElements$f : null; (0, _hooks.useEffect)(function () { if (firstTextBlockId) { var _customPageElements$f3, _customPageElements$f4; actions.updateScreenReaderHelper((_customPageElements$f3 = (_customPageElements$f4 = customPageElements[findTextBlocksKey]) === null || _customPageElements$f4 === void 0 ? void 0 : _customPageElements$f4.value) !== null && _customPageElements$f3 !== void 0 ? _customPageElements$f3 : 'Thank you for your feedback'); } }, []); return (0, _preact.h)("div", { className: isFirstPage ? 'front-page' : 'last-page', id: isFirstPage ? 'frontPage' : 'lastPage', "data-testid": isFirstPage ? 'front-page' : 'last-page' }, elementKeysArr.length > 0 && elementKeysArr.map(function (elementKey) { var _el$alt, _el$alt2, _el$width, _blockState$el$genID, _el$genID; var el = customPageElements[elementKey]; var BlockComponent = customPageBlockMap[el.type]; if (!BlockComponent) { return null; } var BlockProps = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, el.type === 'text' && { text: el.value }), el.type === 'icon' && { icon: el.icon, alt: el === null || el === void 0 ? void 0 : el.alt }), el.type === 'img' && { src: (0, _utils.getImageUri)(el.url), title: (_el$alt = el === null || el === void 0 ? void 0 : el.alt) !== null && _el$alt !== void 0 ? _el$alt : '', alt: (_el$alt2 = el === null || el === void 0 ? void 0 : el.alt) !== null && _el$alt2 !== void 0 ? _el$alt2 : '', style: { height: el.layout === 'static' ? el.height : 'auto', width: (_el$width = el.width) !== null && _el$width !== void 0 ? _el$width : '100%' } }), el.type === 'link' && { block: { id: el.genID, properties: { linktype: el.use_as !== 'link' ? 'function' : 'link', linktype_function: el.use_as, plaintext: el.value || el.description, description: el.value || el.description, hyperlinktext: el.hyperlinktext, show_as_buttons: el.show_as_buttons, show_as_panels: el.show_as_panels, close_on_linkclick: el.close_on_linkclick !== 'undefined' ? el.close_on_linkclick : false, icon: el.icon, iconAlignment: el.icon_align, hyperlinkhref: el.hyperlinkhref } } }); var panelType = el.show_as_panels ? 'panel-wrap' : el.show_as_buttons ? 'btn-wrap' : ''; var imgType = el.type === 'img' ? "img-".concat(el.layout ? el.layout : 'responsive') : ''; var displayAs = el.show_as_panels ? 'inline-block' : 'block'; var divStyle = { textAlign: el.align, display: isFirstPage ? displayAs : (_blockState$el$genID = blockState[el.genID]) !== null && _blockState$el$genID !== void 0 && _blockState$el$genID.isVisible ? displayAs : 'none', width: !el.show_as_panels ? 'auto' : panelLength === 1 ? '100%' : panelLength % 2 === 0 ? '50%' : '33%' }; return (0, _preact.h)("div", { className: "custom-section custompage-".concat(el.type, " ").concat(panelType, " ").concat(imgType), id: "".concat(isFirstPage ? 'intro-page' : 'thanks-page', "_").concat((_el$genID = el.genID) !== null && _el$genID !== void 0 ? _el$genID : elementKey), style: divStyle }, (0, _preact.h)(BlockComponent, BlockProps)); }), webView && elementKeysArr.length === 0 && isLastPage && (0, _preact.h)(_preact.Fragment, null, (0, _preact.h)("div", { "class": "completed-anim do-anim" }, (0, _preact.h)(_SvgIcon["default"], { icon: "check", alt: "check icon" })), (0, _preact.h)("span", { dangerouslySetInnerHTML: { __html: config.properties.exit_content } }))); } //# sourceMappingURL=CustomPage.js.map