2016-05-07 07:06:16 +08:00
|
|
|
/* eslint global-require: 0 */
|
2016-05-28 05:05:27 +08:00
|
|
|
import {AccountStore, Account, Actions, React, IdentityStore} from 'nylas-exports'
|
2016-03-09 08:06:04 +08:00
|
|
|
import {RetinaImg} from 'nylas-component-kit'
|
2016-05-28 05:05:27 +08:00
|
|
|
import {shell} from 'electron';
|
2016-03-09 08:06:04 +08:00
|
|
|
|
|
|
|
export default class AccountErrorHeader extends React.Component {
|
|
|
|
static displayName = 'AccountErrorHeader';
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = this.getStateFromStores();
|
2016-06-08 03:53:05 +08:00
|
|
|
this.upgradeLabel = ""
|
2016-03-09 08:06:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2016-05-14 05:16:54 +08:00
|
|
|
this.mounted = true;
|
2016-05-28 05:05:27 +08:00
|
|
|
this.unsubscribers = [
|
|
|
|
AccountStore.listen(() => this.setState(this.getStateFromStores())),
|
|
|
|
IdentityStore.listen(() => this.setState(this.getStateFromStores())),
|
|
|
|
];
|
2016-03-09 08:06:04 +08:00
|
|
|
}
|
|
|
|
|
2016-05-14 05:16:54 +08:00
|
|
|
componentWillUnmount() {
|
|
|
|
this.mounted = false;
|
2016-05-28 05:05:27 +08:00
|
|
|
for (const unsub of this.unsubscribers) {
|
|
|
|
unsub();
|
2016-05-14 05:16:54 +08:00
|
|
|
}
|
2016-05-28 05:05:27 +08:00
|
|
|
this.unsubscribers = null;
|
2016-05-14 05:16:54 +08:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:06:04 +08:00
|
|
|
getStateFromStores() {
|
2016-05-28 05:05:27 +08:00
|
|
|
return {
|
|
|
|
accounts: AccountStore.accounts(),
|
|
|
|
subscriptionState: IdentityStore.subscriptionState(),
|
2016-06-11 05:29:21 +08:00
|
|
|
daysUntilSubscriptionRequired: IdentityStore.daysUntilSubscriptionRequired(),
|
2016-05-28 05:05:27 +08:00
|
|
|
}
|
2016-03-09 08:06:04 +08:00
|
|
|
}
|
|
|
|
|
2016-05-14 05:16:54 +08:00
|
|
|
_reconnect(existingAccount) {
|
2016-03-09 08:06:04 +08:00
|
|
|
const ipc = require('electron').ipcRenderer;
|
2016-05-14 05:16:54 +08:00
|
|
|
ipc.send('command', 'application:add-account', {existingAccount});
|
2016-03-09 08:06:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_openPreferences() {
|
|
|
|
Actions.switchPreferencesTab('Accounts');
|
|
|
|
Actions.openPreferences()
|
|
|
|
}
|
|
|
|
|
|
|
|
_contactSupport() {
|
|
|
|
shell.openExternal("https://support.nylas.com/hc/en-us/requests/new");
|
|
|
|
}
|
|
|
|
|
2016-05-14 05:16:54 +08:00
|
|
|
_onCheckAgain = (event) => {
|
|
|
|
const errorAccounts = this.state.accounts.filter(a => a.hasSyncStateError());
|
|
|
|
this.setState({refreshing: true});
|
|
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
2016-06-11 05:29:21 +08:00
|
|
|
IdentityStore.refreshStatus().finally(() => {
|
|
|
|
AccountStore.refreshHealthOfAccounts(errorAccounts.map(a => a.id)).finally(() => {
|
|
|
|
if (!this.mounted) { return; }
|
|
|
|
this.setState({refreshing: false});
|
|
|
|
});
|
2016-05-14 05:16:54 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-05-28 05:05:27 +08:00
|
|
|
_onUpgrade = () => {
|
|
|
|
this.setState({buildingUpgradeURL: true});
|
2016-06-08 03:53:05 +08:00
|
|
|
const isSubscription = this.state.subscriptionState === IdentityStore.State.Lapsed
|
|
|
|
const utm = {
|
|
|
|
source: "UpgradeBanner",
|
|
|
|
campaign: isSubscription ? "SubscriptionExpired" : "TrialExpired",
|
|
|
|
}
|
|
|
|
IdentityStore.fetchSingleSignOnURL('/payment', utm).then((url) => {
|
2016-05-28 05:05:27 +08:00
|
|
|
this.setState({buildingUpgradeURL: false});
|
|
|
|
shell.openExternal(url);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_renderErrorHeader(message, buttonName, actionCallback) {
|
2016-03-09 08:06:04 +08:00
|
|
|
return (
|
2016-04-05 08:11:09 +08:00
|
|
|
<div className="account-error-header notifications-sticky">
|
2016-05-07 07:06:16 +08:00
|
|
|
<div
|
|
|
|
className={"notifications-sticky-item notification-error has-default-action"}
|
|
|
|
onClick={actionCallback}
|
|
|
|
>
|
|
|
|
<RetinaImg
|
|
|
|
className="icon"
|
|
|
|
name="icon-alert-onred.png"
|
|
|
|
mode={RetinaImg.Mode.ContentPreserve}
|
|
|
|
/>
|
2016-04-05 08:11:09 +08:00
|
|
|
<div className="message">
|
|
|
|
{message}
|
|
|
|
</div>
|
2016-05-14 05:16:54 +08:00
|
|
|
<a className="action refresh" onClick={this._onCheckAgain}>
|
|
|
|
{this.state.refreshing ? "Checking..." : "Check Again"}
|
|
|
|
</a>
|
2016-03-09 08:06:04 +08:00
|
|
|
<a className="action default" onClick={actionCallback}>
|
|
|
|
{buttonName}
|
|
|
|
</a>
|
|
|
|
</div>
|
2016-05-14 05:16:54 +08:00
|
|
|
</div>
|
|
|
|
)
|
2016-03-09 08:06:04 +08:00
|
|
|
}
|
|
|
|
|
2016-05-28 05:05:27 +08:00
|
|
|
_renderUpgradeHeader() {
|
|
|
|
return (
|
|
|
|
<div className="account-error-header notifications-sticky">
|
|
|
|
<div
|
|
|
|
className={"notifications-sticky-item notification-upgrade has-default-action"}
|
|
|
|
onClick={this._onUpgrade}
|
|
|
|
>
|
|
|
|
<RetinaImg
|
|
|
|
className="icon"
|
|
|
|
name="ic-upgrade.png"
|
|
|
|
mode={RetinaImg.Mode.ContentIsMask}
|
|
|
|
/>
|
|
|
|
<div className="message">
|
|
|
|
{
|
|
|
|
(this.state.subscriptionState === IdentityStore.State.Lapsed) ? (
|
2016-07-27 06:46:29 +08:00
|
|
|
"Your subscription has expired, and we've paused your mailboxes. Renew your subscription to continue using N1!"
|
2016-05-28 05:05:27 +08:00
|
|
|
) : (
|
2016-07-27 06:46:29 +08:00
|
|
|
"Your 30-day trial has expired, and we've paused your mailboxes. Subscribe to continue using N1!"
|
2016-05-28 05:05:27 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
<a className="action refresh" onClick={this._onCheckAgain}>
|
|
|
|
{this.state.refreshing ? "Checking..." : "Check Again"}
|
|
|
|
</a>
|
|
|
|
<a className="action default" onClick={this._onUpgrade}>
|
|
|
|
{this.state.buildingUpgradeURL ? "Please wait..." : "Upgrade to Nylas Pro..."}
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-03-09 08:06:04 +08:00
|
|
|
render() {
|
2016-06-11 05:29:21 +08:00
|
|
|
const {accounts, subscriptionState, daysUntilSubscriptionRequired} = this.state;
|
|
|
|
|
|
|
|
const subscriptionInvalid = (subscriptionState !== IdentityStore.State.Valid);
|
|
|
|
const subscriptionRequired = (daysUntilSubscriptionRequired !== null) && (daysUntilSubscriptionRequired <= 1);
|
2016-05-28 05:05:27 +08:00
|
|
|
|
2016-06-11 05:29:21 +08:00
|
|
|
if (subscriptionInvalid && subscriptionRequired) {
|
|
|
|
return this._renderUpgradeHeader();
|
2016-05-28 05:05:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const errorAccounts = accounts.filter(a => a.hasSyncStateError());
|
2016-03-09 08:06:04 +08:00
|
|
|
if (errorAccounts.length === 1) {
|
|
|
|
const account = errorAccounts[0];
|
|
|
|
|
|
|
|
switch (account.syncState) {
|
2016-05-07 07:06:16 +08:00
|
|
|
case Account.SYNC_STATE_AUTH_FAILED:
|
2016-05-28 05:05:27 +08:00
|
|
|
return this._renderErrorHeader(
|
2016-05-07 07:06:16 +08:00
|
|
|
`Nylas N1 can no longer authenticate with ${account.emailAddress}. Click here to reconnect.`,
|
|
|
|
"Reconnect",
|
|
|
|
() => this._reconnect(account));
|
2016-03-09 08:06:04 +08:00
|
|
|
|
2016-05-07 07:06:16 +08:00
|
|
|
case Account.SYNC_STATE_STOPPED:
|
2016-05-28 05:05:27 +08:00
|
|
|
return this._renderErrorHeader(
|
2016-05-07 07:06:16 +08:00
|
|
|
`The cloud sync for ${account.emailAddress} has been disabled. You will
|
|
|
|
not be able to send or receive mail. Please contact Nylas support.`,
|
|
|
|
"Contact support",
|
|
|
|
() => this._contactSupport());
|
2016-03-09 08:06:04 +08:00
|
|
|
|
2016-05-07 07:06:16 +08:00
|
|
|
default:
|
2016-05-28 05:05:27 +08:00
|
|
|
return this._renderErrorHeader(
|
2016-07-27 06:46:29 +08:00
|
|
|
`Nylas encountered an error while syncing mail for ${account.emailAddress}—we're
|
2016-05-07 07:06:16 +08:00
|
|
|
looking into it. Contact Nylas support for details.`,
|
|
|
|
"Contact support",
|
|
|
|
() => this._contactSupport());
|
2016-03-09 08:06:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (errorAccounts.length > 1) {
|
2016-05-28 05:05:27 +08:00
|
|
|
return this._renderErrorHeader("Several of your accounts are having issues. " +
|
2016-03-09 08:06:04 +08:00
|
|
|
"You will not be able to send or receive mail. Click here to manage your accounts.",
|
|
|
|
"Open preferences",
|
2016-05-07 07:06:16 +08:00
|
|
|
() => this._openPreferences());
|
2016-03-09 08:06:04 +08:00
|
|
|
}
|
2016-05-14 05:16:54 +08:00
|
|
|
return <span />;
|
2016-03-09 08:06:04 +08:00
|
|
|
}
|
|
|
|
}
|