From be17a35faae86b37e3f5c1bb6f3501be5ccfd695 Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Wed, 19 Sep 2018 09:03:44 +0200 Subject: [PATCH] Add condition for premium user to an in app announcement [MAILPOET-1525] --- .../in_app_announcement.jsx | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/assets/js/src/in_app_announcements/in_app_announcement.jsx b/assets/js/src/in_app_announcements/in_app_announcement.jsx index a267c27765..6d6ce49302 100644 --- a/assets/js/src/in_app_announcements/in_app_announcement.jsx +++ b/assets/js/src/in_app_announcements/in_app_announcement.jsx @@ -13,6 +13,12 @@ class InAppAnnouncement extends React.Component { return null; } + if (this.props.premiumUser !== null && + window.mailpoet_premium_active !== this.props.premiumUser + ) { + return null; + } + return ( { + const propValue = props[propName]; + if (propValue !== null && propValue !== true && propValue !== false) { + return new Error(`Invalid property in ${componentName}. newUser must be of type boolean`); + } + if (propValue !== null && typeof window[windowProperty] === 'undefined') { + return new Error( + `Missing data for evaluation of ${componentName} display condition. ${propName} requires window.${windowProperty}` + ); + } + return null; +}; + InAppAnnouncement.propTypes = { width: React.PropTypes.string, height: React.PropTypes.string, className: React.PropTypes.string, children: React.PropTypes.element.isRequired, validUntil: React.PropTypes.number, - newUser: (props, propName, componentName) => { - const propValue = props[propName]; - if (propValue !== null && propValue !== true && propValue !== false) { - return new Error(`Invalid property in ${componentName}. newUser must be of type boolean`); - } - if (typeof window.mailpoet_is_new_user === 'undefined') { - return new Error(`Missing data for evaluation of ${componentName} display condition. ${propName} requires window.mailpoet_is_new_user`); - } - return null; - }, + newUser: (props, propName, componentName) => ( + validateBooleanWithWindowDependency(props, propName, componentName, 'mailpoet_is_new_user') + ), + premiumUser: (props, propName, componentName) => ( + validateBooleanWithWindowDependency(props, propName, componentName, 'mailpoet_premium_active') + ), }; InAppAnnouncement.defaultProps = { @@ -49,6 +64,7 @@ InAppAnnouncement.defaultProps = { className: null, validUntil: null, newUser: null, + premiumUser: null, }; module.exports = InAppAnnouncement;