- Adds a non-passing cert learner course exit screen - Moves all the logic about what course-exit mode we're in into a utility method in the course-exit folder - Moves all the logic about how the 'Next' button should read into a utility method in the course-exit folder
61 lines
1.7 KiB
JavaScript
61 lines
1.7 KiB
JavaScript
import { useModel } from '../../../generic/model-store';
|
|
|
|
import messages from './messages';
|
|
|
|
const COURSE_EXIT_MODES = {
|
|
disabled: 0,
|
|
celebration: 1,
|
|
nonPassing: 2,
|
|
};
|
|
|
|
// These are taken from the edx-platform `get_cert_data` function found in lms/courseware/views/views.py
|
|
const CELEBRATION_STATUSES = [
|
|
'downloadable',
|
|
'earned_but_not_available',
|
|
'requesting',
|
|
'unverified',
|
|
];
|
|
const NON_CERTIFICATE_STATUSES = [ // no certificate will be given, though a valid certificateData block is provided
|
|
'audit_passing',
|
|
'honor_passing', // honor can be configured to not give a certificate
|
|
];
|
|
|
|
function getCourseExitMode(courseId) {
|
|
const {
|
|
certificateData,
|
|
courseExitPageIsActive,
|
|
userHasPassingGrade,
|
|
} = useModel('courses', courseId);
|
|
|
|
if (!courseExitPageIsActive || !certificateData) {
|
|
return COURSE_EXIT_MODES.disabled;
|
|
}
|
|
|
|
const {
|
|
certStatus,
|
|
} = certificateData;
|
|
const isEligibleForCertificate = NON_CERTIFICATE_STATUSES.indexOf(certStatus) === -1;
|
|
|
|
if (isEligibleForCertificate && !userHasPassingGrade) {
|
|
return COURSE_EXIT_MODES.nonPassing;
|
|
}
|
|
if (CELEBRATION_STATUSES.indexOf(certStatus) !== -1) {
|
|
return COURSE_EXIT_MODES.celebration;
|
|
}
|
|
return COURSE_EXIT_MODES.disabled;
|
|
}
|
|
|
|
// Returns null if course exit is either not active or not handling the current case
|
|
function getCourseExitText(courseId, intl) {
|
|
switch (getCourseExitMode(courseId)) {
|
|
case COURSE_EXIT_MODES.celebration:
|
|
return intl.formatMessage(messages.nextButtonComplete);
|
|
case COURSE_EXIT_MODES.nonPassing:
|
|
return intl.formatMessage(messages.nextButtonEnd);
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export { COURSE_EXIT_MODES, getCourseExitMode, getCourseExitText };
|