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 getTrackingData from 'analytics.js';
|
||||
|
||||
const withNpsPoll = function withNpsPoll(Component) {
|
||||
return class extends React.Component {
|
||||
class NpsPoll extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
@@ -80,10 +79,10 @@ const withNpsPoll = function withNpsPoll(Component) {
|
||||
|
||||
render() {
|
||||
if (!window.mailpoet_display_nps_poll) {
|
||||
return (<Component {...this.props} />);
|
||||
return null;
|
||||
}
|
||||
if (window.satismeter) {
|
||||
this.displayPoll();
|
||||
setImmediate(this.displayPoll);
|
||||
} else {
|
||||
const s = document.createElement('script');
|
||||
s.type = 'text/javascript';
|
||||
@@ -91,9 +90,17 @@ const withNpsPoll = function withNpsPoll(Component) {
|
||||
s.onload = () => this.displayPoll();
|
||||
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;
|
||||
|
Reference in New Issue
Block a user