Skip to content

Commit

Permalink
fix: clear error message (#82)
Browse files Browse the repository at this point in the history
clear error message on close button click

VAN-1984
  • Loading branch information
mubbsharanwar authored Jun 21, 2024
1 parent d73ed25 commit 14d4a3d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/base-container/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { ModalDialog } from '@openedx/paragon';
import classNames from 'classnames';
import PropTypes from 'prop-types';

import { useDispatch } from '../data/storeHooks';
import { deleteQueryParams } from '../data/utils';
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';
import './index.scss';

/**
Expand All @@ -25,8 +29,13 @@ const BaseContainer = ({
isOpen,
size = 'lg',
}) => {
const dispatch = useDispatch();

const handleOnClose = () => {
deleteQueryParams(['authMode', 'tpa_hint', 'password_reset_token', 'track']);
dispatch(forgotPasswordClearStatus());
dispatch(loginErrorClear());
dispatch(clearAllRegistrationErrors());
close();
};

Expand Down
5 changes: 5 additions & 0 deletions src/forms/registration-popup/data/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export const registerSlice = createSlice({
delete registrationErrorTemp[payload];
state.registrationError = registrationErrorTemp;
},
clearAllRegistrationErrors: (state) => {
state.registrationError = {};
state.validations = null;
},
setRegistrationFields: (state, { payload }) => {
state.registrationFields = payload;
},
Expand All @@ -77,6 +81,7 @@ export const {
fetchRealtimeValidations,
fetchRealtimeValidationsSuccess,
fetchRealtimeValidationsFailed,
clearAllRegistrationErrors,
clearRegistrationBackendError,
} = registerSlice.actions;

Expand Down
21 changes: 20 additions & 1 deletion src/forms/registration-popup/data/tests/reducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import {
COMPLETE_STATE, DEFAULT_STATE, PENDING_STATE,
} from '../../../../data/constants';
import registerReducer, {
clearRegistrationBackendError, fetchRealtimeValidations,
clearAllRegistrationErrors,
clearRegistrationBackendError,
fetchRealtimeValidations,
fetchRealtimeValidationsFailed,
fetchRealtimeValidationsSuccess,
registerInitialState,
Expand Down Expand Up @@ -56,4 +58,21 @@ describe('registerSlice reducer', () => {

expect(nextState.registrationError).toEqual({ errorCode: 'duplicate-email' });
});

it('should handle clearAllRegistrationErrors action', () => {
const nextState = registerReducer({
...registerInitialState,
registrationError: {
email: [
{
userMessage: 'This email is already associated with an existing or previous edX account',
},
],
errorCode: 'duplicate-email',
},

}, clearAllRegistrationErrors());

expect(nextState.registrationError).toEqual({});
});
});

0 comments on commit 14d4a3d

Please sign in to comment.