From c7b5bd579c370049e9d5e5d9377c4113d9805b62 Mon Sep 17 00:00:00 2001
From: Syed Ali Abbas Zaidi
<88369802+Syed-Ali-Abbas-Zaidi@users.noreply.github.com>
Date: Wed, 23 Aug 2023 18:21:29 +0500
Subject: [PATCH] refactor: remove history pacakge (#853)
* refactor: remove history pacakge
* chore: improve test coverage
---
src/account-settings/AccountSettingsPage.jsx | 24 ++++++------
src/account-settings/data/utils/sagaUtils.js | 5 +--
src/account-settings/hoc.jsx | 19 ++++++++++
src/account-settings/hoc.test.jsx | 38 +++++++++++++++++++
src/account-settings/site-language/actions.js | 3 +-
src/account-settings/site-language/sagas.js | 4 +-
.../tests/panels/SummaryPanel.test.jsx | 5 +--
.../NotificationPreferences.test.jsx | 24 +++++-------
8 files changed, 86 insertions(+), 36 deletions(-)
create mode 100644 src/account-settings/hoc.jsx
create mode 100644 src/account-settings/hoc.test.jsx
diff --git a/src/account-settings/AccountSettingsPage.jsx b/src/account-settings/AccountSettingsPage.jsx
index abdb807ae..e9ac1087d 100644
--- a/src/account-settings/AccountSettingsPage.jsx
+++ b/src/account-settings/AccountSettingsPage.jsx
@@ -1,5 +1,5 @@
import { AppContext } from '@edx/frontend-platform/react';
-import { getConfig, history, getQueryParameters } from '@edx/frontend-platform';
+import { getConfig, getQueryParameters } from '@edx/frontend-platform';
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
@@ -51,19 +51,13 @@ import { fetchSiteLanguages } from './site-language';
import CoachingToggle from './coaching/CoachingToggle';
import DemographicsSection from './demographics/DemographicsSection';
import { fetchCourseList } from '../notification-preferences/data/thunks';
+import { withLocation, withNavigate } from './hoc';
class AccountSettingsPage extends React.Component {
constructor(props, context) {
super(props, context);
- // If there is a "duplicate_provider" query parameter, that's the backend's
- // way of telling us that the provider account the user tried to link is already linked
- // to another user account on the platform. We use this to display a message to that effect,
- // and remove the parameter from the URL.
const duplicateTpaProvider = getQueryParameters().duplicate_provider;
- if (duplicateTpaProvider !== undefined) {
- history.replace(history.location.pathname);
- }
this.state = {
duplicateTpaProvider,
};
@@ -82,7 +76,7 @@ class AccountSettingsPage extends React.Component {
componentDidMount() {
this.props.fetchCourseList();
this.props.fetchSettings();
- this.props.fetchSiteLanguages();
+ this.props.fetchSiteLanguages(this.props.navigate);
sendTrackingLogEvent('edx.user.settings.viewed', {
page: 'account',
visibility: null,
@@ -202,6 +196,12 @@ class AccountSettingsPage extends React.Component {
return null;
}
+ // If there is a "duplicate_provider" query parameter, that's the backend's
+ // way of telling us that the provider account the user tried to link is already linked
+ // to another user account on the platform. We use this to display a message to that effect,
+ // and remove the parameter from the URL.
+ this.props.navigate(this.props.location, { replace: true });
+
return (