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 19, 2024
1 parent aa19c62 commit c046cd3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/base-container/index.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react';

import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
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 { loginErrorClear } from '../forms/login-popup/data/reducers';
import { clearAllRegistrationErrors } from '../forms/registration-popup/data/reducers';
Expand All @@ -28,10 +30,17 @@ const BaseContainer = ({
hasCloseButton = true,
isOpen,
size = 'lg',
currentForm,
}) => {
const dispatch = useDispatch();

const authenticatedUser = getAuthenticatedUser();
const loginErrorResult = useSelector(state => state.login.loginError);

const handleOnClose = () => {
if (authenticatedUser && 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 +79,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
5 changes: 4 additions & 1 deletion src/forms/reset-password-popup/forgot-password/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect, useRef, useState } from 'react';

import { getConfig } from '@edx/frontend-platform';
import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
import { useIntl } from '@edx/frontend-platform/i18n';
import {
Button, Container, Form, StatefulButton,
Expand All @@ -26,6 +27,8 @@ const ForgotPasswordForm = () => {
const { formatMessage } = useIntl();
const dispatch = useDispatch();

const authenticatedUser = getAuthenticatedUser();

const status = useSelector(state => state.forgotPassword?.status);
const backedUpFormData = useSelector(state => state.forgotPassword?.forgotPasswordFormData);
const loginErrorCode = useSelector(state => state.login.loginError?.errorCode);
Expand Down Expand Up @@ -168,7 +171,7 @@ const ForgotPasswordForm = () => {
<ForgotPasswordSuccess email={formFields.email} />
)}
<div className="text-center mt-4.5">
{loginErrorCode !== REQUIRE_PASSWORD_CHANGE && (
{loginErrorCode !== REQUIRE_PASSWORD_CHANGE && !authenticatedUser && (
<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 c046cd3

Please sign in to comment.