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 './open-tracking-constants'
|
2016-02-26 04:48:05 +08:00
|
|
|
import uuid from 'node-uuid';
|
2016-02-24 14:55:47 +08:00
|
|
|
|
2016-02-20 04:30:24 +08:00
|
|
|
export default class OpenTrackingButton extends React.Component {
|
|
|
|
static displayName = 'OpenTrackingButton';
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
draftClientId: React.PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
2016-02-25 06:45:47 +08:00
|
|
|
_title(enabled) {
|
|
|
|
const dir = enabled ? "Disable" : "Enable";
|
|
|
|
return `${dir} read receipts`
|
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 `Read receipts do not work offline. Please re-enable when you come back online.`
|
|
|
|
}
|
2016-02-25 10:21:16 +08:00
|
|
|
return `Unfortunately, read receipts are currently not available. Please try again later. Error: ${error.message}`
|
2016-02-20 04:30:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-02-26 04:48:05 +08:00
|
|
|
const enabledValue = {
|
|
|
|
uid: uuid.v4().replace(/-/g, ""),
|
|
|
|
open_count: 0,
|
|
|
|
open_data: [],
|
|
|
|
};
|
|
|
|
|
2016-02-25 06:45:47 +08:00
|
|
|
return (
|
|
|
|
<MetadataComposerToggleButton
|
|
|
|
title={this._title}
|
|
|
|
iconUrl="nylas://open-tracking/assets/icon-composer-eye@2x.png"
|
|
|
|
pluginId={PLUGIN_ID}
|
|
|
|
pluginName={PLUGIN_NAME}
|
2016-02-26 04:48:05 +08:00
|
|
|
metadataEnabledValue={enabledValue}
|
2016-02-25 06:45:47 +08:00
|
|
|
stickyToggle
|
|
|
|
errorMessage={this._errorMessage}
|
|
|
|
draftClientId={this.props.draftClientId} />
|
|
|
|
)
|
2016-02-20 04:30:24 +08:00
|
|
|
}
|
|
|
|
}
|