@@ -5,18 +5,20 @@ import PropTypes from 'prop-types';
5
5
import { Xpert } from '@edx/frontend-lib-learning-assistant' ;
6
6
import { injectIntl } from '@edx/frontend-platform/i18n' ;
7
7
8
+ import { useModel } from '../../../generic/model-store' ;
9
+
8
10
const Chat = ( {
9
11
enabled,
10
12
enrollmentMode,
11
13
isStaff,
12
14
courseId,
13
15
contentToolsEnabled,
14
16
unitId,
15
- validDates,
16
17
} ) => {
17
18
const {
18
19
activeAttempt, exam,
19
20
} = useSelector ( state => state . specialExams ) ;
21
+ const course = useModel ( 'coursewareMeta' , courseId ) ;
20
22
21
23
const VERIFIED_MODES = [
22
24
'professional' ,
@@ -35,10 +37,27 @@ const Chat = ({
35
37
&& [ ...VERIFIED_MODES ] . some ( mode => mode === enrollmentMode )
36
38
) ;
37
39
40
+ const validDates = ( ) => {
41
+ const date = new Date ( ) ;
42
+ const utcDate = date . toISOString ( ) ;
43
+
44
+ const enrollmentStartDate = course . enrollmentStart || utcDate ;
45
+ const startDate = course . start || enrollmentStartDate ;
46
+ const enrollmentEndDate = course . enrollmentEnd || utcDate ;
47
+ const endDate = course . end || enrollmentEndDate ;
48
+
49
+ return (
50
+ startDate <= enrollmentStartDate
51
+ && enrollmentStartDate <= utcDate
52
+ && utcDate <= enrollmentEndDate
53
+ && enrollmentEndDate <= endDate
54
+ ) ;
55
+ } ;
56
+
38
57
const shouldDisplayChat = (
39
58
enabled
40
59
&& ( hasVerifiedEnrollment || isStaff ) // display only to verified learners or staff
41
- && validDates
60
+ && validDates ( )
42
61
// it is necessary to check both whether the user is in an exam, and whether or not they are viewing an exam
43
62
// this will prevent the learner from interacting with the tool at any point of the exam flow, even at the
44
63
// entrance interstitial.
@@ -63,7 +82,6 @@ Chat.propTypes = {
63
82
courseId : PropTypes . string . isRequired ,
64
83
contentToolsEnabled : PropTypes . bool . isRequired ,
65
84
unitId : PropTypes . string . isRequired ,
66
- validDates : PropTypes . bool . isRequired ,
67
85
} ;
68
86
69
87
Chat . defaultProps = {
0 commit comments