Skip to content

Commit 35a55ac

Browse files
fix: fix useSelector usage in logistration and login component (#1203)
1 parent f9e4e2d commit 35a55ac

File tree

7 files changed

+31
-90
lines changed

7 files changed

+31
-90
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/login/tests/LoginPage.test.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,16 @@ describe('LoginPage', () => {
3939
</MemoryRouter>
4040
</IntlProvider>
4141
);
42+
4243
const loginFormData = {
4344
formFields: {
4445
emailOrUsername: '', password: '',
4546
},
46-
4747
errors: {
4848
emailOrUsername: '', password: '',
4949
},
5050
};
51+
5152
const initialState = {
5253
login: {
5354
loginFormData,

src/logistration/Logistration.jsx

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useState } from 'react';
2-
import { connect } 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 {
@@ -30,18 +27,19 @@ import { RegistrationPage } from '../register';
3027
import { backupRegistrationForm } from '../register/data/actions';
3128

3229
const Logistration = (props) => {
33-
const { selectedPage, tpaProviders } = props;
30+
const { selectedPage } = props;
3431
const tpaHint = getTpaHint();
35-
const {
36-
providers, secondaryProviders,
37-
} = tpaProviders;
3832
const { formatMessage } = useIntl();
3933
const [institutionLogin, setInstitutionLogin] = useState(false);
4034
const [key, setKey] = useState('');
4135
const navigate = useNavigate();
4236
const disablePublicAccountCreation = getConfig().ALLOW_PUBLIC_ACCOUNT_CREATION === false;
4337
const hideRegistrationLink = getConfig().SHOW_REGISTRATION_LINKS === false;
4438

39+
const dispatch = useDispatch();
40+
const providers = useSelector(state => state.commonComponents.thirdPartyAuthContext.providers);
41+
const secondaryProviders = useSelector(state => state.commonComponents.thirdPartyAuthContext.secondaryProviders);
42+
4543
useEffect(() => {
4644
const authService = getAuthService();
4745
if (authService) {
@@ -71,11 +69,11 @@ const Logistration = (props) => {
7169
return;
7270
}
7371
sendTrackEvent(`edx.bi.${tabKey.replace('/', '')}_form.toggled`, { category: 'user-engagement' });
74-
props.clearThirdPartyAuthContextErrorMessage();
72+
dispatch(clearThirdPartyAuthContextErrorMessage());
7573
if (tabKey === LOGIN_PAGE) {
76-
props.backupRegistrationForm();
74+
dispatch(backupRegistrationForm());
7775
} else if (tabKey === REGISTER_PAGE) {
78-
props.backupLoginForm();
76+
dispatch(backupLoginForm());
7977
}
8078
setKey(tabKey);
8179
};
@@ -156,35 +154,10 @@ const Logistration = (props) => {
156154

157155
Logistration.propTypes = {
158156
selectedPage: PropTypes.string,
159-
backupLoginForm: PropTypes.func.isRequired,
160-
backupRegistrationForm: PropTypes.func.isRequired,
161-
clearThirdPartyAuthContextErrorMessage: PropTypes.func.isRequired,
162-
tpaProviders: PropTypes.shape({
163-
providers: PropTypes.arrayOf(PropTypes.shape({})),
164-
secondaryProviders: PropTypes.arrayOf(PropTypes.shape({})),
165-
}),
166-
};
167-
168-
Logistration.defaultProps = {
169-
tpaProviders: {
170-
providers: [],
171-
secondaryProviders: [],
172-
},
173157
};
174158

175159
Logistration.defaultProps = {
176160
selectedPage: REGISTER_PAGE,
177161
};
178162

179-
const mapStateToProps = state => ({
180-
tpaProviders: tpaProvidersSelector(state),
181-
});
182-
183-
export default connect(
184-
mapStateToProps,
185-
{
186-
backupLoginForm,
187-
backupRegistrationForm,
188-
clearThirdPartyAuthContextErrorMessage,
189-
},
190-
)(Logistration);
163+
export default Logistration;

src/logistration/Logistration.test.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ describe('Logistration', () => {
4242
</MemoryRouter>
4343
</IntlProvider>
4444
);
45+
4546
const loginFormData = {
4647
formFields: {
4748
emailOrUsername: '', password: '',
4849
},
49-
5050
errors: {
5151
emailOrUsername: '', password: '',
5252
},
@@ -82,7 +82,6 @@ describe('Logistration', () => {
8282
login: {
8383
loginFormData,
8484
loginResult: { success: false, redirectUrl: '' },
85-
8685
},
8786
};
8887

0 commit comments

Comments
 (0)