@lonelyplanet/dotcom-core
Version:
This package is meant to house some of our more common UI and shared libs across dotcom applications.
108 lines (87 loc) • 2.64 kB
JavaScript
;
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 fetch = require("isomorphic-fetch");
var radium_1 = require("radium");
var React = require("react");
var helpers_1 = require("../../helpers/");
var authModal_1 = require("../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 = helpers_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;