Add condition for premium user to an in app announcement
[MAILPOET-1525]
This commit is contained in:
@@ -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 (
|
||||
<InAppAnnouncementDot
|
||||
className={this.props.className}
|
||||
@@ -25,22 +31,31 @@ class InAppAnnouncement extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
const validateBooleanWithWindowDependency = (props, propName, componentName, windowProperty) => {
|
||||
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;
|
||||
|
Reference in New Issue
Block a user