Skip to content

Commit fa32637

Browse files
committed
feat: update chat component to use PluginSlot and simplify logic
1 parent f91af21 commit fa32637

File tree

4 files changed

+77
-324
lines changed

4 files changed

+77
-324
lines changed

.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,3 @@ OPTIMIZELY_FULL_STACK_SDK_KEY=''
5353
SHOW_UNGRADED_ASSIGNMENT_PROGRESS=''
5454
# Fallback in local style files
5555
PARAGON_THEME_URLS={}
56-
FEATURE_ENABLE_CHAT_V2_ENDPOINT=''

.env.development

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ NODE_ENV='development'
55

66
ACCESS_TOKEN_COOKIE_NAME='edx-jwt-cookie-header-payload'
77
APP_ID='learning'
8-
BASE_URL='http://localhost:2000'
8+
BASE_URL='http://localhost:2010'
99
CONTACT_URL='http://localhost:18000/contact'
1010
CREDENTIALS_BASE_URL='http://localhost:18150'
1111
CREDIT_HELP_LINK_URL='https://help.edx.org/edxlearner/s/article/Can-I-receive-college-credit-or-credit-hours-for-my-course'
@@ -31,7 +31,7 @@ LOGO_WHITE_URL=https://edx-cdn.org/v3/default/logo-white.svg
3131
LEGACY_THEME_NAME=''
3232
MARKETING_SITE_BASE_URL='http://localhost:18000'
3333
ORDER_HISTORY_URL='http://localhost:1996/orders'
34-
PORT=2000
34+
PORT=2010
3535
PROCTORED_EXAM_FAQ_URL=''
3636
PROCTORED_EXAM_RULES_URL=''
3737
REFRESH_ACCESS_TOKEN_ENDPOINT='http://localhost:18000/login_refresh'
@@ -53,6 +53,6 @@ CHAT_RESPONSE_URL='http://localhost:18000/api/learning_assistant/v1/course_id'
5353
PRIVACY_POLICY_URL='http://localhost:18000/privacy'
5454
OPTIMIZELY_FULL_STACK_SDK_KEY=''
5555
SHOW_UNGRADED_ASSIGNMENT_PROGRESS=''
56+
ENABLE_XPERT_AUDIT='true'
5657
# Fallback in local style files
5758
PARAGON_THEME_URLS={}
58-
FEATURE_ENABLE_CHAT_V2_ENDPOINT='false'

src/courseware/course/chat/Chat.jsx

Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,37 @@
11
import { createPortal } from 'react-dom';
2-
import { useSelector } from 'react-redux';
32
import PropTypes from 'prop-types';
4-
5-
import { Xpert } from '@edx/frontend-lib-learning-assistant';
6-
import { getConfig } from '@edx/frontend-platform';
7-
8-
import { ALLOW_UPSELL_MODES, VERIFIED_MODES } from '@src/constants';
9-
import { useModel } from '../../../generic/model-store';
3+
import { PluginSlot } from '@openedx/frontend-plugin-framework';
4+
import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
105

116
const Chat = ({
127
enabled,
138
enrollmentMode,
149
isStaff,
1510
courseId,
16-
contentToolsEnabled,
1711
unitId,
1812
}) => {
19-
const {
20-
activeAttempt, exam,
21-
} = useSelector(state => state.specialExams);
22-
const course = useModel('coursewareMeta', courseId);
23-
24-
// If is disabled or taking an exam, we don't show the chat.
25-
if (!enabled || activeAttempt?.attempt_id || exam?.id) { return null; }
26-
27-
// If is not staff and doesn't have an enrollment, we don't show the chat.
28-
if (!isStaff && !enrollmentMode) { return null; }
29-
30-
const verifiedMode = VERIFIED_MODES.includes(enrollmentMode); // Enrollment verified
31-
const auditMode = (
32-
!isStaff
33-
&& !verifiedMode
34-
&& ALLOW_UPSELL_MODES.includes(enrollmentMode) // Can upgrade course
35-
&& getConfig().ENABLE_XPERT_AUDIT
36-
);
37-
// If user has no access, we don't show the chat.
38-
if (!isStaff && !(verifiedMode || auditMode)) { return null; }
39-
40-
// Date validation
41-
const {
42-
accessExpiration,
43-
start,
44-
end,
45-
} = course;
46-
47-
const utcDate = (new Date()).toISOString();
48-
const expiration = accessExpiration?.expirationDate || utcDate;
49-
const validDate = (
50-
(start ? start <= utcDate : true)
51-
&& (end ? end >= utcDate : true)
52-
&& (auditMode ? expiration >= utcDate : true)
53-
);
54-
// If date is invalid, we don't show the chat.
55-
if (!validDate) { return null; }
56-
57-
// Use a portal to ensure that component overlay does not compete with learning MFE styles.
13+
const { userId } = getAuthenticatedUser();
14+
15+
// If chat is disabled, don't show anything
16+
if (!enabled) {
17+
return null;
18+
}
19+
20+
// Provide minimal, generic context - no feature-specific flags
21+
const pluginContext = {
22+
courseId,
23+
unitId,
24+
userId,
25+
isStaff,
26+
enrollmentMode,
27+
};
28+
29+
// Use generic plugin slot ID (location-based, not feature-specific)
30+
// Plugins will query their own requirements from Redux/config
5831
return createPortal(
59-
<Xpert
60-
courseId={courseId}
61-
contentToolsEnabled={contentToolsEnabled}
62-
unitId={unitId}
63-
isUpgradeEligible={auditMode}
32+
<PluginSlot
33+
id="learner_tools_slot"
34+
pluginProps={pluginContext}
6435
/>,
6536
document.body,
6637
);
@@ -71,7 +42,6 @@ Chat.propTypes = {
7142
enabled: PropTypes.bool.isRequired,
7243
enrollmentMode: PropTypes.string,
7344
courseId: PropTypes.string.isRequired,
74-
contentToolsEnabled: PropTypes.bool.isRequired,
7545
unitId: PropTypes.string.isRequired,
7646
};
7747

0 commit comments

Comments
 (0)