Skip to content

Commit

Permalink
feat: Call LearningAssistantAuditTrial endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ilee2u committed Nov 25, 2024
1 parent 455345e commit c702ca1
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ async function fetchLearningAssistantEnabled(courseId) {
return data;
}


Check failure on line 33 in src/data/api.js

View workflow job for this annotation

GitHub Actions / test

More than 1 blank line not allowed
async function fetchLearningAssistantAuditTrial(userId) {
// TODO: Insert correct URL once get endpoint is implemented.
const url = new URL(`${getConfig().CHAT_RESPONSE_URL}/${userId}/`);

const { data } = await getAuthenticatedHttpClient().get(url.href);
return data;
}


Check failure on line 42 in src/data/api.js

View workflow job for this annotation

GitHub Actions / test

More than 1 blank line not allowed
async function fetchLearningAssistantAuditTrial(userId) {

Check failure on line 43 in src/data/api.js

View workflow job for this annotation

GitHub Actions / test

'fetchLearningAssistantAuditTrial' is already defined
// TODO: Insert correct URL once get endpoint is implemented.
const url = new URL(`${getConfig().CHAT_RESPONSE_URL}/${userId}/`);

const { data } = await getAuthenticatedHttpClient().get(url.href);
// TODO: Extract below values from data:
// Whether or not a trial exists

Check failure on line 49 in src/data/api.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 2 spaces but found 4
// Days remaining in trial

Check failure on line 50 in src/data/api.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 2 spaces but found 4
// When trial was created

Check failure on line 51 in src/data/api.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 2 spaces but found 4
return data;
}

async function fetchLearningAssistantMessageHistory(courseId) {
const url = new URL(`${getConfig().CHAT_RESPONSE_URL}/${courseId}/history`);

Expand All @@ -39,6 +61,7 @@ async function fetchLearningAssistantMessageHistory(courseId) {

export {
fetchChatResponse,
fetchLearningAssistantAuditTrial,
fetchLearningAssistantEnabled,
fetchLearningAssistantMessageHistory,
};
8 changes: 8 additions & 0 deletions src/data/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export const initialState = {
disclosureAcknowledged: false,
sidebarIsOpen: false,
isEnabled: false,
auditTrial: {
trialExists: false,
daysRemaining: 0,
trialCreated: null, // TODO: what do we use for a datetime value here?

Check failure on line 17 in src/data/slice.js

View workflow job for this annotation

GitHub Actions / test

Multiple spaces found before '// TODO: what ...'
},
};

export const learningAssistantSlice = createSlice({
Expand Down Expand Up @@ -44,6 +49,9 @@ export const learningAssistantSlice = createSlice({
setIsEnabled: (state, { payload }) => {
state.isEnabled = payload;
},
setAuditTrial: (state, { payload }) => {
state.auditTrial = payload;
},
},
});

Expand Down
14 changes: 13 additions & 1 deletion src/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { sendTrackEvent } from '@edx/frontend-platform/analytics';
import { getAuthenticatedUser } from '@edx/frontend-platform/auth';

import trackChatBotMessageOptimizely from '../utils/optimizelyExperiment';
import { fetchChatResponse, fetchLearningAssistantMessageHistory, fetchLearningAssistantEnabled } from './api';
import { fetchChatResponse, fetchLearningAssistantMessageHistory, fetchLearningAssistantEnabled, fetchLearningAssistantAuditTrial } from './api';

Check failure on line 5 in src/data/thunks.js

View workflow job for this annotation

GitHub Actions / test

Expected a line break after this opening brace

Check failure on line 5 in src/data/thunks.js

View workflow job for this annotation

GitHub Actions / test

Expected a line break before this closing brace
import {
setCurrentMessage,
clearCurrentMessage,
Expand All @@ -13,6 +13,7 @@ import {
setDisclosureAcknowledged,
setSidebarIsOpen,
setIsEnabled,
setAuditTrial,

Check failure on line 16 in src/data/thunks.js

View workflow job for this annotation

GitHub Actions / test

setAuditTrial not found in './slice'
} from './slice';
import { OPTIMIZELY_PROMPT_EXPERIMENT_KEY } from './optimizely';

Expand Down Expand Up @@ -134,3 +135,14 @@ export function getIsEnabled(courseId) {
}
};
}

export function getIsAuditTrial(userId) {
return async (dispatch) => {
try {
const data = await fetchLearningAssistantAuditTrial(userId);
dispatch(setAuditTrial(data.enabled));
} catch (error) {
dispatch(setApiError());
}
};
}
12 changes: 11 additions & 1 deletion src/widgets/Xpert.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';

import { updateSidebarIsOpen, getIsEnabled } from '../data/thunks';
import { updateSidebarIsOpen, getIsEnabled, getIsAuditTrial } from '../data/thunks';
import ToggleXpert from '../components/ToggleXpertButton';
import Sidebar from '../components/Sidebar';
import { ExperimentsProvider } from '../experiments';
Expand All @@ -15,6 +15,12 @@ const Xpert = ({ courseId, contentToolsEnabled, unitId }) => {
const {
isEnabled,
sidebarIsOpen,
// TODO: How do we plan to use this value to gate things?
// i.e. how to use values such as:
// auditTrial.trialExists
// auditTrial.daysRemaining
// auditTrial.trialCreated
auditTrial,
} = useSelector(state => state.learningAssistant);

const setSidebarIsOpen = (isOpen) => {
Expand All @@ -25,6 +31,10 @@ const Xpert = ({ courseId, contentToolsEnabled, unitId }) => {
dispatch(getIsEnabled(courseId));
}, [dispatch, courseId]);

useEffect(() => {
dispatch(getIsAuditTrial(userId));
}, [dispatch, userId]);

return isEnabled ? (
<ExperimentsProvider>
<>
Expand Down

0 comments on commit c702ca1

Please sign in to comment.