2016-10-04 23:02:11 +08:00
|
|
|
import {shell, ipcRenderer} from 'electron';
|
2016-12-21 20:22:53 +08:00
|
|
|
import {React, Account, AccountStore, Actions} from 'nylas-exports';
|
2016-10-07 01:53:22 +08:00
|
|
|
import {Notification} from 'nylas-component-kit';
|
2016-10-04 23:02:11 +08:00
|
|
|
|
|
|
|
export default class AccountErrorNotification extends React.Component {
|
|
|
|
static displayName = 'AccountErrorNotification';
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = this.getStateFromStores();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.unlisten = AccountStore.listen(() => this.setState(this.getStateFromStores()));
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.unlisten();
|
|
|
|
}
|
|
|
|
|
|
|
|
getStateFromStores() {
|
|
|
|
return {
|
|
|
|
accounts: AccountStore.accounts(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_onContactSupport = () => {
|
|
|
|
shell.openExternal("https://support.nylas.com/hc/en-us/requests/new");
|
|
|
|
}
|
|
|
|
|
|
|
|
_onReconnect = (existingAccount) => {
|
|
|
|
ipcRenderer.send('command', 'application:add-account', {existingAccount});
|
|
|
|
}
|
|
|
|
|
|
|
|
_onOpenAccountPreferences = () => {
|
|
|
|
Actions.switchPreferencesTab('Accounts');
|
|
|
|
Actions.openPreferences()
|
|
|
|
}
|
|
|
|
|
2016-12-21 20:22:53 +08:00
|
|
|
_onCheckAgain(account) {
|
|
|
|
if (account) {
|
|
|
|
Actions.wakeLocalSyncWorkerForAccount(account.id)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const erroredAccounts = this.state.accounts.filter(a => a.hasSyncStateError());
|
|
|
|
erroredAccounts.forEach(acc => Actions.wakeLocalSyncWorkerForAccount(acc.id))
|
2016-10-04 23:02:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const erroredAccounts = this.state.accounts.filter(a => a.hasSyncStateError());
|
|
|
|
let title;
|
|
|
|
let subtitle;
|
|
|
|
let subtitleAction;
|
|
|
|
let actions;
|
|
|
|
if (erroredAccounts.length === 0) {
|
|
|
|
return <span />
|
|
|
|
} else if (erroredAccounts.length > 1) {
|
|
|
|
title = "Several of your accounts are having issues";
|
|
|
|
actions = [{
|
|
|
|
label: "Check Again",
|
2016-12-21 20:22:53 +08:00
|
|
|
fn: () => this._onCheckAgain(),
|
2016-10-04 23:02:11 +08:00
|
|
|
}, {
|
|
|
|
label: "Manage",
|
|
|
|
fn: this._onOpenAccountPreferences,
|
|
|
|
}];
|
|
|
|
} else {
|
|
|
|
const erroredAccount = erroredAccounts[0];
|
|
|
|
switch (erroredAccount.syncState) {
|
2016-12-21 20:22:53 +08:00
|
|
|
case Account.SYNC_STATE_N1_CLOUD_AUTH_FAILED:
|
2017-01-12 09:41:07 +08:00
|
|
|
title = `Cannot authenticate Nylas Mail Cloud Services with ${erroredAccount.emailAddress}`;
|
2016-12-02 01:04:37 +08:00
|
|
|
actions = [{
|
|
|
|
label: "Check Again",
|
2016-12-21 20:22:53 +08:00
|
|
|
fn: () => this._onCheckAgain(erroredAccount),
|
2016-12-02 01:04:37 +08:00
|
|
|
}, {
|
|
|
|
label: 'Reconnect',
|
|
|
|
fn: () => this._onReconnect(erroredAccount),
|
|
|
|
}];
|
|
|
|
break;
|
2016-10-04 23:02:11 +08:00
|
|
|
case Account.SYNC_STATE_AUTH_FAILED:
|
|
|
|
title = `Cannot authenticate with ${erroredAccount.emailAddress}`;
|
|
|
|
actions = [{
|
|
|
|
label: "Check Again",
|
2016-12-21 20:22:53 +08:00
|
|
|
fn: () => this._onCheckAgain(erroredAccount),
|
2016-10-04 23:02:11 +08:00
|
|
|
}, {
|
|
|
|
label: 'Reconnect',
|
|
|
|
fn: () => this._onReconnect(erroredAccount),
|
|
|
|
}];
|
|
|
|
break;
|
|
|
|
default:
|
2016-12-21 20:22:53 +08:00
|
|
|
title = `Encountered an error while syncing ${erroredAccount.emailAddress}`;
|
2016-10-04 23:02:11 +08:00
|
|
|
subtitle = "Contact support";
|
|
|
|
subtitleAction = this._onContactSupport;
|
|
|
|
actions = [{
|
|
|
|
label: "Check Again",
|
2016-12-21 20:22:53 +08:00
|
|
|
fn: () => this._onCheckAgain(erroredAccount),
|
2016-10-04 23:02:11 +08:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Notification
|
|
|
|
priority="3"
|
|
|
|
isError
|
|
|
|
title={title}
|
|
|
|
subtitle={subtitle}
|
|
|
|
subtitleAction={subtitleAction}
|
|
|
|
actions={actions}
|
|
|
|
icon="volstead-error.png"
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|