Refactor NPS poll component to separate poll and wrapper components
[MAILPOET-1815]
This commit is contained in:
committed by
M. Shull
parent
777eb1f7b7
commit
442b138d83
@@ -4,8 +4,7 @@ import ReactDOMServer from 'react-dom/server';
|
|||||||
import ReviewRequest from 'review_request.jsx';
|
import ReviewRequest from 'review_request.jsx';
|
||||||
import getTrackingData from 'analytics.js';
|
import getTrackingData from 'analytics.js';
|
||||||
|
|
||||||
const withNpsPoll = function withNpsPoll(Component) {
|
class NpsPoll extends React.Component {
|
||||||
return class extends React.Component {
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
@@ -80,10 +79,10 @@ const withNpsPoll = function withNpsPoll(Component) {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (!window.mailpoet_display_nps_poll) {
|
if (!window.mailpoet_display_nps_poll) {
|
||||||
return (<Component {...this.props} />);
|
return null;
|
||||||
}
|
}
|
||||||
if (window.satismeter) {
|
if (window.satismeter) {
|
||||||
this.displayPoll();
|
setImmediate(this.displayPoll);
|
||||||
} else {
|
} else {
|
||||||
const s = document.createElement('script');
|
const s = document.createElement('script');
|
||||||
s.type = 'text/javascript';
|
s.type = 'text/javascript';
|
||||||
@@ -91,9 +90,17 @@ const withNpsPoll = function withNpsPoll(Component) {
|
|||||||
s.onload = () => this.displayPoll();
|
s.onload = () => this.displayPoll();
|
||||||
document.getElementsByTagName('body')[0].appendChild(s);
|
document.getElementsByTagName('body')[0].appendChild(s);
|
||||||
}
|
}
|
||||||
return (<Component {...this.props} />);
|
return null;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
const withNpsPoll = function withNpsPoll(Component) {
|
||||||
|
return props => (
|
||||||
|
<>
|
||||||
|
<NpsPoll />
|
||||||
|
<Component {...props} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default withNpsPoll;
|
export default withNpsPoll;
|
||||||
|
Reference in New Issue
Block a user