11import React , { useEffect , useMemo , useState } from 'react' ;
2- import { connect } from 'react-redux' ;
2+ import { useDispatch , useSelector } from 'react-redux' ;
33
44import { getConfig } from '@edx/frontend-platform' ;
55import { sendPageEvent , sendTrackEvent } from '@edx/frontend-platform/analytics' ;
6- import { injectIntl , useIntl } from '@edx/frontend-platform/i18n' ;
6+ import { useIntl } from '@edx/frontend-platform/i18n' ;
77import {
88 Form , StatefulButton ,
99} from '@openedx/paragon' ;
@@ -14,7 +14,7 @@ import { Link } from 'react-router-dom';
1414
1515import AccountActivationMessage from './AccountActivationMessage' ;
1616import {
17- backupLoginFormBegin ,
17+ backupLoginFormBegin as backupFormState ,
1818 dismissPasswordResetBanner ,
1919 loginRequest ,
2020} from './data/actions' ;
@@ -28,12 +28,11 @@ import {
2828 RedirectLogistration ,
2929 ThirdPartyAuthAlert ,
3030} from '../common-components' ;
31- import { getThirdPartyAuthContext } from '../common-components/data/actions' ;
32- import { thirdPartyAuthContextSelector } from '../common-components/data/selectors' ;
31+ import { getThirdPartyAuthContext as getTPADataFromBackend } from '../common-components/data/actions' ;
3332import EnterpriseSSO from '../common-components/EnterpriseSSO' ;
3433import ThirdPartyAuth from '../common-components/ThirdPartyAuth' ;
3534import {
36- DEFAULT_STATE , PENDING_STATE , RESET_PAGE ,
35+ PENDING_STATE , RESET_PAGE ,
3736} from '../data/constants' ;
3837import {
3938 getActivationStatus ,
@@ -45,12 +44,21 @@ import {
4544import ResetPasswordSuccess from '../reset-password/ResetPasswordSuccess' ;
4645
4746const LoginPage = ( props ) => {
47+ const dispatch = useDispatch ( ) ;
48+ const { formatMessage } = useIntl ( ) ;
49+
4850 const {
49- backedUpFormData,
51+ loginFormData : backedUpFormData ,
5052 loginErrorCode,
5153 loginErrorContext,
5254 loginResult,
5355 shouldBackupState,
56+ showResetPasswordSuccessBanner,
57+ submitState,
58+ } = useSelector ( state => state . login ) ;
59+
60+ const {
61+ thirdPartyAuthApiStatus,
5462 thirdPartyAuthContext : {
5563 providers,
5664 currentProvider,
@@ -59,19 +67,15 @@ const LoginPage = (props) => {
5967 platformName,
6068 errorMessage : thirdPartyErrorMessage ,
6169 } ,
62- thirdPartyAuthApiStatus,
70+ } = useSelector ( state => state . commonComponents ) ;
71+
72+ const {
6373 institutionLogin,
64- showResetPasswordSuccessBanner,
65- submitState,
66- // Actions
67- backupFormState,
6874 handleInstitutionLogin,
69- getTPADataFromBackend,
7075 } = props ;
71- const { formatMessage } = useIntl ( ) ;
76+
7277 const activationMsgType = getActivationStatus ( ) ;
7378 const queryParams = useMemo ( ( ) => getAllPossibleQueryParams ( ) , [ ] ) ;
74-
7579 const [ formFields , setFormFields ] = useState ( { ...backedUpFormData . formFields } ) ;
7680 const [ errorCode , setErrorCode ] = useState ( { type : '' , count : 0 , context : { } } ) ;
7781 const [ errors , setErrors ] = useState ( { ...backedUpFormData . errors } ) ;
@@ -86,19 +90,19 @@ const LoginPage = (props) => {
8690 if ( tpaHint ) {
8791 payload . tpa_hint = tpaHint ;
8892 }
89- getTPADataFromBackend ( payload ) ;
90- } , [ getTPADataFromBackend , queryParams , tpaHint ] ) ;
93+ dispatch ( getTPADataFromBackend ( payload ) ) ;
94+ } , [ dispatch , queryParams , tpaHint ] ) ;
9195 /**
9296 * Backup the login form in redux when login page is toggled.
9397 */
9498 useEffect ( ( ) => {
9599 if ( shouldBackupState ) {
96- backupFormState ( {
100+ dispatch ( backupFormState ( {
97101 formFields : { ...formFields } ,
98102 errors : { ...errors } ,
99- } ) ;
103+ } ) ) ;
100104 }
101- } , [ shouldBackupState , formFields , errors , backupFormState ] ) ;
105+ } , [ shouldBackupState , formFields , errors , dispatch ] ) ;
102106
103107 useEffect ( ( ) => {
104108 if ( loginErrorCode ) {
@@ -141,7 +145,7 @@ const LoginPage = (props) => {
141145 const handleSubmit = ( event ) => {
142146 event . preventDefault ( ) ;
143147 if ( showResetPasswordSuccessBanner ) {
144- props . dismissPasswordResetBanner ( ) ;
148+ dispatch ( dismissPasswordResetBanner ( ) ) ;
145149 }
146150
147151 const formData = { ...formFields } ;
@@ -158,7 +162,7 @@ const LoginPage = (props) => {
158162 password : formData . password ,
159163 ...queryParams ,
160164 } ;
161- props . loginRequest ( payload ) ;
165+ dispatch ( loginRequest ( payload ) ) ;
162166 } ;
163167
164168 const handleOnChange = ( event ) => {
@@ -281,88 +285,10 @@ const LoginPage = (props) => {
281285 ) ;
282286} ;
283287
284- const mapStateToProps = state => {
285- const loginPageState = state . login ;
286- 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 ,
294- thirdPartyAuthContext : thirdPartyAuthContextSelector ( state ) ,
295- thirdPartyAuthApiStatus : state . commonComponents . thirdPartyAuthApiStatus ,
296- } ;
297- } ;
298-
299288LoginPage . propTypes = {
300- backedUpFormData : PropTypes . shape ( {
301- formFields : PropTypes . shape ( { } ) ,
302- errors : PropTypes . shape ( { } ) ,
303- } ) ,
304- loginErrorCode : PropTypes . string ,
305- loginErrorContext : PropTypes . shape ( {
306- email : PropTypes . string ,
307- redirectUrl : PropTypes . string ,
308- context : PropTypes . shape ( { } ) ,
309- } ) ,
310- loginResult : PropTypes . shape ( {
311- redirectUrl : PropTypes . string ,
312- success : PropTypes . bool ,
313- } ) ,
314- shouldBackupState : PropTypes . bool ,
315- showResetPasswordSuccessBanner : PropTypes . bool ,
316- submitState : PropTypes . string ,
317- thirdPartyAuthApiStatus : PropTypes . string ,
318289 institutionLogin : PropTypes . bool . isRequired ,
319- thirdPartyAuthContext : PropTypes . shape ( {
320- currentProvider : PropTypes . string ,
321- errorMessage : PropTypes . string ,
322- platformName : PropTypes . string ,
323- providers : PropTypes . arrayOf ( PropTypes . shape ( { } ) ) ,
324- secondaryProviders : PropTypes . arrayOf ( PropTypes . shape ( { } ) ) ,
325- finishAuthUrl : PropTypes . string ,
326- } ) ,
327290 // Actions
328- backupFormState : PropTypes . func . isRequired ,
329- dismissPasswordResetBanner : PropTypes . func . isRequired ,
330- loginRequest : PropTypes . func . isRequired ,
331- getTPADataFromBackend : PropTypes . func . isRequired ,
332291 handleInstitutionLogin : PropTypes . func . isRequired ,
333292} ;
334293
335- LoginPage . defaultProps = {
336- backedUpFormData : {
337- formFields : {
338- emailOrUsername : '' , password : '' ,
339- } ,
340- errors : {
341- emailOrUsername : '' , password : '' ,
342- } ,
343- } ,
344- loginErrorCode : null ,
345- loginErrorContext : { } ,
346- loginResult : { } ,
347- shouldBackupState : false ,
348- showResetPasswordSuccessBanner : false ,
349- submitState : DEFAULT_STATE ,
350- thirdPartyAuthApiStatus : PENDING_STATE ,
351- thirdPartyAuthContext : {
352- currentProvider : null ,
353- errorMessage : null ,
354- finishAuthUrl : null ,
355- providers : [ ] ,
356- secondaryProviders : [ ] ,
357- } ,
358- } ;
359-
360- export default connect (
361- mapStateToProps ,
362- {
363- backupFormState : backupLoginFormBegin ,
364- dismissPasswordResetBanner,
365- loginRequest,
366- getTPADataFromBackend : getThirdPartyAuthContext ,
367- } ,
368- ) ( injectIntl ( LoginPage ) ) ;
294+ export default LoginPage ;
0 commit comments