UNPKG

@lonelyplanet/dotcom-core

Version:

This package is meant to house some of our more common UI and shared libs across dotcom applications.

72 lines (71 loc) 2.82 kB
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 __()); }; })(); import * as fetch from "isomorphic-fetch"; import { StyleRoot } from "radium"; import * as React from "react"; import { authSetupWithDefaults } from "../../helpers/"; import AuthModal from "../authModal"; var Component = React.Component; var GlobalLogin = /** @class */ (function (_super) { __extends(GlobalLogin, _super); function GlobalLogin(props) { var _this = _super.call(this, props) || this; _this.state = { authActions: {}, isOpen: false, }; _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 = 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(StyleRoot, null, this.state.isOpen && React.createElement(AuthModal, { isOpen: this.state.isOpen, closeModal: this.close, authActions: this.state.authActions, isMobile: false }))); }; return GlobalLogin; }(React.Component)); export default GlobalLogin;