2016-05-07 07:06:16 +08:00
|
|
|
/* eslint global-require: 0 */
|
2016-03-09 08:06:04 +08:00
|
|
|
import {AccountStore, Account, Actions, React} from 'nylas-exports'
|
|
|
|
import {RetinaImg} from 'nylas-component-kit'
|
|
|
|
|
|
|
|
export default class AccountErrorHeader extends React.Component {
|
|
|
|
static displayName = 'AccountErrorHeader';
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = this.getStateFromStores();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2016-05-14 05:16:54 +08:00
|
|
|
this.mounted = true;
|
2016-03-09 08:06:04 +08:00
|
|
|
this.unsubscribe = AccountStore.listen(() => this._onAccountsChanged());
|
|
|
|
}
|
|
|
|
|
2016-05-14 05:16:54 +08:00
|
|
|
componentWillUnmount() {
|
|
|
|
this.mounted = false;
|
|
|
|
if (this.unsubscribe) {
|
|
|
|
this.unsubscribe();
|
|
|
|
this.unsubscribe = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-09 08:06:04 +08:00
|
|
|
getStateFromStores() {
|
|
|
|
return {accounts: AccountStore.accounts()}
|
|
|
|
}
|
|
|
|
|
|
|
|
_onAccountsChanged() {
|
|
|
|
this.setState(this.getStateFromStores())
|
|
|
|
}
|
|
|
|
|
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() {
|
|
|
|
const {shell} = require("electron");
|
|
|
|
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();
|
|
|
|
|
|
|
|
AccountStore.refreshHealthOfAccounts(errorAccounts.map(a => a.id)).finally(() => {
|
|
|
|
if (!this.mounted) { return; }
|
|
|
|
this.setState({refreshing: false});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-09 08:06:04 +08:00
|
|
|
renderErrorHeader(message, buttonName, actionCallback) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-03-19 01:41:08 +08:00
|
|
|
const errorAccounts = this.state.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:
|
|
|
|
return this.renderErrorHeader(
|
|
|
|
`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:
|
|
|
|
return this.renderErrorHeader(
|
|
|
|
`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:
|
|
|
|
return this.renderErrorHeader(
|
|
|
|
`Nylas encountered an error while syncing mail for ${account.emailAddress} - we're
|
|
|
|
looking into it. Contact Nylas support for details.`,
|
|
|
|
"Contact support",
|
|
|
|
() => this._contactSupport());
|
2016-03-09 08:06:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (errorAccounts.length > 1) {
|
|
|
|
return this.renderErrorHeader("Several of your accounts are having issues. " +
|
|
|
|
"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
|
|
|
}
|
|
|
|
}
|