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,7 +28,7 @@ import {
2828 RedirectLogistration ,
2929 ThirdPartyAuthAlert ,
3030} from '../common-components' ;
31- import { getThirdPartyAuthContext } from '../common-components/data/actions' ;
31+ import { getThirdPartyAuthContext as getTPADataFromBackend } from '../common-components/data/actions' ;
3232import { thirdPartyAuthContextSelector } from '../common-components/data/selectors' ;
3333import EnterpriseSSO from '../common-components/EnterpriseSSO' ;
3434import ThirdPartyAuth from '../common-components/ThirdPartyAuth' ;
@@ -45,12 +45,22 @@ import {
4545import ResetPasswordSuccess from '../reset-password/ResetPasswordSuccess' ;
4646
4747const LoginPage = ( props ) => {
48+ const dispatch = useDispatch ( ) ;
49+ const { formatMessage } = useIntl ( ) ;
50+
4851 const {
49- backedUpFormData,
52+ loginFormData : backedUpFormData ,
5053 loginErrorCode,
5154 loginErrorContext,
5255 loginResult,
5356 shouldBackupState,
57+ showResetPasswordSuccessBanner,
58+ submitState,
59+ } = useSelector ( state => state . login ) ;
60+
61+ const {
62+ thirdPartyAuthApiStatus,
63+ thirdPartyAuthContext,
5464 thirdPartyAuthContext : {
5565 providers,
5666 currentProvider,
@@ -59,19 +69,16 @@ const LoginPage = (props) => {
5969 platformName,
6070 errorMessage : thirdPartyErrorMessage ,
6171 } ,
62- thirdPartyAuthApiStatus,
72+ } = useSelector ( state => state . commonComponents ) ;
73+
74+ const {
6375 institutionLogin,
64- showResetPasswordSuccessBanner,
65- submitState,
66- // Actions
67- backupFormState,
6876 handleInstitutionLogin,
69- getTPADataFromBackend,
7077 } = props ;
71- const { formatMessage } = useIntl ( ) ;
78+
7279 const activationMsgType = getActivationStatus ( ) ;
7380 const queryParams = useMemo ( ( ) => getAllPossibleQueryParams ( ) , [ ] ) ;
74-
81+ console . log ( 'backedUpFormData' , backedUpFormData ) ;
7582 const [ formFields , setFormFields ] = useState ( { ...backedUpFormData . formFields } ) ;
7683 const [ errorCode , setErrorCode ] = useState ( { type : '' , count : 0 , context : { } } ) ;
7784 const [ errors , setErrors ] = useState ( { ...backedUpFormData . errors } ) ;
@@ -86,19 +93,19 @@ const LoginPage = (props) => {
8693 if ( tpaHint ) {
8794 payload . tpa_hint = tpaHint ;
8895 }
89- getTPADataFromBackend ( payload ) ;
90- } , [ getTPADataFromBackend , queryParams , tpaHint ] ) ;
96+ dispatch ( getTPADataFromBackend ( payload ) ) ;
97+ } , [ dispatch , queryParams , tpaHint ] ) ;
9198 /**
9299 * Backup the login form in redux when login page is toggled.
93100 */
94101 useEffect ( ( ) => {
95102 if ( shouldBackupState ) {
96- backupFormState ( {
103+ dispatch ( backupFormState ( {
97104 formFields : { ...formFields } ,
98105 errors : { ...errors } ,
99- } ) ;
106+ } ) ) ;
100107 }
101- } , [ shouldBackupState , formFields , errors , backupFormState ] ) ;
108+ } , [ shouldBackupState , formFields , errors , dispatch ] ) ;
102109
103110 useEffect ( ( ) => {
104111 if ( loginErrorCode ) {
@@ -141,7 +148,7 @@ const LoginPage = (props) => {
141148 const handleSubmit = ( event ) => {
142149 event . preventDefault ( ) ;
143150 if ( showResetPasswordSuccessBanner ) {
144- props . dismissPasswordResetBanner ( ) ;
151+ dispatch ( dismissPasswordResetBanner ( ) ) ;
145152 }
146153
147154 const formData = { ...formFields } ;
@@ -158,7 +165,7 @@ const LoginPage = (props) => {
158165 password : formData . password ,
159166 ...queryParams ,
160167 } ;
161- props . loginRequest ( payload ) ;
168+ dispatch ( loginRequest ( payload ) ) ;
162169 } ;
163170
164171 const handleOnChange = ( event ) => {
@@ -281,88 +288,10 @@ const LoginPage = (props) => {
281288 ) ;
282289} ;
283290
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-
299291LoginPage . 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 ,
318292 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- } ) ,
327293 // Actions
328- backupFormState : PropTypes . func . isRequired ,
329- dismissPasswordResetBanner : PropTypes . func . isRequired ,
330- loginRequest : PropTypes . func . isRequired ,
331- getTPADataFromBackend : PropTypes . func . isRequired ,
332294 handleInstitutionLogin : PropTypes . func . isRequired ,
333295} ;
334296
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 ) ) ;
297+ export default LoginPage ;
0 commit comments