import React, { PropTypes, Component } from 'react';
import { FormattedMessage, intlShape } from 'react-intl';
import Formsy from 'formsy-react';
import { Input } from 'formsy-react-components';
//import Actions from "../actions.js";
import { Button } from 'react-bootstrap';
import Cookie from 'react-cookie';
//import { Messages } from "meteor/nova:core";
class Newsletter extends Component {
constructor(props, context) {
super(props);
this.subscribeEmail = this.subscribeEmail.bind(this);
this.successCallbackSubscription = this.successCallbackSubscription.bind(this);
this.dismissBanner = this.dismissBanner.bind(this);
const showBanner =
Cookie.load('showBanner') !== "no" &&
!Users.getSetting(context.currentUser, 'newsletter_subscribeToNewsletter', false);
this.state = {
showBanner: showBanner
};
}
componentWillReceiveProps(nextProps, nextContext) {
if (nextContext.currentUser) {
const showBanner =
Cookie.load('showBanner') !== "no" &&
!Users.getSetting(nextContext.currentUser, 'newsletter_subscribeToNewsletter', false);
this.setState({showBanner});
}
}
subscribeEmail(data) {
this.context.actions.call("newsletter.addEmail", data.email, (error, result) => {
if (error) {
console.log(error);
this.context.messages.flash(error.message, "error");
} else {
this.successCallbackSubscription(result);
}
});
}
successCallbackSubscription(result) {
this.context.messages.flash(this.context.intl.formatMessage({id: "newsletter.success_message"}), "success");
this.dismissBanner();
}
dismissBanner(e) {
if (e && e.preventDefault) e.preventDefault();
this.setState({showBanner: false});
// set cookie
Cookie.save('showBanner', "no");
}
renderForm() {
return (