2016-08-08 11:18:21 +09:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
2016-06-03 11:03:36 +09:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
|
|
|
|
2016-07-31 14:14:51 +02:00
|
|
|
// 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">Newsletter</label>
|
|
|
|
<div className="col-sm-9">
|
2016-11-17 11:37:26 -06:00
|
|
|
<Telescope.components.NewsletterButton
|
2016-11-18 11:35:48 -06:00
|
|
|
user={this.props.document}
|
2016-07-31 14:14:51 +02:00
|
|
|
successCallback={() => {
|
|
|
|
this.context.messages.flash("Newsletter subscription updated", "success")
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2016-06-03 11:03:36 +09:00
|
|
|
</div>
|
2016-07-31 14:14:51 +02:00
|
|
|
)
|
|
|
|
}
|
2016-06-03 11:03:36 +09:00
|
|
|
}
|
|
|
|
|
2016-07-21 00:38:49 +02:00
|
|
|
NewsletterSubscribe.contextTypes = {
|
|
|
|
messages: React.PropTypes.object,
|
2016-07-31 14:14:51 +02:00
|
|
|
addToAutofilledValues: React.PropTypes.func,
|
2016-07-21 00:38:49 +02:00
|
|
|
};
|
|
|
|
|
2016-06-03 11:03:36 +09:00
|
|
|
module.exports = NewsletterSubscribe;
|
2016-11-17 11:37:26 -06:00
|
|
|
export default NewsletterSubscribe;
|