Merge pull request #1512 from mailpoet/in-app-announcements
In app announcements component [MAILPOET-1413]
This commit is contained in:
51
assets/js/src/in_app_announcements/in_app_announcement.jsx
Normal file
51
assets/js/src/in_app_announcements/in_app_announcement.jsx
Normal 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;
|
@@ -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;
|
Reference in New Issue
Block a user