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,
img: React.PropTypes.string,
}
constructor(props) {
super(props);
this.state = {
loading: false,
};
}
_onClick = () => {
IdentityStore.fetchSingleSignOnURL(this.props.path).then((url) => {
this.setState({loading: false});
shell.openExternal(url);
});
}
render() {
if (this.state.loading) {
return (
{this.props.label}…
);
}
if (this.props.img) {
return (
{this.props.label}
)
}
return (
{this.props.label}
);
}
}
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(),
subscriptionState: IdentityStore.subscriptionState(),
trialDaysRemaining: IdentityStore.trialDaysRemaining(),
};
}
_renderPaymentRow() {
const {identity, trialDaysRemaining, subscriptionState} = this.state
if (subscriptionState === IdentityStore.SubscriptionState.Trialing) {
return (
There {(trialDaysRemaining > 1) ? `are ${trialDaysRemaining} days ` : `is one day `}
remaining in your 30-day trial of Nylas Pro.
)
}
if (subscriptionState === IdentityStore.SubscriptionState.Lapsed) {
return (
Your subscription has been cancelled or your billing information has expired.
We've paused your mailboxes! Re-new your subscription to continue using N1.
)
}
return (
Your subscription will renew on {new Date(identity.valid_until).toLocaleDateString()}. Enjoy N1!
)
}
render() {
const {identity} = this.state
const {firstname, lastname, email} = identity
return (
Nylas ID:
{firstname} {lastname}
{email}
Actions.logoutNylasIdentity()}>Sign Out
{this._renderPaymentRow()}
);
}
}
export default PreferencesIdentity;