mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-04 07:10:06 +08:00
4a738602ab
commit50d0cfb87c
Author: Ben Gotow <bengotow@gmail.com> Date: Fri May 27 14:01:49 2016 -0700 IdentityStore conveniene methods for subscription state commit80c3c7b956
Author: Ben Gotow <bengotow@gmail.com> Date: Fri May 27 12:03:53 2016 -0700 Periodically refresh identity, show expired notice in top bar commit5dc39efe98
Merge:4c4f463
906ea74
Author: Juan Tejada <juans.tejada@gmail.com> Date: Thu May 26 15:17:46 2016 -0700 Merge branch 'bengotow/n1-pro' of github.com:nylas/N1 into bengotow/n1-pro commit4c4f463f4b
Author: Juan Tejada <juans.tejada@gmail.com> Date: Thu May 26 15:16:48 2016 -0700 Hijack links inside email that go to billing site and add SSO to them commit906ea74807
Author: Ben Gotow <bengotow@gmail.com> Date: Thu May 26 12:02:29 2016 -0700 Add custom welcome page for upgrading users commit2ba9aedfe9
Author: Juan Tejada <juans.tejada@gmail.com> Date: Wed May 25 17:27:12 2016 -0700 Add styling to Subscription tab in prefs commit384433a338
Author: Ben Gotow <bengotow@gmail.com> Date: Wed May 25 16:21:18 2016 -0700 Add better style reset, more IdentityStore changes commitc4f9dfb4e4
Author: Ben Gotow <bengotow@gmail.com> Date: Wed May 25 15:29:41 2016 -0700 Add subscription tab commitbd4c25405a
Author: Ben Gotow <bengotow@gmail.com> Date: Wed May 25 14:18:40 2016 -0700 Point to billing-staging for now commit578e808bfc
Author: Ben Gotow <bengotow@gmail.com> Date: Wed May 25 13:30:13 2016 -0700 Rename account helpers > onboarding helpers commitdfea0a9861
Author: Ben Gotow <bengotow@gmail.com> Date: Wed May 25 13:26:46 2016 -0700 A few minor fixes commit7110217fd4
Author: Ben Gotow <bengotow@gmail.com> Date: Wed May 25 12:58:21 2016 -0700 feat(onboarding): Nylas Pro onboarding overhaul Summary: Rip out all invite-related code Enable Templates and Translate by default Scrub packages page, unused code in onboarding pkg Remove resizing New onboarding screens IMAP provider list, validation Call success with response object as well Renaming and tweaks Test Plan: No tests yet Reviewers: evan, juan, jackie Differential Revision: https://phab.nylas.com/D2985 commitdc9ea45ca9
Author: Ben Gotow <bengotow@gmail.com> Date: Wed May 25 12:52:39 2016 -0700 Renaming and tweaks commit5ca4cd31ce
Author: Ben Gotow <bengotow@gmail.com> Date: Wed May 25 11:03:57 2016 -0700 Call success with response object as well commit45f14f9b00
Author: Ben Gotow <bengotow@gmail.com> Date: Tue May 24 18:26:38 2016 -0700 IMAP provider list, validation commitc6ca124e6e
Author: Ben Gotow <bengotow@gmail.com> Date: Sat May 21 11:14:44 2016 -0700 New onboarding screens commitdad918d926
Author: Ben Gotow <bengotow@gmail.com> Date: Thu May 19 16:37:31 2016 -0700 Remove resizing commitecb1a569e2
Author: Ben Gotow <bengotow@gmail.com> Date: Thu May 19 16:36:04 2016 -0700 Scrub packages page, unused code in onboarding pkg commit3e0a44156c
Author: Ben Gotow <bengotow@gmail.com> Date: Thu May 19 16:33:12 2016 -0700 Enable Templates and Translate by default commit0d218bc86f
Author: Ben Gotow <bengotow@gmail.com> Date: Thu May 19 16:30:47 2016 -0700 Rip out all invite-related code
156 lines
4.6 KiB
JavaScript
156 lines
4.6 KiB
JavaScript
import OnboardingActions from './onboarding-actions';
|
|
import {AccountStore, Actions, IdentityStore} from 'nylas-exports';
|
|
import {shell, ipcRenderer} from 'electron';
|
|
import NylasStore from 'nylas-store';
|
|
import {buildWelcomeURL} from './onboarding-helpers';
|
|
|
|
function accountTypeForProvider(provider) {
|
|
if (provider === 'eas') {
|
|
return 'exchange';
|
|
}
|
|
if (provider === 'custom') {
|
|
return 'imap';
|
|
}
|
|
return provider;
|
|
}
|
|
|
|
class OnboardingStore extends NylasStore {
|
|
constructor() {
|
|
super();
|
|
|
|
this.listenTo(OnboardingActions.moveToPreviousPage, this._onMoveToPreviousPage)
|
|
this.listenTo(OnboardingActions.moveToPage, this._onMoveToPage)
|
|
this.listenTo(OnboardingActions.accountJSONReceived, this._onAccountJSONReceived)
|
|
this.listenTo(OnboardingActions.authenticationJSONReceived, this._onAuthenticationJSONReceived)
|
|
this.listenTo(OnboardingActions.setAccountInfo, this._onSetAccountInfo);
|
|
this.listenTo(OnboardingActions.setAccountType, this._onSetAccountType);
|
|
|
|
const {existingAccount, addingAccount} = NylasEnv.getWindowProps();
|
|
|
|
const identity = IdentityStore.identity();
|
|
if (identity) {
|
|
this._accountInfo = {
|
|
name: `${identity.firstname || ""} ${identity.lastname || ""}`,
|
|
};
|
|
} else {
|
|
this._accountInfo = {};
|
|
}
|
|
|
|
if (existingAccount) {
|
|
const accountType = accountTypeForProvider(existingAccount.provider);
|
|
this._pageStack = ['account-choose']
|
|
this._accountInfo = {
|
|
name: existingAccount.name,
|
|
email: existingAccount.emailAddress,
|
|
};
|
|
this._onSetAccountType(accountType);
|
|
} else if (addingAccount) {
|
|
this._pageStack = ['account-choose'];
|
|
} else {
|
|
this._pageStack = ['welcome'];
|
|
}
|
|
}
|
|
|
|
_onOnboardingComplete = () => {
|
|
// When account JSON is received, we want to notify external services
|
|
// that it succeeded. Unfortunately in this case we're likely to
|
|
// close the window before those requests can be made. We add a short
|
|
// delay here to ensure that any pending requests have a chance to
|
|
// clear before the window closes.
|
|
setTimeout(() => {
|
|
ipcRenderer.send('account-setup-successful');
|
|
}, 100);
|
|
}
|
|
|
|
_onSetAccountType = (type) => {
|
|
let nextPage = "account-settings";
|
|
if (type === 'gmail') {
|
|
nextPage = "account-settings-gmail";
|
|
} else if (type === 'exchange') {
|
|
nextPage = "account-settings-exchange";
|
|
}
|
|
Actions.recordUserEvent('Auth Flow Started', {type});
|
|
this._onSetAccountInfo(Object.assign({}, this._accountInfo, {type}));
|
|
this._onMoveToPage(nextPage);
|
|
}
|
|
|
|
_onSetAccountInfo = (info) => {
|
|
this._accountInfo = info;
|
|
this.trigger();
|
|
}
|
|
|
|
_onMoveToPreviousPage = () => {
|
|
this._pageStack.pop();
|
|
this.trigger();
|
|
}
|
|
|
|
_onMoveToPage = (page) => {
|
|
this._pageStack.push(page)
|
|
this.trigger();
|
|
}
|
|
|
|
_onAuthenticationJSONReceived = (json) => {
|
|
const isFirstAccount = AccountStore.accounts().length === 0;
|
|
|
|
Actions.setNylasIdentity(json);
|
|
|
|
setTimeout(() => {
|
|
if (isFirstAccount) {
|
|
this._onSetAccountInfo(Object.assign({}, this._accountInfo, {
|
|
name: `${json.firstname || ""} ${json.lastname || ""}`,
|
|
email: json.email,
|
|
}));
|
|
OnboardingActions.moveToPage('account-choose');
|
|
} else {
|
|
this._onOnboardingComplete();
|
|
}
|
|
}, 1000);
|
|
}
|
|
|
|
_onAccountJSONReceived = (json) => {
|
|
try {
|
|
const isFirstAccount = AccountStore.accounts().length === 0;
|
|
|
|
AccountStore.addAccountFromJSON(json);
|
|
this._accountFromAuth = AccountStore.accountForEmail(json.email_address);
|
|
|
|
Actions.recordUserEvent('Auth Successful', {
|
|
provider: this._accountFromAuth.provider,
|
|
});
|
|
ipcRenderer.send('new-account-added');
|
|
NylasEnv.displayWindow();
|
|
|
|
if (isFirstAccount) {
|
|
this._onMoveToPage('initial-preferences');
|
|
Actions.recordUserEvent('First Account Linked');
|
|
|
|
// open the external welcome page
|
|
const url = buildWelcomeURL(this._accountFromAuth);
|
|
shell.openExternal(url, {activate: false});
|
|
} else {
|
|
this._onOnboardingComplete();
|
|
}
|
|
} catch (e) {
|
|
NylasEnv.reportError(e);
|
|
NylasEnv.showErrorDialog("Unable to Connect Account", "Sorry, something went wrong on the Nylas server. Please try again. If you're still having issues, contact us at support@nylas.com.");
|
|
}
|
|
}
|
|
|
|
page() {
|
|
return this._pageStack[this._pageStack.length - 1];
|
|
}
|
|
|
|
pageDepth() {
|
|
return this._pageStack.length;
|
|
}
|
|
|
|
accountInfo() {
|
|
return this._accountInfo;
|
|
}
|
|
|
|
accountFromAuth() {
|
|
return this._accountFromAuth;
|
|
}
|
|
}
|
|
|
|
export default new OnboardingStore();
|