2016-12-08 09:42:50 +01:00
|
|
|
import { Components } from 'meteor/nova:lib';
|
2016-06-03 11:03:36 +09:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
2016-12-08 09:42:50 +01:00
|
|
|
import { withMessages } from 'meteor/nova:core';
|
2016-06-03 11:03:36 +09:00
|
|
|
|
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-12-06 18:06:29 +01:00
|
|
|
<Components.NewsletterButton
|
2016-07-31 14:14:51 +02:00
|
|
|
user={this.props.document}
|
|
|
|
successCallback={() => {
|
2016-10-31 17:13:14 +01:00
|
|
|
this.props.flash("Newsletter subscription updated", "success")
|
2016-07-31 14:14:51 +02:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</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 = {
|
2016-07-31 14:14:51 +02:00
|
|
|
addToAutofilledValues: React.PropTypes.func,
|
2016-07-21 00:38:49 +02:00
|
|
|
};
|
|
|
|
|
2016-12-08 09:42:50 +01:00
|
|
|
module.exports = withMessages(NewsletterSubscribe);
|
|
|
|
export default withMessages(NewsletterSubscribe);
|