diff --git a/src/course-rerun/hooks.jsx b/src/course-rerun/hooks.jsx
index 87fb97041f..d95102db97 100644
--- a/src/course-rerun/hooks.jsx
+++ b/src/course-rerun/hooks.jsx
@@ -1,13 +1,11 @@
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useIntl } from '@edx/frontend-platform/i18n';
-import { useNavigate } from 'react-router-dom';
import { RequestStatus } from '../data/constants';
import { updateSavingStatus } from '../generic/data/slice';
import {
getSavingStatus,
- getRedirectUrlObj,
getCourseRerunData,
getCourseData,
} from '../generic/data/selectors';
@@ -17,11 +15,9 @@ import { fetchStudioHomeData } from '../studio-home/data/thunks';
const useCourseRerun = (courseId) => {
const intl = useIntl();
const dispatch = useDispatch();
- const navigate = useNavigate();
const savingStatus = useSelector(getSavingStatus);
const courseData = useSelector(getCourseData);
const courseRerunData = useSelector(getCourseRerunData);
- const redirectUrlObj = useSelector(getRedirectUrlObj);
const {
displayName = '',
@@ -46,10 +42,6 @@ const useCourseRerun = (courseId) => {
useEffect(() => {
if (savingStatus === RequestStatus.SUCCESSFUL) {
dispatch(updateSavingStatus({ status: '' }));
- const { url } = redirectUrlObj;
- if (url) {
- navigate('/home');
- }
}
}, [savingStatus]);
diff --git a/src/generic/create-or-rerun-course/CreateOrRerunCourseForm.test.jsx b/src/generic/create-or-rerun-course/CreateOrRerunCourseForm.test.jsx
index 0383b789a7..b7a2127e3f 100644
--- a/src/generic/create-or-rerun-course/CreateOrRerunCourseForm.test.jsx
+++ b/src/generic/create-or-rerun-course/CreateOrRerunCourseForm.test.jsx
@@ -27,11 +27,14 @@ import messages from './messages';
import { CreateOrRerunCourseForm } from '.';
import { initialState } from './factories/mockApiResponses';
+const mockedUsedNavigate = jest.fn();
+
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useParams: () => ({
courseId: 'course-id-mock',
}),
+ useNavigate: () => mockedUsedNavigate,
}));
let axiosMock;
@@ -134,8 +137,6 @@ describe('', () => {
});
describe('handleOnClickCreate', () => {
- delete window.location;
- window.location = { assign: jest.fn() };
it('should call window.location.assign with url', async () => {
render();
await mockStore();
@@ -156,7 +157,7 @@ describe('', () => {
await axiosMock.onPost(getCreateOrRerunCourseUrl()).reply(200, { url });
await executeThunk(updateCreateOrRerunCourseQuery({ org: 'testX', run: 'some' }), store.dispatch);
- expect(window.location.assign).toHaveBeenCalledWith(`${process.env.STUDIO_BASE_URL}${url}`);
+ expect(mockedUsedNavigate).toHaveBeenCalledWith(url);
});
it('should call window.location.assign with url and destinationCourseKey', async () => {
render();
@@ -179,7 +180,7 @@ describe('', () => {
});
await executeThunk(updateCreateOrRerunCourseQuery({ org: 'testX', run: 'some' }), store.dispatch);
- expect(window.location.assign).toHaveBeenCalledWith(`${process.env.STUDIO_BASE_URL}${url}${destinationCourseKey}`);
+ expect(mockedUsedNavigate).toHaveBeenCalledWith(`${url}${destinationCourseKey}`);
});
});
diff --git a/src/generic/create-or-rerun-course/hooks.jsx b/src/generic/create-or-rerun-course/hooks.jsx
index c328fdd440..5bb744aa4a 100644
--- a/src/generic/create-or-rerun-course/hooks.jsx
+++ b/src/generic/create-or-rerun-course/hooks.jsx
@@ -1,9 +1,9 @@
import { useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
-import { getConfig } from '@edx/frontend-platform';
import { useIntl } from '@edx/frontend-platform/i18n';
import { useFormik } from 'formik';
import * as Yup from 'yup';
+import { useNavigate } from 'react-router-dom';
import { RequestStatus } from '../../data/constants';
import { getStudioHomeData } from '../../studio-home/data/selectors';
@@ -20,6 +20,7 @@ import messages from './messages';
const useCreateOrRerunCourse = (initialValues) => {
const intl = useIntl();
const dispatch = useDispatch();
+ const navigate = useNavigate();
const redirectUrlObj = useSelector(getRedirectUrlObj);
const createOrRerunCourseSavingStatus = useSelector(getSavingStatus);
const allOrganizations = useSelector(getOrganizations);
@@ -93,9 +94,9 @@ const useCreateOrRerunCourse = (initialValues) => {
// is in the destionationCourseKey attribute from the api.
if (url) {
if (destinationCourseKey) {
- window.location.assign(`${getConfig().STUDIO_BASE_URL}${url}${destinationCourseKey}`);
+ navigate(`${url}${destinationCourseKey}`);
} else {
- window.location.assign(`${getConfig().STUDIO_BASE_URL}${url}`);
+ navigate(url);
}
}
} else if (createOrRerunCourseSavingStatus === RequestStatus.FAILED) {