2016-02-25 06:45:47 +08:00
|
|
|
// import {DraftStore, React, Actions, NylasAPI, DatabaseStore, Message, Rx} from 'nylas-exports'
|
2016-02-25 08:05:16 +08:00
|
|
|
import {React, APIError, NylasAPI} from 'nylas-exports'
|
2016-02-25 06:45:47 +08:00
|
|
|
import {MetadataComposerToggleButton} from 'nylas-component-kit'
|
2016-02-24 14:55:47 +08:00
|
|
|
import {PLUGIN_ID, PLUGIN_NAME} from './link-tracking-constants'
|
|
|
|
|
2016-02-20 04:30:24 +08:00
|
|
|
export default class LinkTrackingButton extends React.Component {
|
|
|
|
static displayName = 'LinkTrackingButton';
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
draftClientId: React.PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
2016-02-25 06:45:47 +08:00
|
|
|
_title(enabled) {
|
|
|
|
const dir = enabled ? "Disable" : "Enable";
|
|
|
|
return `${dir} link tracking`
|
2016-02-20 04:30:24 +08:00
|
|
|
}
|
|
|
|
|
2016-02-25 06:45:47 +08:00
|
|
|
_errorMessage(error) {
|
2016-02-25 08:05:16 +08:00
|
|
|
if (error instanceof APIError && error.statusCode === NylasAPI.TimeoutErrorCode) {
|
|
|
|
return `Link tracking does not work offline. Please re-enable when you come back online.`
|
|
|
|
}
|
2016-02-25 10:21:16 +08:00
|
|
|
return `Unfortunately, link tracking servers are currently not available. Please try again later. Error: ${error.message}`
|
2016-02-20 04:30:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2016-02-25 06:45:47 +08:00
|
|
|
<MetadataComposerToggleButton
|
|
|
|
title={this._title}
|
|
|
|
iconName="icon-composer-linktracking.png"
|
|
|
|
pluginId={PLUGIN_ID}
|
|
|
|
pluginName={PLUGIN_NAME}
|
2016-02-26 04:48:05 +08:00
|
|
|
metadataEnabledValue={{"tracked": true}}
|
2016-02-25 06:45:47 +08:00
|
|
|
stickyToggle
|
|
|
|
errorMessage={this._errorMessage}
|
|
|
|
draftClientId={this.props.draftClientId} />
|
2016-02-20 04:30:24 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|