@@ -3,9 +3,10 @@ import { useSelector } from 'react-redux';
33import PropTypes from 'prop-types' ;
44
55import { Xpert } from '@edx/frontend-lib-learning-assistant' ;
6+ import { getConfig } from '@edx/frontend-platform' ;
67import { injectIntl } from '@edx/frontend-platform/i18n' ;
78
8- import { VERIFIED_MODES } from '@src/constants' ;
9+ import { AUDIT_MODES , VERIFIED_MODES } from '@src/constants' ;
910import { useModel } from '../../../generic/model-store' ;
1011
1112const Chat = ( {
@@ -21,40 +22,64 @@ const Chat = ({
2122 } = useSelector ( state => state . specialExams ) ;
2223 const course = useModel ( 'coursewareMeta' , courseId ) ;
2324
25+ const {
26+ accessExpiration,
27+ start,
28+ end,
29+ } = course ;
30+
2431 const hasVerifiedEnrollment = (
2532 enrollmentMode !== null
2633 && enrollmentMode !== undefined
2734 && VERIFIED_MODES . includes ( enrollmentMode )
2835 ) ;
2936
37+ // audit learners should only have access if the ENABLE_XPERT_AUDIT setting is true
38+ const hasAuditEnrollmentAndAccess = (
39+ enrollmentMode !== null
40+ && enrollmentMode !== undefined
41+ && AUDIT_MODES . includes ( enrollmentMode )
42+ && getConfig ( ) . ENABLE_XPERT_AUDIT
43+ ) ;
44+
3045 const validDates = ( ) => {
3146 const date = new Date ( ) ;
3247 const utcDate = date . toISOString ( ) ;
3348
34- const startDate = course . start || utcDate ;
35- const endDate = course . end || utcDate ;
49+ const startDate = start || utcDate ;
50+ const endDate = end || utcDate ;
51+ const accessExpirationDate = accessExpiration && accessExpiration . expirationDate
52+ ? accessExpiration . expirationDate : utcDate ;
3653
3754 return (
3855 startDate <= utcDate
3956 && utcDate <= endDate
57+ && ( hasAuditEnrollmentAndAccess ? utcDate <= accessExpirationDate : true )
4058 ) ;
4159 } ;
4260
4361 const shouldDisplayChat = (
4462 enabled
45- && ( hasVerifiedEnrollment || isStaff ) // display only to verified learners or staff
63+ && ( hasVerifiedEnrollment || isStaff || hasAuditEnrollmentAndAccess )
4664 && validDates ( )
4765 // it is necessary to check both whether the user is in an exam, and whether or not they are viewing an exam
4866 // this will prevent the learner from interacting with the tool at any point of the exam flow, even at the
4967 // entrance interstitial.
5068 && ! ( activeAttempt ?. attempt_id || exam ?. id )
5169 ) ;
5270
71+ const isUpgradeEligible = ! hasVerifiedEnrollment && ! isStaff ;
72+
5373 return (
5474 < >
5575 { /* Use a portal to ensure that component overlay does not compete with learning MFE styles. */ }
5676 { shouldDisplayChat && ( createPortal (
57- < Xpert courseId = { courseId } contentToolsEnabled = { contentToolsEnabled } unitId = { unitId } /> ,
77+ < Xpert
78+ courseId = { courseId }
79+ contentToolsEnabled = { contentToolsEnabled }
80+ unitId = { unitId }
81+ isUpgradeEligible = { isUpgradeEligible }
82+ /> ,
5883 document . body ,
5984 ) ) }
6085 </ >
0 commit comments