diff --git a/assets/js/src/announcements/feature_announcement.jsx b/assets/js/src/announcements/feature_announcement.jsx index 61f02b96c3..a4289c16c4 100644 --- a/assets/js/src/announcements/feature_announcement.jsx +++ b/assets/js/src/announcements/feature_announcement.jsx @@ -8,33 +8,47 @@ class FeatureAnnouncement extends React.Component { super(props); this.loadBeamer = this.loadBeamer.bind(this); this.beamerCallback = this.beamerCallback.bind(this); + this.showBeamer = this.showBeamer.bind(this); this.state = { showDot: props.hasNews, beamerLoaded: typeof window.Beamer !== 'undefined', + beamerInitialized: false, }; } - loadBeamer(e) { - e.preventDefault(); - if (!this.state.beamerLoaded) { - window.beamer_config = { - product_id: 'VvHbhYWy7118', - selector: 'beamer-selector', - language: window.mailpoet_user_locale, - callback: this.beamerCallback, - }; - MailPoet.Modal.loading(true); - this.setState({ beamerLoaded: true }); - window.mailpoet_feature_announcement_has_news = false; - const s = document.createElement('script'); - s.type = 'text/javascript'; - s.src = 'https://app.getbeamer.com/js/beamer-embed.js'; - document.getElementsByTagName('body')[0].appendChild(s); - } + loadBeamer() { + window.beamer_config = { + product_id: 'VvHbhYWy7118', + language: window.mailpoet_user_locale, + callback: this.beamerCallback, + }; + MailPoet.Modal.loading(true); + window.mailpoet_feature_announcement_has_news = false; + this.setState({ beamerLoaded: true }); + const s = document.createElement('script'); + s.type = 'text/javascript'; + s.src = 'https://app.getbeamer.com/js/beamer-embed.js'; + document.getElementsByTagName('body')[0].appendChild(s); } beamerCallback() { + // We show Beamer panel only on first callback after initialization + if (this.state.beamerInitialized) { + return; + } + this.showBeamer(); + this.setState({ beamerInitialized: true }); + } + + showBeamer(event) { + if (event) { + event.preventDefault(); + } + if (!this.state.beamerLoaded) { + this.loadBeamer(); + return; + } this.setState({ showDot: false }); MailPoet.Modal.loading(false); window.Beamer.show(); @@ -58,15 +72,13 @@ class FeatureAnnouncement extends React.Component {
- ); } }