2016-05-28 05:05:27 +08:00
|
|
|
import React from 'react';
|
|
|
|
import {IdentityStore} from 'nylas-exports';
|
2017-03-07 03:45:55 +08:00
|
|
|
import {Webview} from 'nylas-component-kit';
|
2016-10-18 08:59:33 +08:00
|
|
|
import OnboardingActions from './onboarding-actions';
|
2016-05-28 05:05:27 +08:00
|
|
|
|
|
|
|
export default class AuthenticatePage extends React.Component {
|
|
|
|
static displayName = "AuthenticatePage";
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
accountInfo: React.PropTypes.object,
|
|
|
|
};
|
|
|
|
|
2017-03-07 03:45:55 +08:00
|
|
|
_src() {
|
2016-08-31 01:41:31 +08:00
|
|
|
const n1Version = NylasEnv.getVersion();
|
2017-03-07 03:45:55 +08:00
|
|
|
return `${IdentityStore.URLRoot}/onboarding?utm_medium=N1&utm_source=OnboardingPage&N1_version=${n1Version}&client_edition=basic`
|
2016-05-28 05:05:27 +08:00
|
|
|
}
|
|
|
|
|
2017-03-07 03:45:55 +08:00
|
|
|
_onDidFinishLoad = (webview) => {
|
2016-08-31 10:20:51 +08:00
|
|
|
const receiveUserInfo = `
|
2016-05-28 05:05:27 +08:00
|
|
|
var a = document.querySelector('#pro-account');
|
|
|
|
result = a ? a.innerText : null;
|
|
|
|
`;
|
2016-08-31 10:20:51 +08:00
|
|
|
webview.executeJavaScript(receiveUserInfo, false, (result) => {
|
2016-05-28 05:05:27 +08:00
|
|
|
this.setState({ready: true, webviewLoading: false});
|
|
|
|
if (result !== null) {
|
|
|
|
OnboardingActions.authenticationJSONReceived(JSON.parse(result));
|
|
|
|
}
|
|
|
|
});
|
2016-08-31 10:20:51 +08:00
|
|
|
|
|
|
|
const openExternalLink = `
|
|
|
|
var el = document.querySelector('.open-external');
|
|
|
|
if (el) {el.addEventListener('click', function(event) {console.log(this.href); event.preventDefault(); return false;})}
|
|
|
|
`;
|
|
|
|
webview.executeJavaScript(openExternalLink);
|
2016-05-28 05:05:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className="page authenticate">
|
2017-03-07 03:45:55 +08:00
|
|
|
<Webview src={this._src()} onDidFinishLoad={this._onDidFinishLoad} />
|
2016-05-28 05:05:27 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|