Files
frontend-app-learning/src/shared/access.js
Troy Sankey 79575330c9 feat: Add redirect to enterprise learner dashboard (#1251)
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
2023-12-15 07:45:36 -05:00

42 lines
1.6 KiB
JavaScript

/* eslint-disable import/prefer-default-export */
import { getLocale } from '@edx/frontend-platform/i18n';
// This function inspects an access denied error and provides a redirect url (looks like a /redirect/... path),
// which then renders a nice little message while the browser loads the next page.
// This is basically a frontend version of check_course_access_with_redirect in the backend.
export function getAccessDeniedRedirectUrl(courseId, activeTabSlug, courseAccess, start) {
let url = null;
switch (courseAccess.errorCode) {
case 'audit_expired':
url = `/redirect/dashboard?access_response_error=${courseAccess.additionalContextUserMessage}`;
break;
case 'course_not_started':
// eslint-disable-next-line no-case-declarations
const startDate = (new Intl.DateTimeFormat(getLocale())).format(new Date(start));
url = `/redirect/dashboard?notlive=${startDate}`;
break;
case 'course_not_started_enterprise_learner':
url = '/redirect/enterprise-learner-dashboard';
break;
case 'survey_required':
url = `/redirect/survey/${courseId}`;
break;
case 'data_sharing_access_required':
url = `/redirect/consent?consentPath=${encodeURIComponent(courseAccess.developerMessage)}`;
break;
case 'incorrect_active_enterprise':
url = `/course/${courseId}/access-denied`;
break;
case 'unfulfilled_milestones':
url = '/redirect/dashboard';
break;
case 'authentication_required':
case 'enrollment_required':
default:
if (activeTabSlug !== 'outline') {
url = `/course/${courseId}/home`;
}
}
return url;
}