Skip to content

Commit

Permalink
feat: Unsubscribe audit users from goal remindners on the course exit…
Browse files Browse the repository at this point in the history
… page (openedx#660)
  • Loading branch information
MatthewPiatetsky authored Oct 5, 2021
1 parent dae0c89 commit 55b3396
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/courseware/course/course-exit/CourseExit.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';

import { getConfig } from '@edx/frontend-platform';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
Expand All @@ -11,13 +11,15 @@ import CourseInProgress from './CourseInProgress';
import CourseNonPassing from './CourseNonPassing';
import { COURSE_EXIT_MODES, getCourseExitMode } from './utils';
import messages from './messages';
import { unsubscribeFromGoalReminders } from './data/thunks';

import { useModel } from '../../../generic/model-store';

function CourseExit({ intl }) {
const { courseId } = useSelector(state => state.courseware);
const {
certificateData,
enrollmentMode,
hasScheduledContent,
isEnrolled,
userHasPassingGrade,
Expand All @@ -32,6 +34,15 @@ function CourseExit({ intl }) {
courseExitPageIsActive,
);

// Audit users cannot fully complete a course, so we will
// unsubscribe them from goal reminders once they reach the course exit page
// to avoid spamming them with goal reminder emails
if (enrollmentMode === 'audit') {
useEffect(() => {
unsubscribeFromGoalReminders(courseId);
}, []);
}

let body = null;
if (mode === COURSE_EXIT_MODES.nonPassing) {
body = (<CourseNonPassing />);
Expand Down
15 changes: 15 additions & 0 deletions src/courseware/course/course-exit/CourseExit.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import MockAdapter from 'axios-mock-adapter';
import { Factory } from 'rosie';
import { getConfig } from '@edx/frontend-platform';
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { waitFor } from '@testing-library/react';

import { fetchCourse } from '../../data';
import { buildSimpleCourseBlocks } from '../../../shared/data/__factories__/courseBlocks.factory';
Expand Down Expand Up @@ -377,4 +378,18 @@ describe('Course Exit Pages', () => {
expect(screen.getByRole('link', { name: 'View course schedule' })).toBeInTheDocument();
});
});

it('unsubscribes the user when loading the course exit page', async () => {
setMetadata({
enrollment: {
mode: 'audit',
},
});
await fetchAndRender(<CourseExit />);
const url = `${getConfig().LMS_BASE_URL}/api/course_home/save_course_goal`;
await waitFor(() => {
expect(axiosMock.history.post[0].url).toMatch(url);
expect(axiosMock.history.post[0].data).toMatch(`{"course_id":"${defaultMetadata.id}","subscribed_to_reminders":false}`);
});
});
});
10 changes: 9 additions & 1 deletion src/courseware/course/course-exit/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function filterRecommendationsList(
));
}

export default async function getCourseRecommendations(courseKey) {
export async function getCourseRecommendations(courseKey) {
const discoveryApiUrl = getConfig().DISCOVERY_API_BASE_URL;
if (!discoveryApiUrl) {
return [];
Expand All @@ -36,3 +36,11 @@ export default async function getCourseRecommendations(courseKey) {
]);
return filterRecommendationsList(camelCaseObject(recommendationsResponse), camelCaseObject(enrollmentsResponse));
}

export async function postUnsubscribeFromGoalReminders(courseId) {
const url = new URL(`${getConfig().LMS_BASE_URL}/api/course_home/save_course_goal`);
return getAuthenticatedHttpClient().post(url.href, {
course_id: courseId,
subscribed_to_reminders: false,
});
}
9 changes: 8 additions & 1 deletion src/courseware/course/course-exit/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
fetchCourseRecommendationsRequest,
fetchCourseRecommendationsSuccess,
} from './slice';
import getCourseRecommendations from './api';
import {
getCourseRecommendations,
postUnsubscribeFromGoalReminders,
} from './api';
import { updateModel } from '../../../../generic/model-store';

export default function fetchCourseRecommendations(courseKey, courseId) {
Expand All @@ -27,3 +30,7 @@ export default function fetchCourseRecommendations(courseKey, courseId) {
}
};
}

export async function unsubscribeFromGoalReminders(courseId, daysPerWeek, subscribedToReminders) {
return postUnsubscribeFromGoalReminders(courseId, daysPerWeek, subscribedToReminders);
}

0 comments on commit 55b3396

Please sign in to comment.