Skip to content

Commit e19d19d

Browse files
committed
feat: Add plugin slot for login page
This change adds a plugin slot for the login page allowing it to be customised. Since there was a dependency conflict between frontend-plugin-framework and the react-hooks testing package, the react-hooks testing package has been removed and a replaced with a simple mechanism for testing hooks. Since this touched the Login Page those have also been refactored to move away from redux connect.
1 parent 8939e5b commit e19d19d

File tree

8 files changed

+260
-175
lines changed

8 files changed

+260
-175
lines changed

package-lock.json

Lines changed: 41 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939
"@fortawesome/free-brands-svg-icons": "6.6.0",
4040
"@fortawesome/free-solid-svg-icons": "6.6.0",
4141
"@fortawesome/react-fontawesome": "0.2.2",
42+
"@openedx/frontend-plugin-framework": "^1.4.0",
4243
"@openedx/paragon": "^22.1.1",
4344
"@optimizely/react-sdk": "^2.9.1",
4445
"@redux-devtools/extension": "3.3.0",
4546
"@testing-library/react": "^12.1.5",
46-
"@testing-library/react-hooks": "^8.0.1",
4747
"algoliasearch": "^4.14.3",
4848
"algoliasearch-helper": "^3.14.0",
4949
"classnames": "2.5.1",

src/login/LoginPage.jsx

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useMemo, useState } from 'react';
2-
import { connect } from 'react-redux';
2+
import { connect, useSelector } from 'react-redux';
33

44
import { getConfig } from '@edx/frontend-platform';
55
import { sendPageEvent, sendTrackEvent } from '@edx/frontend-platform/analytics';
@@ -33,7 +33,7 @@ import { thirdPartyAuthContextSelector } from '../common-components/data/selecto
3333
import EnterpriseSSO from '../common-components/EnterpriseSSO';
3434
import ThirdPartyAuth from '../common-components/ThirdPartyAuth';
3535
import {
36-
DEFAULT_STATE, PENDING_STATE, RESET_PAGE,
36+
PENDING_STATE, RESET_PAGE,
3737
} from '../data/constants';
3838
import {
3939
getActivationStatus,
@@ -46,11 +46,6 @@ import ResetPasswordSuccess from '../reset-password/ResetPasswordSuccess';
4646

4747
const LoginPage = (props) => {
4848
const {
49-
backedUpFormData,
50-
loginErrorCode,
51-
loginErrorContext,
52-
loginResult,
53-
shouldBackupState,
5449
thirdPartyAuthContext: {
5550
providers,
5651
currentProvider,
@@ -59,15 +54,32 @@ const LoginPage = (props) => {
5954
platformName,
6055
errorMessage: thirdPartyErrorMessage,
6156
},
62-
thirdPartyAuthApiStatus,
6357
institutionLogin,
64-
showResetPasswordSuccessBanner,
65-
submitState,
6658
// Actions
6759
backupFormState,
6860
handleInstitutionLogin,
6961
getTPADataFromBackend,
7062
} = props;
63+
const {
64+
backedUpFormData,
65+
loginErrorCode,
66+
loginErrorContext,
67+
loginResult,
68+
shouldBackupState,
69+
showResetPasswordSuccessBanner,
70+
submitState,
71+
thirdPartyAuthApiStatus,
72+
} = useSelector((state) => ({
73+
backedUpFormData: state.login.loginFormData,
74+
loginErrorCode: state.login.loginErrorCode,
75+
loginErrorContext: state.login.loginErrorContext,
76+
loginResult: state.login.loginResult,
77+
shouldBackupState: state.login.shouldBackupState,
78+
showResetPasswordSuccessBanner: state.login.showResetPasswordSuccessBanner,
79+
submitState: state.login.submitState,
80+
thirdPartyAuthContext: thirdPartyAuthContextSelector(state),
81+
thirdPartyAuthApiStatus: state.commonComponents.thirdPartyAuthApiStatus,
82+
}));
7183
const { formatMessage } = useIntl();
7284
const activationMsgType = getActivationStatus();
7385
const queryParams = useMemo(() => getAllPossibleQueryParams(), []);
@@ -282,17 +294,8 @@ const LoginPage = (props) => {
282294
};
283295

284296
const mapStateToProps = state => {
285-
const loginPageState = state.login;
286297
return {
287-
backedUpFormData: loginPageState.loginFormData,
288-
loginErrorCode: loginPageState.loginErrorCode,
289-
loginErrorContext: loginPageState.loginErrorContext,
290-
loginResult: loginPageState.loginResult,
291-
shouldBackupState: loginPageState.shouldBackupState,
292-
showResetPasswordSuccessBanner: loginPageState.showResetPasswordSuccessBanner,
293-
submitState: loginPageState.submitState,
294298
thirdPartyAuthContext: thirdPartyAuthContextSelector(state),
295-
thirdPartyAuthApiStatus: state.commonComponents.thirdPartyAuthApiStatus,
296299
};
297300
};
298301

@@ -301,7 +304,6 @@ LoginPage.propTypes = {
301304
formFields: PropTypes.shape({}),
302305
errors: PropTypes.shape({}),
303306
}),
304-
loginErrorCode: PropTypes.string,
305307
loginErrorContext: PropTypes.shape({
306308
email: PropTypes.string,
307309
redirectUrl: PropTypes.string,
@@ -311,10 +313,6 @@ LoginPage.propTypes = {
311313
redirectUrl: PropTypes.string,
312314
success: PropTypes.bool,
313315
}),
314-
shouldBackupState: PropTypes.bool,
315-
showResetPasswordSuccessBanner: PropTypes.bool,
316-
submitState: PropTypes.string,
317-
thirdPartyAuthApiStatus: PropTypes.string,
318316
institutionLogin: PropTypes.bool.isRequired,
319317
thirdPartyAuthContext: PropTypes.shape({
320318
currentProvider: PropTypes.string,
@@ -341,13 +339,8 @@ LoginPage.defaultProps = {
341339
emailOrUsername: '', password: '',
342340
},
343341
},
344-
loginErrorCode: null,
345342
loginErrorContext: {},
346343
loginResult: {},
347-
shouldBackupState: false,
348-
showResetPasswordSuccessBanner: false,
349-
submitState: DEFAULT_STATE,
350-
thirdPartyAuthApiStatus: PENDING_STATE,
351344
thirdPartyAuthContext: {
352345
currentProvider: null,
353346
errorMessage: null,

src/login/tests/LoginPage.test.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ describe('LoginPage', () => {
4343
const initialState = {
4444
login: {
4545
loginResult: { success: false, redirectUrl: '' },
46+
loginFormData: {
47+
formFields: {
48+
emailOrUsername: '', password: '',
49+
},
50+
errors: {
51+
emailOrUsername: '', password: '',
52+
},
53+
},
4654
},
4755
commonComponents: {
4856
thirdPartyAuthApiStatus: null,

0 commit comments

Comments
 (0)