Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix login nudge issue #118

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
syedsajjadkazmii marked this conversation as resolved.
Show resolved Hide resolved
} = 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
Loading