From 444214b44ea6d63102c98d97f70011a4e465ba41 Mon Sep 17 00:00:00 2001 From: Bianca Severino Date: Thu, 19 Aug 2021 10:08:17 -0400 Subject: [PATCH] fix: update header loading state from old proctored exam settings (#184) --- .../ProctoredExamSettings.jsx | 10 +++++++++ .../ProctoredExamSettings.test.jsx | 17 ++++++++++----- src/proctored-exam-settings/data/thunks.js | 21 +++++++++++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 src/proctored-exam-settings/data/thunks.js diff --git a/src/proctored-exam-settings/ProctoredExamSettings.jsx b/src/proctored-exam-settings/ProctoredExamSettings.jsx index 02126b94d..9a2790c47 100644 --- a/src/proctored-exam-settings/ProctoredExamSettings.jsx +++ b/src/proctored-exam-settings/ProctoredExamSettings.jsx @@ -1,4 +1,5 @@ import React, { useState, useEffect, useRef } from 'react'; +import { useDispatch } from 'react-redux'; import PropTypes from 'prop-types'; import EmailValidator from 'email-validator'; import moment from 'moment'; @@ -18,8 +19,14 @@ import StudioApiService from '../data/services/StudioApiService'; import Loading from '../generic/Loading'; import ConnectionErrorAlert from '../generic/ConnectionErrorAlert'; import PermissionDeniedAlert from '../generic/PermissionDeniedAlert'; +import { + fetchExamSettingsFailure, + fetchExamSettingsPending, + fetchExamSettingsSuccess, +} from './data/thunks'; function ProctoredExamSettings({ courseId, intl }) { + const dispatch = useDispatch(); const [loading, setLoading] = useState(true); const [loaded, setLoaded] = useState(false); const [loadingConnectionError, setLoadingConnectionError] = useState(false); @@ -462,6 +469,7 @@ function ProctoredExamSettings({ courseId, intl }) { useEffect( () => { + dispatch(fetchExamSettingsPending(courseId)); StudioApiService.getProctoredExamSettingsData(courseId) .then( response => { @@ -484,6 +492,7 @@ function ProctoredExamSettings({ courseId, intl }) { setProctortrackEscalationEmail(proctoringEscalationEmail === null ? '' : proctoringEscalationEmail); setCreateZendeskTickets(proctoredExamSettings.create_zendesk_tickets); + dispatch(fetchExamSettingsSuccess(courseId)); }, ).catch( error => { @@ -495,6 +504,7 @@ function ProctoredExamSettings({ courseId, intl }) { setLoading(false); setLoaded(false); setSubmissionInProgress(false); + dispatch(fetchExamSettingsFailure(courseId)); }, ); }, [], diff --git a/src/proctored-exam-settings/ProctoredExamSettings.test.jsx b/src/proctored-exam-settings/ProctoredExamSettings.test.jsx index b697690de..134bc7996 100644 --- a/src/proctored-exam-settings/ProctoredExamSettings.test.jsx +++ b/src/proctored-exam-settings/ProctoredExamSettings.test.jsx @@ -7,8 +7,10 @@ import { IntlProvider, injectIntl } from '@edx/frontend-platform/i18n'; import MockAdapter from 'axios-mock-adapter'; import { initializeMockApp } from '@edx/frontend-platform'; import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; +import { AppProvider } from '@edx/frontend-platform/react'; import ProctoredExamSettings from './ProctoredExamSettings'; import StudioApiService from '../data/services/StudioApiService'; +import initializeStore from '../store'; const defaultProps = { courseId: 'course-v1%3AedX%2BDemoX%2BDemo_Course', @@ -16,12 +18,16 @@ const defaultProps = { const IntlProctoredExamSettings = injectIntl(ProctoredExamSettings); -const intlWrapper = children => ( - - {children} - -); let axiosMock; +let store; + +const intlWrapper = children => ( + + + {children} + + +); describe('ProctoredExamSettings', () => { afterEach(() => { @@ -39,6 +45,7 @@ describe('ProctoredExamSettings', () => { }, }); + store = initializeStore(); axiosMock = new MockAdapter(getAuthenticatedHttpClient()); axiosMock.onGet( diff --git a/src/proctored-exam-settings/data/thunks.js b/src/proctored-exam-settings/data/thunks.js new file mode 100644 index 000000000..ac32ad4ad --- /dev/null +++ b/src/proctored-exam-settings/data/thunks.js @@ -0,0 +1,21 @@ +import { RequestStatus } from '../../data/constants'; +import { updateLoadingStatus } from '../../pages-and-resources/data/slice'; + +/* eslint-disable import/prefer-default-export */ +export function fetchExamSettingsPending(courseId) { + return async (dispatch) => { + dispatch(updateLoadingStatus({ courseId, status: RequestStatus.IN_PROGRESS })); + }; +} + +export function fetchExamSettingsSuccess(courseId) { + return async (dispatch) => { + dispatch(updateLoadingStatus({ courseId, status: RequestStatus.SUCCESSFUL })); + }; +} + +export function fetchExamSettingsFailure(courseId) { + return async (dispatch) => { + dispatch(updateLoadingStatus({ courseId, status: RequestStatus.FAILED })); + }; +}