Merge pull request #1512 from mailpoet/in-app-announcements

In app announcements component [MAILPOET-1413]
This commit is contained in:
Michelle Shull
2018-09-19 10:41:30 -04:00
committed by GitHub
4 changed files with 114 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
import React from 'react';
import InAppAnnouncementDot from './in_app_announcement_dot.jsx';
const InAppAnnouncement = (props) => {
if (props.newUser !== null &&
window.mailpoet_is_new_user !== props.newUser
) {
return null;
}
if (props.validUntil < (new Date().getTime() / 1000)) {
return null;
}
return (
<InAppAnnouncementDot
className={props.className}
width={props.width}
height={props.height}
>
{props.children}
</InAppAnnouncementDot>);
};
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;
},
};
InAppAnnouncement.defaultProps = {
width: '900px',
height: '600px',
className: null,
validUntil: null,
newUser: null,
};
module.exports = InAppAnnouncement;

View File

@@ -0,0 +1,34 @@
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import classNames from 'classnames';
import MailPoet from 'mailpoet';
const InAppAnnouncementDot = props => (
<span
role="button"
tabIndex="-1"
className={classNames('mailpoet_in_app_announcement_pulsing_dot', props.className)}
onClick={() => {
MailPoet.Modal.popup({
template: ReactDOMServer.renderToString(props.children),
width: props.width,
height: props.height,
});
}}
/>
);
InAppAnnouncementDot.propTypes = {
width: React.PropTypes.string,
height: React.PropTypes.string,
className: React.PropTypes.string,
children: React.PropTypes.element.isRequired,
};
InAppAnnouncementDot.defaultProps = {
width: 'auto',
height: 'auto',
className: null,
};
module.exports = InAppAnnouncementDot;