Skip to content

Commit 82f85ad

Browse files
fix: fix useSelector usage in logistration and login component (#1203)
1 parent fade402 commit 82f85ad

File tree

5 files changed

+28
-88
lines changed

5 files changed

+28
-88
lines changed

src/common-components/data/reducers.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { THIRD_PARTY_AUTH_CONTEXT, THIRD_PARTY_AUTH_CONTEXT_CLEAR_ERROR_MSG } from './actions';
22
import { COMPLETE_STATE, FAILURE_STATE, PENDING_STATE } from '../../data/constants';
33

4+
export const storeName = 'commonComponents';
5+
46
export const defaultState = {
57
fieldDescriptions: {},
68
optionalFields: {

src/common-components/data/selectors.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/common-components/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export { default as InstitutionLogistration } from './InstitutionLogistration';
99
export { RenderInstitutionButton } from './InstitutionLogistration';
1010
export { default as reducer } from './data/reducers';
1111
export { default as saga } from './data/sagas';
12-
export { storeName } from './data/selectors';
12+
export { storeName } from './data/reducers';
1313
export { default as FormGroup } from './FormGroup';
1414
export { default as PasswordField } from './PasswordField';
1515
export { default as Zendesk } from './Zendesk';

src/login/LoginPage.jsx

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,21 @@ import ResetPasswordSuccess from '../reset-password/ResetPasswordSuccess';
4646
const LoginPage = (props) => {
4747
const dispatch = useDispatch();
4848
const { formatMessage } = useIntl();
49+
const backedUpFormData = useSelector(state => state.login.loginFormData);
50+
const loginErrorCode = useSelector(state => state.login.loginErrorCode);
51+
const loginErrorContext = useSelector(state => state.login.loginErrorContext);
52+
const loginResult = useSelector(state => state.login.loginResult);
53+
const shouldBackupState = useSelector(state => state.login.shouldBackupState);
54+
const showResetPasswordSuccessBanner = useSelector(state => state.login.showResetPasswordSuccessBanner);
55+
const submitState = useSelector(state => state.login.submitState);
4956

50-
const {
51-
loginFormData: backedUpFormData,
52-
loginErrorCode,
53-
loginErrorContext,
54-
loginResult,
55-
shouldBackupState,
56-
showResetPasswordSuccessBanner,
57-
submitState,
58-
} = useSelector(state => state.login);
59-
60-
const {
61-
thirdPartyAuthApiStatus,
62-
thirdPartyAuthContext: {
63-
providers,
64-
currentProvider,
65-
secondaryProviders,
66-
finishAuthUrl,
67-
platformName,
68-
errorMessage: thirdPartyErrorMessage,
69-
},
70-
} = useSelector(state => state.commonComponents);
57+
const thirdPartyAuthApiStatus = useSelector(state => state.commonComponents.thirdPartyAuthApiStatus);
58+
const providers = useSelector(state => state.commonComponents.thirdPartyAuthContext.providers);
59+
const currentProvider = useSelector(state => state.commonComponents.thirdPartyAuthContext.currentProvider);
60+
const secondaryProviders = useSelector(state => state.commonComponents.thirdPartyAuthContext.secondaryProviders);
61+
const finishAuthUrl = useSelector(state => state.commonComponents.thirdPartyAuthContext.finishAuthUrl);
62+
const platformName = useSelector(state => state.commonComponents.thirdPartyAuthContext.platformName);
63+
const thirdPartyErrorMessage = useSelector(state => state.commonComponents.thirdPartyAuthContext.errorMessage);
7164

7265
const {
7366
institutionLogin,
@@ -92,6 +85,7 @@ const LoginPage = (props) => {
9285
}
9386
dispatch(getTPADataFromBackend(payload));
9487
}, [dispatch, queryParams, tpaHint]);
88+
9589
/**
9690
* Backup the login form in redux when login page is toggled.
9791
*/

src/logistration/Logistration.jsx

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

44
import { getConfig } from '@edx/frontend-platform';
55
import { sendPageEvent, sendTrackEvent } from '@edx/frontend-platform/analytics';
@@ -16,9 +16,6 @@ import { Navigate, useNavigate } from 'react-router-dom';
1616

1717
import BaseContainer from '../base-container';
1818
import { clearThirdPartyAuthContextErrorMessage } from '../common-components/data/actions';
19-
import {
20-
tpaProvidersSelector,
21-
} from '../common-components/data/selectors';
2219
import messages from '../common-components/messages';
2320
import { LOGIN_PAGE, REGISTER_PAGE } from '../data/constants';
2421
import {
@@ -31,11 +28,8 @@ import { backupRegistrationForm, setSimplifyRegExperimentData } from '../registe
3128
import { FIRST_STEP, SECOND_STEP } from '../register/data/optimizelyExperiment/helper';
3229

3330
const Logistration = (props) => {
34-
const { selectedPage, tpaProviders } = props;
31+
const { selectedPage } = props;
3532
const tpaHint = getTpaHint();
36-
const {
37-
providers, secondaryProviders,
38-
} = tpaProviders;
3933
const { formatMessage } = useIntl();
4034
const [institutionLogin, setInstitutionLogin] = useState(false);
4135
const [key, setKey] = useState('');
@@ -44,7 +38,10 @@ const Logistration = (props) => {
4438
const hideRegistrationLink = getConfig().SHOW_REGISTRATION_LINKS === false;
4539

4640
const dispatch = useDispatch();
47-
const { simplifyRegExpVariation, simplifiedRegisterPageStep } = useSelector(state => state.register);
41+
const providers = useSelector(state => state.commonComponents.thirdPartyAuthContext.providers);
42+
const secondaryProviders = useSelector(state => state.commonComponents.thirdPartyAuthContext.secondaryProviders);
43+
const simplifyRegExpVariation = useSelector(state => state.register.simplifyRegExpVariation);
44+
const simplifiedRegisterPageStep = useSelector(state => state.register.simplifiedRegisterPageStep);
4845

4946
useEffect(() => {
5047
const authService = getAuthService();
@@ -72,11 +69,11 @@ const Logistration = (props) => {
7269

7370
const handleOnSelect = (tabKey) => {
7471
sendTrackEvent(`edx.bi.${tabKey.replace('/', '')}_form.toggled`, { category: 'user-engagement' });
75-
props.clearThirdPartyAuthContextErrorMessage();
72+
dispatch(clearThirdPartyAuthContextErrorMessage());
7673
if (tabKey === LOGIN_PAGE) {
77-
props.backupRegistrationForm();
74+
dispatch(backupRegistrationForm());
7875
} else if (tabKey === REGISTER_PAGE) {
79-
props.backupLoginForm();
76+
dispatch(backupLoginForm());
8077
}
8178
setKey(tabKey);
8279
};
@@ -184,35 +181,10 @@ const Logistration = (props) => {
184181

185182
Logistration.propTypes = {
186183
selectedPage: PropTypes.string,
187-
backupLoginForm: PropTypes.func.isRequired,
188-
backupRegistrationForm: PropTypes.func.isRequired,
189-
clearThirdPartyAuthContextErrorMessage: PropTypes.func.isRequired,
190-
tpaProviders: PropTypes.shape({
191-
providers: PropTypes.arrayOf(PropTypes.shape({})),
192-
secondaryProviders: PropTypes.arrayOf(PropTypes.shape({})),
193-
}),
194-
};
195-
196-
Logistration.defaultProps = {
197-
tpaProviders: {
198-
providers: [],
199-
secondaryProviders: [],
200-
},
201184
};
202185

203186
Logistration.defaultProps = {
204187
selectedPage: REGISTER_PAGE,
205188
};
206189

207-
const mapStateToProps = state => ({
208-
tpaProviders: tpaProvidersSelector(state),
209-
});
210-
211-
export default connect(
212-
mapStateToProps,
213-
{
214-
backupLoginForm,
215-
backupRegistrationForm,
216-
clearThirdPartyAuthContextErrorMessage,
217-
},
218-
)(Logistration);
190+
export default Logistration;

0 commit comments

Comments
 (0)