Vulcan/packages/nova-newsletter/lib/components/NewsletterSubscribe.jsx
2016-11-24 08:27:12 -06:00

45 lines
1.5 KiB
JavaScript

import Telescope from 'meteor/nova:lib';
import React, { PropTypes, Component } from 'react';
import { intlShape } from 'react-intl';
// this component is used as a custom controller in user's account edit (cf. ./custom_fields.js)
class NewsletterSubscribe extends Component {
// initiate NovaForm with the newsletter setting value
// note: forced boolean value because NovaForm's falsy value are empty double quotes.
componentWillMount() {
this.context.addToAutofilledValues({[this.props.name]: !!this.props.value});
}
componentWillReceiveProps(nextProps, nextContext) {
// if the user is editing her profile & subscribed to the newsletter from the banner, send the update to NovaForm
if (!!nextProps.value !== !!this.props.value) {
this.context.addToAutofilledValues({[this.props.name]: !!nextProps.value});
}
}
render() {
return (
<div className="form-group row">
<label className="control-label col-sm-3"></label>
<div className="col-sm-9">
<Telescope.components.NewsletterButton
user={this.props.document}
successCallback={() => {
this.context.messages.flash(this.context.intl.formatMessage({id: "newsletter.subscription_updated"}), "success")
}}
/>
</div>
</div>
)
}
}
NewsletterSubscribe.contextTypes = {
messages: React.PropTypes.object,
addToAutofilledValues: React.PropTypes.func,
intl: intlShape
};
module.exports = NewsletterSubscribe;
export default NewsletterSubscribe;