2016-05-25 08:52:04 +02:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
|
|
|
import Actions from "../actions.js";
|
|
|
|
import { Button } from 'react-bootstrap';
|
|
|
|
|
|
|
|
import { Messages } from 'meteor/nova:core';
|
|
|
|
|
|
|
|
class NewsletterButton extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2016-05-25 08:57:12 +02:00
|
|
|
this.subscriptionAction = this.subscriptionAction.bind(this);
|
2016-05-25 08:52:04 +02:00
|
|
|
}
|
|
|
|
|
2016-05-25 08:57:12 +02:00
|
|
|
/**
|
|
|
|
* @summary subscribe or unsubcribe
|
|
|
|
* @params action: string, name of the method for subscribing or unsubscribing user
|
|
|
|
*/
|
|
|
|
subscriptionAction(action) {
|
|
|
|
return () => {
|
|
|
|
Actions.call(action, this.props.user, (error, result) => {
|
|
|
|
if (error) {
|
|
|
|
console.log(error);
|
|
|
|
Messages.flash(error.message, "error");
|
|
|
|
} else {
|
|
|
|
this.props.successCallback(result);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2016-05-25 08:52:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const isSubscribed = Users.getSetting(this.props.user, 'newsletter_subscribeToNewsletter', false);
|
|
|
|
|
|
|
|
return (
|
2016-05-25 08:57:12 +02:00
|
|
|
<Button
|
|
|
|
className="newsletter-button"
|
|
|
|
onClick={this.subscriptionAction(isSubscribed ? "removeUserFromMailChimpList" : "addUserToMailChimpList")}
|
|
|
|
bsStyle="primary"
|
|
|
|
>
|
2016-05-25 08:52:04 +02:00
|
|
|
{isSubscribed ? "Unsubscribe" : this.props.buttonText}
|
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NewsletterButton.propTypes = {
|
|
|
|
user: React.PropTypes.object.isRequired,
|
2016-05-25 08:57:12 +02:00
|
|
|
successCallback: React.PropTypes.func.isRequired,
|
2016-05-25 08:52:04 +02:00
|
|
|
buttonText: React.PropTypes.string
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = NewsletterButton;
|
|
|
|
export default NewsletterButton;
|