Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Call LearningAssistantSummary endpoint #68

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/components/Sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const Sidebar = ({
isOpen,
setIsOpen,
unitId,
}) => {
auditTrialNotExpired
&, > {
const {
apiError,
disclosureAcknowledged,
Expand Down Expand Up @@ -98,7 +99,10 @@ const Sidebar = ({
</div>
)
}
{getMessageForm()}
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this only happening in the case where the user is an audit learner? In other words, where are we handling the logic to check if the learner is audit or verified (since the experience will be different).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following up from a standup discussion we had, I removed the gating here as that functionality will be implemented in another ticket.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great!

auditTrialNotExpired
&& getMessageForm()
}
</div>
);

Expand Down
9 changes: 9 additions & 0 deletions src/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,17 @@ async function fetchLearningAssistantMessageHistory(courseId) {
return data;
}

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

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

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,10 @@
disclosureAcknowledged: false,
sidebarIsOpen: false,
isEnabled: false,
auditTrial: {
startDate: 0,
expirationDate: null, // TODO: what do we use for a datetime value here?

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

View workflow job for this annotation

GitHub Actions / test

Multiple spaces found before '// TODO: what ...'
varshamenon4 marked this conversation as resolved.
Show resolved Hide resolved
},
};

export const learningAssistantSlice = createSlice({
Expand Down Expand Up @@ -44,6 +48,10 @@
setIsEnabled: (state, { payload }) => {
state.isEnabled = payload;
},
setAuditTrial: (state, { payload }) => {
state.auditTrial.startDate = payload.start_date;
state.auditTrial.expirationDate = payload.expiration_date;
},
},
});

Expand Down
16 changes: 15 additions & 1 deletion src/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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 @@
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,16 @@
}
};
}

export function getAuditTrial(userId) {
return async (dispatch) => {
try {
const data = await fetchLearningAssistantAuditTrial(userId);
if (!_.isEmpty(data)) { // If returned data is not empty

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

View workflow job for this annotation

GitHub Actions / test

'_' is not defined

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

View workflow job for this annotation

GitHub Actions / test

Multiple spaces found before '// If returned...'
dispatch(setAuditTrial(data));
}
} catch (error) {
dispatch(setApiError());
}
};
}
16 changes: 15 additions & 1 deletion src/widgets/Xpert.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';

import { updateSidebarIsOpen, getIsEnabled } from '../data/thunks';
import { updateSidebarIsOpen, getIsEnabled, getAuditTrial } from '../data/thunks';
import ToggleXpert from '../components/ToggleXpertButton';
import Sidebar from '../components/Sidebar';

Check failure on line 7 in src/widgets/Xpert.jsx

View workflow job for this annotation

GitHub Actions / test

Parse errors in imported module '../components/Sidebar': ',' expected. (24:2)

Check failure on line 7 in src/widgets/Xpert.jsx

View workflow job for this annotation

GitHub Actions / test

Parse errors in imported module '../components/Sidebar': ',' expected. (24:2)
import { ExperimentsProvider } from '../experiments';
import { useMessageHistory } from '../hooks';

Expand All @@ -15,6 +15,7 @@
const {
isEnabled,
sidebarIsOpen,
auditTrial,
} = useSelector(state => state.learningAssistant);

const setSidebarIsOpen = (isOpen) => {
Expand All @@ -25,6 +26,18 @@
dispatch(getIsEnabled(courseId));
}, [dispatch, courseId]);

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

const isAuditTrialNotExpired = () => {
const auditTrialExpired = (Date.now() - auditTrial.expirationDate) > 0;
if (auditTrialExpired) {
return true
}
return false
}

return isEnabled ? (
<ExperimentsProvider>
<>
Expand All @@ -39,6 +52,7 @@
isOpen={sidebarIsOpen}
setIsOpen={setSidebarIsOpen}
unitId={unitId}
auditTrialNotExpired={isAuditTrialNotExpired}
/>
</>
</ExperimentsProvider>
Expand Down
Loading