UNPKG

@lonelyplanet/dotcom-core

Version:

74 lines (73 loc) 2.88 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var React = require("react"); var radium_1 = require("radium"); var authModal_1 = require("../authModal"); var fetch = require("isomorphic-fetch"); var _1 = require("../../helpers/"); var Component = React.Component; var GlobalLogin = (function (_super) { __extends(GlobalLogin, _super); function GlobalLogin(props) { var _this = _super.call(this) || this; _this.state = { isOpen: false, authActions: {}, }; _this.close = _this.close.bind(_this); return _this; } GlobalLogin.prototype.componentDidMount = function () { var _this = this; window.addEventListener("hashchange", function () { _this.setState({ isOpen: _this.isOpen(), }); }, false); var authLinks = _1.authSetupWithDefaults(window.lp.auth); this.setState({ authActions: { facebook: function () { window.location.href = authLinks.facebookLink; }, twitter: function () { window.location.href = authLinks.twitterLink; }, google: function () { window.location.href = authLinks.googleLink; }, passwordless: function (email) { var magicLink = authLinks.passwordlessLink(email); fetch(magicLink, { method: "post", credentials: "include", }); }, password: authLinks.passwordLink, }, isOpen: this.isOpen(), }); }; GlobalLogin.prototype.isOpen = function () { return typeof window !== "undefined" && window.location.hash.indexOf("login") === 1; }; GlobalLogin.prototype.close = function () { window.location.hash = ""; }; GlobalLogin.prototype.render = function () { return (React.createElement(radium_1.StyleRoot, null, this.state.isOpen && React.createElement(authModal_1.default, { isOpen: this.state.isOpen, closeModal: this.close, authActions: this.state.authActions, isMobile: false }))); }; return GlobalLogin; }(React.Component)); exports.default = GlobalLogin;