Files
frontend-app-learning/src/generic/notices/NoticesProvider.jsx
wgu-jesse-stewart ab3f5fd7bc fix: ensure full-height layout (#1724)
When content within a sequence was shorter than the height of the browser viewport, the `.sequence-container > .outline-sidebar-wrapper` element does not expand appropriately.  This caused the course outline sidebar to be partially or completely hidden from view.
2025-06-06 15:55:15 -03:00

36 lines
1.1 KiB
JavaScript

import { useEffect, useState } from 'react';
import { getConfig } from '@edx/frontend-platform';
import PropTypes from 'prop-types';
import { getNotices } from './api';
/**
* This component uses the platform-plugin-notices plugin to function.
* If the user has an unacknowledged notice, they will be rerouted off
* course home and onto a full-screen notice page. If the plugin is not
* installed, or there are no notices, we just passthrough this component.
*/
const NoticesProvider = ({ children }) => {
const [isRedirected, setIsRedirected] = useState();
useEffect(() => {
async function getData() {
if (getConfig().ENABLE_NOTICES) {
const data = await getNotices();
if (data && data.results && data.results.length > 0) {
const { results } = data;
setIsRedirected(true);
window.location.replace(`${results[0]}?next=${window.location.href}`);
}
}
}
getData();
}, []);
return isRedirected === true ? null : children;
};
NoticesProvider.propTypes = {
children: PropTypes.node.isRequired,
};
export default NoticesProvider;