From 8aee3408cc8896b1ae4259b6d2ded26629db85a9 Mon Sep 17 00:00:00 2001 From: Waheed Ahmed Date: Thu, 3 Jun 2021 13:00:54 +0500 Subject: [PATCH] fix: welcome page redirection (#309) * fix: welcome page redirection Redirect ot finish auth URL if present upon clicking submit or skip on welcome page. * Update RedirectLogistration.jsx nit --- .../RedirectLogistration.jsx | 15 +++++++---- src/welcome/WelcomePage.jsx | 27 ++++++++----------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/common-components/RedirectLogistration.jsx b/src/common-components/RedirectLogistration.jsx index 82cb0274..e5f13d56 100644 --- a/src/common-components/RedirectLogistration.jsx +++ b/src/common-components/RedirectLogistration.jsx @@ -11,6 +11,7 @@ function RedirectLogistration(props) { const { finishAuthUrl, redirectUrl, redirectToWelcomePage, success, } = props; + let finalRedirectUrl = ''; if (success) { // If we're in a third party auth pipeline, we must complete the pipeline @@ -18,15 +19,19 @@ function RedirectLogistration(props) { // Note: For multiple enterprise use case, we need to make sure that user first visits the // enterprise selection page and then complete the auth workflow if (finishAuthUrl && !redirectUrl.includes(finishAuthUrl)) { - window.location.href = getConfig().LMS_BASE_URL + finishAuthUrl; - } else if (redirectToWelcomePage) { - const welcomeProps = { redirectUrl, success }; - return ; + finalRedirectUrl = getConfig().LMS_BASE_URL + finishAuthUrl; } else { + finalRedirectUrl = redirectUrl; + } + + if (redirectToWelcomePage) { // use this component to redirect WelcomePage after successful registration // return ; - window.location.href = redirectUrl; + const registrationResult = { redirectUrl: finalRedirectUrl, success }; + return ; } + + window.location.href = finalRedirectUrl; } return <>; } diff --git a/src/welcome/WelcomePage.jsx b/src/welcome/WelcomePage.jsx index 7f126244..2ee02125 100644 --- a/src/welcome/WelcomePage.jsx +++ b/src/welcome/WelcomePage.jsx @@ -1,6 +1,5 @@ import React, { useState, useEffect } from 'react'; import PropTypes from 'prop-types'; -import { connect } from 'react-redux'; import { Helmet } from 'react-helmet'; import { getConfig } from '@edx/frontend-platform'; @@ -17,12 +16,12 @@ import { import messages from './messages'; import { EDUCATION_LEVELS, GENDER_OPTIONS, YEAR_OF_BIRTH_OPTIONS } from '../register/data/constants'; -import { registrationRequestSelector } from '../register/data/selectors'; import { AuthnValidationFormGroup } from '../common-components'; import { DEFAULT_REDIRECT_URL } from '../data/constants'; const WelcomePage = (props) => { - const { intl, registrationResult } = props; + const { intl } = props; + const [registrationResult, setRegistrationResult] = useState({}); const [values, setValues] = useState({}); const [ready, setReady] = useState(false); const DASHBOARD_URL = getConfig().LMS_BASE_URL.concat(DEFAULT_REDIRECT_URL); @@ -33,11 +32,15 @@ const WelcomePage = (props) => { setReady(true); }); }); + + if (props.location.state && props.location.state.registrationResult) { + setRegistrationResult(props.location.state.registrationResult); + } }, []); const authenticatedUser = getAuthenticatedUser(); - if (!registrationResult.redirectUrl) { + if (!props.location.state || !props.location.state.registrationResult) { global.location.assign(DASHBOARD_URL); return null; } @@ -188,21 +191,13 @@ const WelcomePage = (props) => { WelcomePage.propTypes = { intl: intlShape.isRequired, - registrationResult: PropTypes.shape({ - redirectUrl: PropTypes.string, - success: PropTypes.bool, + location: PropTypes.shape({ + state: PropTypes.object, }), }; WelcomePage.defaultProps = { - registrationResult: {}, + location: { state: {} }, }; -const mapStateToProps = state => { - const registrationResult = registrationRequestSelector(state); - return { registrationResult }; -}; - -export default connect( - mapStateToProps, -)(injectIntl(WelcomePage)); +export default (injectIntl(WelcomePage));