Skip to content

Commit

Permalink
fix: fix login nudge issue
Browse files Browse the repository at this point in the history
Description:
Fix password nudge case
VAN-2008
  • Loading branch information
Ahtesham Quraish authored and ahtesham-quraish committed Jul 22, 2024
1 parent 18c33b7 commit 3d04e8d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/base-container/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { ModalDialog } from '@openedx/paragon';
import classNames from 'classnames';
import PropTypes from 'prop-types';

import { useDispatch } from '../data/storeHooks';
import { FORGOT_PASSWORD_FORM } from '../data/constants';
import { useDispatch, useSelector } from '../data/storeHooks';
import { deleteQueryParams } from '../data/utils';
import { NUDGE_PASSWORD_CHANGE } from '../forms/login-popup/data/constants';
import { loginErrorClear } from '../forms/login-popup/data/reducers';
import { clearAllRegistrationErrors } from '../forms/registration-popup/data/reducers';
import { forgotPasswordClearStatus } from '../forms/reset-password-popup/forgot-password/data/reducers';
Expand All @@ -28,10 +30,19 @@ const BaseContainer = ({
hasCloseButton = true,
isOpen,
size = 'lg',
currentForm,
}) => {
const dispatch = useDispatch();

const loginErrorResult = useSelector(state => state.login.loginError);
const loginErrorCode = useSelector(state => state.login.loginError?.errorCode);

const handleOnClose = () => {
if (loginErrorCode === NUDGE_PASSWORD_CHANGE
&& loginErrorResult.redirectUrl
&& currentForm === FORGOT_PASSWORD_FORM) {
window.location.href = loginErrorResult.redirectUrl;
}
deleteQueryParams(['authMode', 'tpa_hint', 'password_reset_token', 'track']);
dispatch(forgotPasswordClearStatus());
dispatch(loginErrorClear());
Expand Down Expand Up @@ -70,6 +81,7 @@ BaseContainer.propTypes = {
close: PropTypes.func.isRequired,
size: PropTypes.string,
hasCloseButton: PropTypes.bool,
currentForm: PropTypes.string.isRequired,
};

export default BaseContainer;
3 changes: 2 additions & 1 deletion src/forms/login-popup/data/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ export const loginSlice = createSlice({
errorCode,
email,
value,
redirectUrl,
} = payload;

const errorContext = { ...context, email, errorMessage: value };
state.loginError = { errorCode, errorContext };
state.loginError = { errorCode, errorContext, redirectUrl };
state.loginResult = {};
state.submitState = FAILURE_STATE;
},
Expand Down
3 changes: 2 additions & 1 deletion src/forms/reset-password-popup/forgot-password/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ const ForgotPasswordForm = () => {
<ForgotPasswordSuccess email={formFields.email} />
)}
<div className="text-center mt-4.5">
{loginErrorCode !== REQUIRE_PASSWORD_CHANGE && (
{loginErrorCode !== REQUIRE_PASSWORD_CHANGE
&& loginErrorCode !== NUDGE_PASSWORD_CHANGE && (
<Button
id="reset-password-back-to-login"
name="reset-password-back-to-login"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const initialState = {
},
};

jest.mock('@edx/frontend-platform/auth', () => ({
getAuthenticatedUser: jest.fn(),
}));

describe('ForgotPasswordPage', () => {
let store = {};

Expand Down
1 change: 1 addition & 0 deletions src/onboarding-component/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export const OnBoardingComponent = ({
close={close}
hasCloseButton={hasCloseButton}
size={screenSize}
currentForm={currentForm}
>
{pendingState
? getSpinner()
Expand Down

0 comments on commit 3d04e8d

Please sign in to comment.