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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.props.premiumUser !== null &&
|
||||||
|
window.mailpoet_premium_active !== this.props.premiumUser
|
||||||
|
) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<InAppAnnouncementDot
|
<InAppAnnouncementDot
|
||||||
className={this.props.className}
|
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 = {
|
InAppAnnouncement.propTypes = {
|
||||||
width: React.PropTypes.string,
|
width: React.PropTypes.string,
|
||||||
height: React.PropTypes.string,
|
height: React.PropTypes.string,
|
||||||
className: React.PropTypes.string,
|
className: React.PropTypes.string,
|
||||||
children: React.PropTypes.element.isRequired,
|
children: React.PropTypes.element.isRequired,
|
||||||
validUntil: React.PropTypes.number,
|
validUntil: React.PropTypes.number,
|
||||||
newUser: (props, propName, componentName) => {
|
newUser: (props, propName, componentName) => (
|
||||||
const propValue = props[propName];
|
validateBooleanWithWindowDependency(props, propName, componentName, 'mailpoet_is_new_user')
|
||||||
if (propValue !== null && propValue !== true && propValue !== false) {
|
),
|
||||||
return new Error(`Invalid property in ${componentName}. newUser must be of type boolean`);
|
premiumUser: (props, propName, componentName) => (
|
||||||
}
|
validateBooleanWithWindowDependency(props, propName, componentName, 'mailpoet_premium_active')
|
||||||
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;
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
InAppAnnouncement.defaultProps = {
|
InAppAnnouncement.defaultProps = {
|
||||||
@@ -49,6 +64,7 @@ InAppAnnouncement.defaultProps = {
|
|||||||
className: null,
|
className: null,
|
||||||
validUntil: null,
|
validUntil: null,
|
||||||
newUser: null,
|
newUser: null,
|
||||||
|
premiumUser: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = InAppAnnouncement;
|
module.exports = InAppAnnouncement;
|
||||||
|
Reference in New Issue
Block a user