Skip to content

Commit

Permalink
feat: update segment events
Browse files Browse the repository at this point in the history
  • Loading branch information
alangsto committed Aug 28, 2023
1 parent a567a46 commit 2124eac
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/components/Sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import React, { useRef, useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Send } from 'react-feather';
import PropTypes from 'prop-types';
import Disclosure from '../Disclosure';
import { sendTrackEvent } from '@edx/frontend-platform/analytics';
import { Button, Icon } from '@edx/paragon';
import { Close } from '@edx/paragon/icons';
import Disclosure from '../Disclosure';
import ChatBox from '../ChatBox';
import APIError from '../APIError';
import './Sidebar.scss';
Expand Down Expand Up @@ -82,13 +83,16 @@ const Sidebar = ({
const handleSubmitMessage = (event) => {
event.preventDefault();
if (currentMessage) {
dispatch(addChatMessage('user', currentMessage));
dispatch(addChatMessage('user', currentMessage, courseId));
dispatch(getChatResponse(courseId));
}
};

const handleClearMessages = () => {
dispatch(clearMessages());
sendTrackEvent('edx.ui.lms.learning_assistant.clear', {
course_id: courseId,
});
};

const getSidebar = () => (
Expand Down
1 change: 0 additions & 1 deletion src/components/ToggleXpertButton/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ChevronRight } from 'react-feather';
import PropTypes from 'prop-types';
import { sendTrackEvent } from '@edx/frontend-platform/analytics';
import { ReactComponent as NewXeySvg } from '../../assets/new_xey.svg';
Expand Down
9 changes: 7 additions & 2 deletions src/data/thunks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { sendTrackEvent } from '@edx/frontend-platform/analytics';
import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
import fetchChatResponse from './api';
import {
setCurrentMessage,
Expand All @@ -11,7 +12,7 @@ import {
setDisclosureAcknowledged,
} from './slice';

export function addChatMessage(role, content) {
export function addChatMessage(role, content, courseId) {
return (dispatch, getState) => {
const { messageList, conversationId } = getState().learningAssistant;

Expand All @@ -28,8 +29,12 @@ export function addChatMessage(role, content) {
dispatch(setMessageList({ messageList: updatedMessageList }));
dispatch(clearCurrentMessage());
dispatch(resetApiError());

const { userId } = getAuthenticatedUser();
sendTrackEvent('edx.ui.lms.learning_assistant.message', {
id: conversationId,
course_id: courseId,
user_id: userId,
timestamp: message.timestamp,
role: message.role,
content: message.content,
Expand All @@ -45,7 +50,7 @@ export function getChatResponse(courseId) {
try {
const message = await fetchChatResponse(courseId, messageList);
dispatch(setApiIsLoading(false));
dispatch(addChatMessage(message.role, message.content));
dispatch(addChatMessage(message.role, message.content, courseId));
} catch (error) {
dispatch(setApiError());
dispatch(setApiIsLoading(false));
Expand Down

0 comments on commit 2124eac

Please sign in to comment.