2016-05-28 05:05:27 +08:00
|
|
|
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,
|
2016-06-08 03:53:05 +08:00
|
|
|
source: React.PropTypes.string,
|
|
|
|
campaign: React.PropTypes.string,
|
2016-05-28 05:05:27 +08:00
|
|
|
img: React.PropTypes.string,
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
loading: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
_onClick = () => {
|
2016-06-08 03:53:05 +08:00
|
|
|
this.setState({loading: true});
|
|
|
|
IdentityStore.fetchSingleSignOnURL(this.props.path, {
|
|
|
|
source: this.props.source,
|
|
|
|
campaign: this.props.campaign,
|
|
|
|
content: this.props.label,
|
|
|
|
}).then((url) => {
|
2016-05-28 05:05:27 +08:00
|
|
|
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} />
|
|
|
|
{this.props.label}…
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (this.props.img) {
|
|
|
|
return (
|
|
|
|
<div className="btn" onClick={this._onClick}>
|
|
|
|
<RetinaImg name={this.props.img} mode={RetinaImg.Mode.ContentPreserve} />
|
|
|
|
{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();
|
2016-06-14 03:06:37 +08:00
|
|
|
this.state.refreshing = false;
|
2016-05-28 05:05:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.unsubscribe = IdentityStore.listen(() => {
|
|
|
|
this.setState(this.getStateFromStores());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.unsubscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
getStateFromStores() {
|
|
|
|
return {
|
2016-06-03 09:56:03 +08:00
|
|
|
identity: IdentityStore.identity() || {},
|
2016-05-28 05:05:27 +08:00
|
|
|
subscriptionState: IdentityStore.subscriptionState(),
|
2016-06-11 05:29:21 +08:00
|
|
|
daysUntilSubscriptionRequired: IdentityStore.daysUntilSubscriptionRequired(),
|
2016-05-28 05:05:27 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-06-14 03:06:37 +08:00
|
|
|
_onRefresh = () => {
|
|
|
|
this.setState({refreshing: true});
|
|
|
|
IdentityStore.refreshStatus().finally(() => {
|
|
|
|
this.setState({refreshing: false});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-05-28 05:05:27 +08:00
|
|
|
_renderPaymentRow() {
|
2016-06-11 05:29:21 +08:00
|
|
|
const {identity, daysUntilSubscriptionRequired, subscriptionState} = this.state
|
2016-05-28 05:05:27 +08:00
|
|
|
|
2016-06-01 03:24:21 +08:00
|
|
|
if (subscriptionState === IdentityStore.State.Trialing) {
|
2016-06-11 05:29:21 +08:00
|
|
|
let msg = "You have not upgraded to Nylas Pro.";
|
|
|
|
if (daysUntilSubscriptionRequired > 1) {
|
|
|
|
msg = `There are ${daysUntilSubscriptionRequired} days remaining in your 30-day trial of Nylas Pro.`;
|
|
|
|
} else if (daysUntilSubscriptionRequired === 1) {
|
|
|
|
msg = `There is one day remaining in your trial of Nylas Pro. Upgrade today!`;
|
|
|
|
}
|
2016-05-28 05:05:27 +08:00
|
|
|
return (
|
|
|
|
<div className="row payment-row">
|
2016-06-11 05:29:21 +08:00
|
|
|
<div>{msg}</div>
|
2016-06-08 03:53:05 +08:00
|
|
|
<OpenIdentityPageButton img="ic-upgrade.png" label="Upgrade to Nylas Pro" path="/payment" campaign="Upgrade" source="Preferences" />
|
2016-05-28 05:05:27 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-06-01 03:24:21 +08:00
|
|
|
if (subscriptionState === IdentityStore.State.Lapsed) {
|
2016-05-28 05:05:27 +08:00
|
|
|
return (
|
|
|
|
<div className="row payment-row">
|
|
|
|
<div>
|
2016-06-17 03:23:06 +08:00
|
|
|
Your subscription has been canceled or your billing information has expired.
|
|
|
|
We've paused your mailboxes! Renew your subscription to continue using N1.
|
2016-05-28 05:05:27 +08:00
|
|
|
</div>
|
2016-06-08 03:53:05 +08:00
|
|
|
<OpenIdentityPageButton img="ic-upgrade.png" label="Update Subscription" path="/dashboard#subscription" campaign="Renew" source="Preferences" />
|
2016-05-28 05:05:27 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="row payment-row">
|
|
|
|
<div>
|
2016-06-17 03:23:06 +08:00
|
|
|
Your subscription is valid until {new Date(identity.valid_until * 1000).toLocaleDateString()}. Enjoy N1!
|
2016-05-28 05:05:27 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-06-14 03:06:37 +08:00
|
|
|
const {identity, refreshing} = this.state;
|
2016-06-03 09:56:03 +08:00
|
|
|
const {firstname, lastname, email} = identity;
|
|
|
|
|
2016-06-14 03:06:37 +08:00
|
|
|
let refresh = null;
|
|
|
|
if (refreshing) {
|
|
|
|
refresh = (
|
|
|
|
<a className="refresh spinning" onClick={this._onRefresh}>
|
|
|
|
Refreshing... <RetinaImg style={{verticalAlign: 'sub'}} name="ic-refresh.png" mode={RetinaImg.Mode.ContentIsMask} />
|
|
|
|
</a>
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
refresh = (
|
|
|
|
<a className="refresh" onClick={this._onRefresh}>
|
|
|
|
Refresh <RetinaImg style={{verticalAlign: 'sub'}} name="ic-refresh.png" mode={RetinaImg.Mode.ContentIsMask} />
|
|
|
|
</a>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2016-05-28 05:05:27 +08:00
|
|
|
return (
|
|
|
|
<div className="container-identity">
|
2016-06-14 03:06:37 +08:00
|
|
|
<div className="id-header">
|
|
|
|
Nylas ID:
|
|
|
|
{refresh}
|
|
|
|
</div>
|
2016-05-28 05:05:27 +08:00
|
|
|
<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">
|
2016-06-08 03:53:05 +08:00
|
|
|
<OpenIdentityPageButton label="Account Details" path="/dashboard" source="Preferences" campaign="Dashboard" />
|
2016-05-28 05:05:27 +08:00
|
|
|
<div className="btn" onClick={() => Actions.logoutNylasIdentity()}>Sign Out</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{this._renderPaymentRow()}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PreferencesIdentity;
|