Add new upgrade offer alert
This commit is contained in:
21
src/offer-alert/OfferAlert.jsx
Normal file
21
src/offer-alert/OfferAlert.jsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import Alert from '../user-messages/Alert';
|
||||
|
||||
function OfferAlert(props) {
|
||||
const {
|
||||
rawHtml,
|
||||
} = props;
|
||||
return rawHtml && (
|
||||
<Alert type="info">
|
||||
<div dangerouslySetInnerHTML={{ __html: rawHtml }} />
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
OfferAlert.propTypes = {
|
||||
rawHtml: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
export default OfferAlert;
|
||||
28
src/offer-alert/hooks.js
Normal file
28
src/offer-alert/hooks.js
Normal file
@@ -0,0 +1,28 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import { useContext, useState, useEffect } from 'react';
|
||||
import UserMessagesContext from '../user-messages/UserMessagesContext';
|
||||
import { useModel } from '../model-store';
|
||||
|
||||
export function useOfferAlert(courseId) {
|
||||
const course = useModel('courses', courseId);
|
||||
const { add, remove } = useContext(UserMessagesContext);
|
||||
const [alertId, setAlertId] = useState(null);
|
||||
const rawHtml = (course && course.offerHtml) || null;
|
||||
useEffect(() => {
|
||||
if (rawHtml && alertId === null) {
|
||||
setAlertId(add({
|
||||
code: 'clientOfferAlert',
|
||||
topic: 'course',
|
||||
rawHtml,
|
||||
}));
|
||||
} else if (!rawHtml && alertId !== null) {
|
||||
remove(alertId);
|
||||
setAlertId(null);
|
||||
}
|
||||
return () => {
|
||||
if (alertId !== null) {
|
||||
remove(alertId);
|
||||
}
|
||||
};
|
||||
}, [course, rawHtml]);
|
||||
}
|
||||
2
src/offer-alert/index.js
Normal file
2
src/offer-alert/index.js
Normal file
@@ -0,0 +1,2 @@
|
||||
export { default as OfferAlert } from './OfferAlert';
|
||||
export { useOfferAlert } from './hooks';
|
||||
Reference in New Issue
Block a user