When a learner tries to load the B2C course page for a course that starts in the future (error_code="course_not_started"), normally the learning MFE automatically redirects to the B2C dashboard. This change supports an alternate error_code "course_not_started_enterprise_learner" to trigger an alternative redirect to the B2B (enterprise) learner dashboard. This does two main things: 1. When the course metadata API response indicates course_access.error_code = "course_not_started_enterprise_learner" then redirect to "/redirect/enterprise-learner-dashboard". 2. When the top-level router matches path "/redirect/enterprise-learner-dashboard" then redirec to to the value of config `ENTERPRISE_LEARNER_PORTAL_URL`. ENT-8078
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
import PropTypes from 'prop-types';
|
|
import {
|
|
generatePath, useParams, useLocation,
|
|
} from 'react-router-dom';
|
|
import { getConfig } from '@edx/frontend-platform';
|
|
|
|
import queryString from 'query-string';
|
|
import { REDIRECT_MODES } from '../constants';
|
|
|
|
const RedirectPage = ({
|
|
pattern, mode,
|
|
}) => {
|
|
const { courseId } = useParams();
|
|
const location = useLocation();
|
|
const { consentPath } = queryString.parse(location?.search);
|
|
|
|
const {
|
|
LMS_BASE_URL,
|
|
ENTERPRISE_LEARNER_PORTAL_URL,
|
|
} = getConfig();
|
|
|
|
switch (mode) {
|
|
case REDIRECT_MODES.DASHBOARD_REDIRECT:
|
|
global.location.assign(`${LMS_BASE_URL}${pattern}${location?.search}`);
|
|
break;
|
|
case REDIRECT_MODES.ENTERPRISE_LEARNER_DASHBOARD_REDIRECT:
|
|
global.location.assign(ENTERPRISE_LEARNER_PORTAL_URL);
|
|
break;
|
|
case REDIRECT_MODES.CONSENT_REDIRECT:
|
|
global.location.assign(`${LMS_BASE_URL}${consentPath}`);
|
|
break;
|
|
case REDIRECT_MODES.HOME_REDIRECT:
|
|
global.location.assign(generatePath(pattern, { courseId }));
|
|
break;
|
|
default:
|
|
global.location.assign(`${LMS_BASE_URL}${generatePath(pattern, { courseId })}`);
|
|
}
|
|
|
|
return null;
|
|
};
|
|
|
|
RedirectPage.propTypes = {
|
|
pattern: PropTypes.string,
|
|
mode: PropTypes.string.isRequired,
|
|
};
|
|
|
|
RedirectPage.defaultProps = {
|
|
pattern: null,
|
|
};
|
|
|
|
export default RedirectPage;
|