-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: AA-1205: Enable Entrance Exam support for Learning MFE (#840)
Adds an alert to the courseware if the section is an Entrance Exam. Also adds a listener to reload the page upon receiving a message from the LMS indicating the user has now passed the exam. Commit also contains misc. clean up for i18n messages switching to variable names.
- Loading branch information
1 parent
385635f
commit 57c3f30
Showing
9 changed files
with
207 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { useModel } from '../../generic/model-store'; | ||
import { ALERT_TYPES, useAlert } from '../../generic/user-messages'; | ||
|
||
import messages from './messages'; | ||
|
||
function useSequenceBannerTextAlert(sequenceId) { | ||
const sequence = useModel('sequences', sequenceId); | ||
const sequenceStatus = useSelector(state => state.courseware.sequenceStatus); | ||
|
||
// Show Alert that comes along with the sequence | ||
useAlert(sequenceStatus === 'loaded' && sequence.bannerText, { | ||
code: null, | ||
dismissible: false, | ||
text: sequence.bannerText, | ||
type: ALERT_TYPES.INFO, | ||
topic: 'sequence', | ||
}); | ||
} | ||
|
||
function useSequenceEntranceExamAlert(courseId, sequenceId, intl) { | ||
const course = useModel('coursewareMeta', courseId); | ||
const sequence = useModel('sequences', sequenceId); | ||
const sequenceStatus = useSelector(state => state.courseware.sequenceStatus); | ||
const { | ||
entranceExamCurrentScore, | ||
entranceExamEnabled, | ||
entranceExamId, | ||
entranceExamMinimumScorePct, | ||
entranceExamPassed, | ||
} = course.entranceExamData || {}; | ||
const entranceExamAlertVisible = sequenceStatus === 'loaded' && entranceExamEnabled && entranceExamId === sequence.sectionId; | ||
let entranceExamText; | ||
|
||
if (entranceExamPassed) { | ||
entranceExamText = intl.formatMessage( | ||
messages.entranceExamTextPassed, { entranceExamCurrentScore: entranceExamCurrentScore * 100 }, | ||
); | ||
} else { | ||
entranceExamText = intl.formatMessage(messages.entranceExamTextNotPassing, { | ||
entranceExamCurrentScore: entranceExamCurrentScore * 100, | ||
entranceExamMinimumScorePct: entranceExamMinimumScorePct * 100, | ||
}); | ||
} | ||
|
||
useAlert(entranceExamAlertVisible, { | ||
code: null, | ||
dismissible: false, | ||
text: entranceExamText, | ||
type: ALERT_TYPES.INFO, | ||
topic: 'sequence', | ||
}); | ||
} | ||
|
||
export { useSequenceBannerTextAlert, useSequenceEntranceExamAlert }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { defineMessages } from '@edx/frontend-platform/i18n'; | ||
|
||
const messages = defineMessages({ | ||
entranceExamTextNotPassing: { | ||
id: 'learn.sequence.entranceExamTextNotPassing', | ||
defaultMessage: 'To access course materials, you must score {entranceExamMinimumScorePct}% or higher on this exam. Your current score is {entranceExamCurrentScore}%.', | ||
}, | ||
entranceExamTextPassed: { | ||
id: 'learn.sequence.entranceExamTextPassed', | ||
defaultMessage: 'Your score is {entranceExamCurrentScore}%. You have passed the entrance exam.', | ||
}, | ||
}); | ||
|
||
export default messages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,36 @@ | ||
import { defineMessages } from '@edx/frontend-platform/i18n'; | ||
|
||
const messages = defineMessages({ | ||
'learn.loading.content.lock': { | ||
id: 'learn.loading.content.lock', | ||
defaultMessage: 'Loading locked content messaging...', | ||
description: 'Message shown when an interface about locked content is being loaded', | ||
headerPlaceholder: { | ||
id: 'learn.header.h2.placeholder', | ||
defaultMessage: 'Level 2 headings may be created by course providers in the future.', | ||
description: 'Message spoken by a screenreader indicating that the h2 tag is a placeholder.', | ||
}, | ||
'learn.loading.honor.code': { | ||
loadFailure: { | ||
id: 'learn.course.load.failure', | ||
defaultMessage: 'There was an error loading this course.', | ||
description: 'Message when a course fails to load', | ||
}, | ||
loadingHonorCode: { | ||
id: 'learn.loading.honor.codk', | ||
defaultMessage: 'Loading honor code messaging...', | ||
description: 'Message shown when an interface about the honor code is being loaded', | ||
}, | ||
'learn.loading.learning.sequence': { | ||
loadingLockedContent: { | ||
id: 'learn.loading.content.lock', | ||
defaultMessage: 'Loading locked content messaging...', | ||
description: 'Message shown when an interface about locked content is being loaded', | ||
}, | ||
loadingSequence: { | ||
id: 'learn.loading.learning.sequence', | ||
defaultMessage: 'Loading learning sequence...', | ||
description: 'Message when learning sequence is being loaded', | ||
}, | ||
'learn.course.load.failure': { | ||
id: 'learn.course.load.failure', | ||
defaultMessage: 'There was an error loading this course.', | ||
description: 'Message when a course fails to load', | ||
}, | ||
'learn.sequence.no.content': { | ||
noContent: { | ||
id: 'learn.sequence.no.content', | ||
defaultMessage: 'There is no content here.', | ||
description: 'Message shown when there is no content to show a user inside a learning sequence.', | ||
}, | ||
'learn.header.h2.placeholder': { | ||
id: 'learn.header.h2.placeholder', | ||
defaultMessage: 'Level 2 headings may be created by course providers in the future.', | ||
description: 'Message spoken by a screenreader indicating that the h2 tag is a placeholder.', | ||
|
||
}, | ||
}); | ||
|
||
export default messages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters