From 9d487d7b617891b5f92cdd418e673dac6b9becd1 Mon Sep 17 00:00:00 2001 From: Syed Sajjad Hussain Shah <52817156+syedsajjadkazmii@users.noreply.github.com> Date: Mon, 10 Apr 2023 12:36:40 +0500 Subject: [PATCH] fix: render tpa pipeline error from django messages on mfe (#829) VAN-1339 Co-authored-by: Syed Sajjad Hussain Shah --- src/common-components/Logistration.jsx | 4 ++ .../RedirectLogistration.jsx | 3 - src/common-components/SocialAuthProviders.jsx | 8 +-- src/common-components/data/actions.js | 5 ++ src/common-components/data/reducers.js | 12 +++- .../data/tests/reducer.test.js | 38 +++++++++- .../tests/Logistration.test.jsx | 18 ++--- .../tests/SocialAuthProviders.test.jsx | 43 ------------ src/login/LoginFailure.jsx | 14 ++++ src/login/LoginPage.jsx | 13 +++- src/login/data/constants.js | 1 + src/login/messages.jsx | 7 ++ src/login/tests/LoginFailure.test.jsx | 23 ++++++ src/login/tests/LoginPage.test.jsx | 17 +++++ src/register/RegistrationFailure.jsx | 21 +++++- src/register/RegistrationPage.jsx | 14 ++-- src/register/data/constants.js | 1 + src/register/data/utils.js | 2 - src/register/messages.jsx | 7 ++ src/register/tests/RegistrationPage.test.jsx | 70 +++++++++++++++---- 20 files changed, 233 insertions(+), 88 deletions(-) diff --git a/src/common-components/Logistration.jsx b/src/common-components/Logistration.jsx index 9a31373f..cc8c1101 100644 --- a/src/common-components/Logistration.jsx +++ b/src/common-components/Logistration.jsx @@ -20,6 +20,7 @@ import { getTpaHint, getTpaProvider, updatePathWithQueryParams } from '../data/u import { LoginPage } from '../login'; import { RegistrationPage } from '../register'; import { backupRegistrationForm } from '../register/data/actions'; +import { clearThirdPartyAuthContextErrorMessage } from './data/actions'; import { tpaProvidersSelector, } from './data/selectors'; @@ -56,6 +57,7 @@ const Logistration = (props) => { const handleOnSelect = (tabKey) => { sendTrackEvent(`edx.bi.${tabKey.replace('/', '')}_form.toggled`, { category: 'user-engagement' }); + props.clearThirdPartyAuthContextErrorMessage(); if (tabKey === LOGIN_PAGE) { props.backupRegistrationForm(); } @@ -135,6 +137,7 @@ const Logistration = (props) => { Logistration.propTypes = { selectedPage: PropTypes.string, backupRegistrationForm: PropTypes.func.isRequired, + clearThirdPartyAuthContextErrorMessage: PropTypes.func.isRequired, tpaProviders: PropTypes.shape({ providers: PropTypes.arrayOf(PropTypes.shape({})), secondaryProviders: PropTypes.arrayOf(PropTypes.shape({})), @@ -160,5 +163,6 @@ export default connect( mapStateToProps, { backupRegistrationForm, + clearThirdPartyAuthContextErrorMessage, }, )(Logistration); diff --git a/src/common-components/RedirectLogistration.jsx b/src/common-components/RedirectLogistration.jsx index c9bc1e21..862845ca 100644 --- a/src/common-components/RedirectLogistration.jsx +++ b/src/common-components/RedirectLogistration.jsx @@ -21,9 +21,6 @@ const RedirectLogistration = (props) => { let finalRedirectUrl = ''; if (success) { - // After successful registeration remove the tpaHintedAuthentication flag from local storage if set - localStorage.removeItem('tpaHintedAuthentication'); - // If we're in a third party auth pipeline, we must complete the pipeline // once user has successfully logged in. Otherwise, redirect to the specified redirect url. // Note: For multiple enterprise use case, we need to make sure that user first visits the diff --git a/src/common-components/SocialAuthProviders.jsx b/src/common-components/SocialAuthProviders.jsx index c5cea3fc..9d80ea3d 100644 --- a/src/common-components/SocialAuthProviders.jsx +++ b/src/common-components/SocialAuthProviders.jsx @@ -13,13 +13,9 @@ const SocialAuthProviders = (props) => { const { formatMessage } = useIntl(); const { referrer, socialAuthProviders } = props; - function handleSubmit(e, skipRegistrationForm) { + function handleSubmit(e) { e.preventDefault(); - if (skipRegistrationForm) { - localStorage.setItem('tpaHintedAuthentication', 'true'); - } - const url = e.currentTarget.dataset.providerUrl; window.location.href = getConfig().LMS_BASE_URL + url; } @@ -31,7 +27,7 @@ const SocialAuthProviders = (props) => { type="button" className={`btn-social btn-${provider.id} ${index % 2 === 0 ? 'mr-3' : ''}`} data-provider-url={referrer === LOGIN_PAGE ? provider.loginUrl : provider.registerUrl} - onClick={(e) => handleSubmit(e, provider.skipRegistrationForm)} + onClick={handleSubmit} > {provider.iconImage ? (