mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-10 10:11:25 +08:00
327eb43932
Summary: Changes the delta code to handle new deltas on the Account object, which are triggered by changes in sync state indicating various backend issues. Saves the sync state in a new field on the Account object, which is persisited in `config.cson`. Includes several UI changes to display more information when an account has backend sync issues. Adds better messages and new actions the user can take based on the type of sync issue. Additionally, fixes bug in action bridge that was preventing multi-arg global actions from working. Test Plan: Manual, by testing different sync state values and triggering deltas from the backend Reviewers: juan, evan, bengotow Reviewed By: evan, bengotow Subscribers: khamidou Differential Revision: https://phab.nylas.com/D2696
93 lines
2.9 KiB
JavaScript
93 lines
2.9 KiB
JavaScript
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() {
|
|
this.unsubscribe = AccountStore.listen(() => this._onAccountsChanged());
|
|
}
|
|
|
|
getStateFromStores() {
|
|
return {accounts: AccountStore.accounts()}
|
|
}
|
|
|
|
_onAccountsChanged() {
|
|
this.setState(this.getStateFromStores())
|
|
}
|
|
|
|
_reconnect(account) {
|
|
const ipc = require('electron').ipcRenderer;
|
|
ipc.send('command', 'application:add-account', account.provider);
|
|
}
|
|
|
|
_openPreferences() {
|
|
Actions.switchPreferencesTab('Accounts');
|
|
Actions.openPreferences()
|
|
}
|
|
|
|
_contactSupport() {
|
|
const {shell} = require("electron");
|
|
shell.openExternal("https://support.nylas.com/hc/en-us/requests/new");
|
|
}
|
|
|
|
renderErrorHeader(message, buttonName, actionCallback) {
|
|
return (
|
|
<div className="sync-issue notifications-sticky">
|
|
<div className={"notifications-sticky-item notification-error has-default-action"}
|
|
onClick={actionCallback}>
|
|
<div>
|
|
<div className="icon">
|
|
<RetinaImg
|
|
name="icon-alert-onred.png"
|
|
mode={RetinaImg.Mode.ContentPreserve} />
|
|
</div>{message}</div>
|
|
<a className="action default" onClick={actionCallback}>
|
|
{buttonName}
|
|
</a>
|
|
</div>
|
|
</div>)
|
|
}
|
|
|
|
render() {
|
|
const errorAccounts = this.state.accounts.filter(a => a.syncState !== "running");
|
|
if (errorAccounts.length === 1) {
|
|
const account = errorAccounts[0];
|
|
|
|
switch (account.syncState) {
|
|
|
|
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));
|
|
|
|
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());
|
|
|
|
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());
|
|
}
|
|
}
|
|
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",
|
|
()=>this._openPreferences());
|
|
}
|
|
return false;
|
|
}
|
|
}
|