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();
|
2017-01-20 02:52:52 +08:00
|
|
|
this._checkingTimeout = null
|
|
|
|
this.state = {
|
|
|
|
checking: false,
|
|
|
|
debugKeyPressed: false,
|
|
|
|
accounts: AccountStore.accounts(),
|
|
|
|
}
|
2016-10-04 23:02:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2017-01-20 02:52:52 +08:00
|
|
|
this.unlisten = AccountStore.listen(() => this.setState({
|
|
|
|
accounts: AccountStore.accounts(),
|
|
|
|
}));
|
2016-10-04 23:02:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.unlisten();
|
|
|
|
}
|
|
|
|
|
2017-01-20 02:52:52 +08:00
|
|
|
_onContactSupport = (erroredAccount) => {
|
2017-08-17 04:20:54 +08:00
|
|
|
let url = 'https://support.getmerani.com/hc/en-us/requests/new'
|
2017-01-20 02:52:52 +08:00
|
|
|
if (erroredAccount) {
|
|
|
|
url += `?email=${encodeURIComponent(erroredAccount.emailAddress)}`
|
|
|
|
const {syncError} = erroredAccount
|
|
|
|
if (syncError != null) {
|
|
|
|
url += `&subject=${encodeURIComponent('Sync Error')}`
|
|
|
|
const description = encodeURIComponent(
|
|
|
|
`Sync Error:\n\`\`\`\n${JSON.stringify(syncError, null, 2)}\n\`\`\``
|
|
|
|
)
|
|
|
|
url += `&description=${description}`
|
|
|
|
}
|
2016-10-04 23:02:11 +08:00
|
|
|
}
|
2017-01-20 02:52:52 +08:00
|
|
|
shell.openExternal(url);
|
2016-10-04 23:02:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_onReconnect = (existingAccount) => {
|
2017-02-23 05:49:17 +08:00
|
|
|
ipcRenderer.send('command', 'application:add-account', {existingAccount, source: 'Reconnect from error notification'});
|
2016-10-04 23:02:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_onOpenAccountPreferences = () => {
|
|
|
|
Actions.switchPreferencesTab('Accounts');
|
|
|
|
Actions.openPreferences()
|
|
|
|
}
|
|
|
|
|
2017-08-31 08:21:39 +08:00
|
|
|
_onCheckAgain(accounts) {
|
|
|
|
clearTimeout(this._checkingTimeout);
|
|
|
|
this.setState({checking: true});
|
2017-01-20 02:52:52 +08:00
|
|
|
this._checkingTimeout = setTimeout(() => this.setState({checking: false}), 10000)
|
|
|
|
|
2017-08-31 08:21:39 +08:00
|
|
|
accounts.forEach((acct) =>
|
|
|
|
NylasEnv.mailsyncBridge.forceRelaunchClient(acct)
|
|
|
|
);
|
2016-10-04 23:02:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-08-31 08:21:39 +08:00
|
|
|
const erroredAccounts = this.state.accounts.filter(a => a.hasSyncStateError());
|
2017-01-20 02:52:52 +08:00
|
|
|
const checkAgainLabel = this.state.checking ? 'Checking...' : 'Check Again'
|
2016-10-04 23:02:11 +08:00
|
|
|
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 = [{
|
2017-01-20 02:52:52 +08:00
|
|
|
label: checkAgainLabel,
|
2017-08-31 08:21:39 +08:00
|
|
|
fn: () => this._onCheckAgain(AccountStore.accounts().filter(a => a.hasSyncStateError())),
|
2016-10-04 23:02:11 +08:00
|
|
|
}, {
|
|
|
|
label: "Manage",
|
|
|
|
fn: this._onOpenAccountPreferences,
|
|
|
|
}];
|
|
|
|
} else {
|
|
|
|
const erroredAccount = erroredAccounts[0];
|
2017-08-31 08:21:39 +08:00
|
|
|
switch (erroredAccount.syncState) {
|
|
|
|
case Account.SYNC_STATE_AUTH_FAILED:
|
|
|
|
title = `Cannot authenticate with ${erroredAccount.emailAddress}`;
|
|
|
|
actions = [{
|
|
|
|
label: checkAgainLabel,
|
|
|
|
fn: () => this._onCheckAgain([erroredAccount]),
|
|
|
|
}, {
|
|
|
|
label: 'Reconnect',
|
|
|
|
fn: () => this._onReconnect(erroredAccount),
|
|
|
|
}];
|
|
|
|
break;
|
|
|
|
default: {
|
|
|
|
title = `Encountered an error while syncing ${erroredAccount.emailAddress}`;
|
|
|
|
actions = [{
|
|
|
|
label: this.state.checking ? 'Retrying...' : 'Try Again',
|
|
|
|
fn: () => this._onCheckAgain([erroredAccount]),
|
|
|
|
}];
|
2017-01-20 02:52:52 +08:00
|
|
|
}
|
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"
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|