1
1
import React , { useEffect , useMemo , useState } from 'react' ;
2
- import { connect } from 'react-redux' ;
2
+ import { useDispatch , useSelector } from 'react-redux' ;
3
3
4
4
import { getConfig } from '@edx/frontend-platform' ;
5
5
import { sendPageEvent , sendTrackEvent } from '@edx/frontend-platform/analytics' ;
6
- import { injectIntl , useIntl } from '@edx/frontend-platform/i18n' ;
6
+ import { useIntl } from '@edx/frontend-platform/i18n' ;
7
7
import {
8
8
Form , StatefulButton ,
9
9
} from '@openedx/paragon' ;
@@ -14,7 +14,7 @@ import { Link } from 'react-router-dom';
14
14
15
15
import AccountActivationMessage from './AccountActivationMessage' ;
16
16
import {
17
- backupLoginFormBegin ,
17
+ backupLoginFormBegin as backupFormState ,
18
18
dismissPasswordResetBanner ,
19
19
loginRequest ,
20
20
} from './data/actions' ;
@@ -28,7 +28,7 @@ import {
28
28
RedirectLogistration ,
29
29
ThirdPartyAuthAlert ,
30
30
} from '../common-components' ;
31
- import { getThirdPartyAuthContext } from '../common-components/data/actions' ;
31
+ import { getThirdPartyAuthContext as getTPADataFromBackend } from '../common-components/data/actions' ;
32
32
import { thirdPartyAuthContextSelector } from '../common-components/data/selectors' ;
33
33
import EnterpriseSSO from '../common-components/EnterpriseSSO' ;
34
34
import ThirdPartyAuth from '../common-components/ThirdPartyAuth' ;
@@ -45,12 +45,22 @@ import {
45
45
import ResetPasswordSuccess from '../reset-password/ResetPasswordSuccess' ;
46
46
47
47
const LoginPage = ( props ) => {
48
+ const dispatch = useDispatch ( ) ;
49
+ const { formatMessage } = useIntl ( ) ;
50
+
48
51
const {
49
- backedUpFormData,
52
+ loginFormData : backedUpFormData ,
50
53
loginErrorCode,
51
54
loginErrorContext,
52
55
loginResult,
53
56
shouldBackupState,
57
+ showResetPasswordSuccessBanner,
58
+ submitState,
59
+ } = useSelector ( state => state . login ) ;
60
+
61
+ const {
62
+ thirdPartyAuthApiStatus,
63
+ thirdPartyAuthContext,
54
64
thirdPartyAuthContext : {
55
65
providers,
56
66
currentProvider,
@@ -59,19 +69,16 @@ const LoginPage = (props) => {
59
69
platformName,
60
70
errorMessage : thirdPartyErrorMessage ,
61
71
} ,
62
- thirdPartyAuthApiStatus,
72
+ } = useSelector ( state => state . commonComponents ) ;
73
+
74
+ const {
63
75
institutionLogin,
64
- showResetPasswordSuccessBanner,
65
- submitState,
66
- // Actions
67
- backupFormState,
68
76
handleInstitutionLogin,
69
- getTPADataFromBackend,
70
77
} = props ;
71
- const { formatMessage } = useIntl ( ) ;
78
+
72
79
const activationMsgType = getActivationStatus ( ) ;
73
80
const queryParams = useMemo ( ( ) => getAllPossibleQueryParams ( ) , [ ] ) ;
74
-
81
+ console . log ( 'backedUpFormData' , backedUpFormData ) ;
75
82
const [ formFields , setFormFields ] = useState ( { ...backedUpFormData . formFields } ) ;
76
83
const [ errorCode , setErrorCode ] = useState ( { type : '' , count : 0 , context : { } } ) ;
77
84
const [ errors , setErrors ] = useState ( { ...backedUpFormData . errors } ) ;
@@ -86,19 +93,19 @@ const LoginPage = (props) => {
86
93
if ( tpaHint ) {
87
94
payload . tpa_hint = tpaHint ;
88
95
}
89
- getTPADataFromBackend ( payload ) ;
90
- } , [ getTPADataFromBackend , queryParams , tpaHint ] ) ;
96
+ dispatch ( getTPADataFromBackend ( payload ) ) ;
97
+ } , [ dispatch , queryParams , tpaHint ] ) ;
91
98
/**
92
99
* Backup the login form in redux when login page is toggled.
93
100
*/
94
101
useEffect ( ( ) => {
95
102
if ( shouldBackupState ) {
96
- backupFormState ( {
103
+ dispatch ( backupFormState ( {
97
104
formFields : { ...formFields } ,
98
105
errors : { ...errors } ,
99
- } ) ;
106
+ } ) ) ;
100
107
}
101
- } , [ shouldBackupState , formFields , errors , backupFormState ] ) ;
108
+ } , [ shouldBackupState , formFields , errors , dispatch ] ) ;
102
109
103
110
useEffect ( ( ) => {
104
111
if ( loginErrorCode ) {
@@ -141,7 +148,7 @@ const LoginPage = (props) => {
141
148
const handleSubmit = ( event ) => {
142
149
event . preventDefault ( ) ;
143
150
if ( showResetPasswordSuccessBanner ) {
144
- props . dismissPasswordResetBanner ( ) ;
151
+ dispatch ( dismissPasswordResetBanner ( ) ) ;
145
152
}
146
153
147
154
const formData = { ...formFields } ;
@@ -158,7 +165,7 @@ const LoginPage = (props) => {
158
165
password : formData . password ,
159
166
...queryParams ,
160
167
} ;
161
- props . loginRequest ( payload ) ;
168
+ dispatch ( loginRequest ( payload ) ) ;
162
169
} ;
163
170
164
171
const handleOnChange = ( event ) => {
@@ -281,88 +288,10 @@ const LoginPage = (props) => {
281
288
) ;
282
289
} ;
283
290
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
-
299
291
LoginPage . 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 ,
318
292
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
- } ) ,
327
293
// Actions
328
- backupFormState : PropTypes . func . isRequired ,
329
- dismissPasswordResetBanner : PropTypes . func . isRequired ,
330
- loginRequest : PropTypes . func . isRequired ,
331
- getTPADataFromBackend : PropTypes . func . isRequired ,
332
294
handleInstitutionLogin : PropTypes . func . isRequired ,
333
295
} ;
334
296
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