/* eslint global-require: 0 */ import {AccountStore, Account, Actions, React, IdentityStore} from 'nylas-exports' import {RetinaImg} from 'nylas-component-kit' import {shell} from 'electron'; export default class AccountErrorHeader extends React.Component { static displayName = 'AccountErrorHeader'; constructor() { super(); this.state = this.getStateFromStores(); this.upgradeLabel = "" } componentDidMount() { this.mounted = true; this.unsubscribers = [ AccountStore.listen(() => this.setState(this.getStateFromStores())), IdentityStore.listen(() => this.setState(this.getStateFromStores())), ]; } componentWillUnmount() { this.mounted = false; for (const unsub of this.unsubscribers) { unsub(); } this.unsubscribers = null; } getStateFromStores() { return { accounts: AccountStore.accounts(), subscriptionState: IdentityStore.subscriptionState(), daysUntilSubscriptionRequired: IdentityStore.daysUntilSubscriptionRequired(), } } _reconnect(existingAccount) { const ipc = require('electron').ipcRenderer; ipc.send('command', 'application:add-account', {existingAccount}); } _openPreferences() { Actions.switchPreferencesTab('Accounts'); Actions.openPreferences() } _contactSupport() { shell.openExternal("https://support.nylas.com/hc/en-us/requests/new"); } _onCheckAgain = (event) => { const errorAccounts = this.state.accounts.filter(a => a.hasSyncStateError()); this.setState({refreshing: true}); event.stopPropagation(); IdentityStore.refreshStatus().finally(() => { AccountStore.refreshHealthOfAccounts(errorAccounts.map(a => a.id)).finally(() => { if (!this.mounted) { return; } this.setState({refreshing: false}); }); }); } _onUpgrade = () => { this.setState({buildingUpgradeURL: true}); const isSubscription = this.state.subscriptionState === IdentityStore.State.Lapsed const utm = { source: "UpgradeBanner", campaign: isSubscription ? "SubscriptionExpired" : "TrialExpired", } IdentityStore.fetchSingleSignOnURL('/payment', utm).then((url) => { this.setState({buildingUpgradeURL: false}); shell.openExternal(url); }); } _renderErrorHeader(message, buttonName, actionCallback) { return (
) } _renderUpgradeHeader() { return (