Mailspring/internal_packages/preferences/lib/tabs/preferences-identity.jsx
Evan Morikawa 7210c80c5a fix(subscription): show Nylas Basic subscription with CTA to upgrade
Summary:
Removes references to the N1 ID expring.

Luckily, local-sync Nylas Mail Basic doesn't need the nylas ID to do
pretty much anything, which means we don't need to worry about the "trial"
status of the Nylas ID. The existing trial infrastructure will only kick
into place when someone connects an email account with the Nylas Cloud
Sync servers for the first time.

The one place we do check for the Nylas ID is in the
cloud-api/src/authentication route. Here we hit
https://billing.nylas.com/n1/user and simply expect to get back a Nylas
ID. As long as we return the existence of a Nylas ID (which should ignore
whether or not the old subscription system is "valid"), the API calls will
succeed.

This makes the "Upgrade Now" button go to
billing.nylas.com/dashboard?upgrade_to_pro=true with the auto-sign in
features enabled. This will automatically log the user into the Nylas
billing site with the upgrade_to_pro=true flag set.

There is also a new "Learn More" button which goes to
https://nylas.com/nylas-pro.

@mike, will these urls work?

Test Plan: manual

Reviewers: khamidou, mike, juan

Reviewed By: juan

Subscribers: mike

Differential Revision: https://phab.nylas.com/D3680
2017-01-14 17:40:54 -08:00

125 lines
3.5 KiB
JavaScript

import React from 'react';
import {Actions, IdentityStore} from 'nylas-exports';
import {RetinaImg} from 'nylas-component-kit';
import {shell} from 'electron';
class OpenIdentityPageButton extends React.Component {
static propTypes = {
path: React.PropTypes.string,
label: React.PropTypes.string,
source: React.PropTypes.string,
campaign: React.PropTypes.string,
img: React.PropTypes.string,
}
constructor(props) {
super(props);
this.state = {
loading: false,
};
}
_onClick = () => {
this.setState({loading: true});
IdentityStore.fetchSingleSignOnURL(this.props.path, {
source: this.props.source,
campaign: this.props.campaign,
content: this.props.label,
}).then((url) => {
this.setState({loading: false});
shell.openExternal(url);
});
}
render() {
if (this.state.loading) {
return (
<div className="btn btn-disabled">
<RetinaImg name="sending-spinner.gif" width={15} height={15} mode={RetinaImg.Mode.ContentPreserve} />
&nbsp;{this.props.label}&hellip;
</div>
);
}
if (this.props.img) {
return (
<div className="btn" onClick={this._onClick}>
<RetinaImg name={this.props.img} mode={RetinaImg.Mode.ContentPreserve} />
&nbsp;&nbsp;{this.props.label}
</div>
)
}
return (
<div className="btn" onClick={this._onClick}>{this.props.label}</div>
);
}
}
class PreferencesIdentity extends React.Component {
static displayName = 'PreferencesIdentity';
constructor() {
super();
this.state = this.getStateFromStores();
}
componentDidMount() {
this.unsubscribe = IdentityStore.listen(() => {
this.setState(this.getStateFromStores());
});
}
componentWillUnmount() {
this.unsubscribe();
}
getStateFromStores() {
return {
identity: IdentityStore.identity() || {},
};
}
render() {
const {identity} = this.state;
const {firstname, lastname, email} = identity;
const logout = () => Actions.logoutNylasIdentity()
const learnMore = () => shell.openExternal("https://nylas.com/nylas-pro")
return (
<div className="container-identity">
<div className="id-header">
Nylas ID:
</div>
<div className="identity-content-box">
<div className="row info-row">
<div className="logo">
<RetinaImg
name="prefs-identity-nylas-logo.png"
mode={RetinaImg.Mode.ContentPreserve}
/>
</div>
<div className="identity-info">
<div className="name">{firstname} {lastname}</div>
<div className="email">{email}</div>
<div className="identity-actions">
<OpenIdentityPageButton label="Account Details" path="/dashboard" source="Preferences" campaign="Dashboard" />
<OpenIdentityPageButton label="Upgrade to Nylas Pro" path="/dashboard?upgrade_to_pro=true" source="Preferences" campaign="Dashboard" />
<div className="btn" onClick={logout}>Sign Out</div>
</div>
</div>
</div>
<div className="row payment-row">
<div>
You are using Nylas Mail Basic. Upgrade to Nylas Pro to unlock a more powerful email experience.
</div>
<div className="btn" onClick={learnMore}>Learn More about Nylas Pro</div>
</div>
</div>
</div>
);
}
}
export default PreferencesIdentity;