UNPKG

@mmob/react-mmob-marketplace

Version:
52 lines (51 loc) 2.53 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import React, { useEffect, useRef } from "react"; var IFRAME_NAME = "mmob_marketplace_target_iframe"; var MMOBMarketplaceForm = function (_a) { var customerInfo = _a.customerInfo, marketplaceUrl = _a.marketplaceUrl, cpId = _a.cpId, cpDeploymentId = _a.cpDeploymentId, page = _a.page, locale = _a.locale; var url = marketplaceUrl + "/boot"; var iframeEl = useRef(null); useEffect(function () { var _a; (_a = iframeEl.current) === null || _a === void 0 ? void 0 : _a.submit(); }, [iframeEl.current]); return (React.createElement("form", { method: "POST", action: url, style: { position: "absolute", top: "-10px", left: "-10px" }, target: IFRAME_NAME, ref: iframeEl }, Object.keys(customerInfo).map(function (key) { var value = customerInfo[key]; if (value !== null && value !== undefined) { return React.createElement("input", { type: "hidden", name: key, value: value, key: key }); } else { return ""; } }), React.createElement("input", { type: "hidden", name: "cp_id", value: cpId }), React.createElement("input", { type: "hidden", name: "cp_deployment_id", value: cpDeploymentId }), React.createElement("input", { type: "hidden", name: "page", value: page }), locale ? React.createElement("input", { type: "hidden", name: "locale", value: locale }) : "")); }; var MMOBMarketplace = function (props) { useEffect(function () { console.log("Build boot", props); }, []); var marketplaceUrl = props.marketplaceUrl || "https://marketplace.staging.mmob.com"; var allow = "geolocation 'self' " + marketplaceUrl + "clipboard-read; clipboard-write 'self' " + marketplaceUrl + "; fullscreen"; return (React.createElement(React.Fragment, null, React.createElement(MMOBMarketplaceForm, __assign({}, props, { marketplaceUrl: marketplaceUrl })), React.createElement("iframe", { name: IFRAME_NAME, style: { width: "100%", height: "100%", border: 0 }, allow: allow }))); }; export default MMOBMarketplace;