1
+ /* eslint-disable no-shadow */
1
2
import React , { Component } from 'react' ;
2
3
import styled from 'styled-components' ;
4
+ import { bindActionCreators } from 'redux' ;
3
5
import { connect } from 'react-redux' ;
4
6
import { ActivityIndicator } from 'react-native' ;
7
+ import CookieManager from 'react-native-cookies' ;
5
8
9
+ import { auth , getUser } from 'auth' ;
6
10
import { ViewContainer } from 'components' ;
7
11
import { colors , fonts , normalize } from 'config' ;
8
- import { t } from 'utils' ;
12
+ import { t , resetNavigationTo } from 'utils' ;
9
13
10
14
const mapStateToProps = state => ( {
11
15
locale : state . auth . locale ,
12
16
isLoggingIn : state . auth . isLoggingIn ,
17
+ isAuthenticated : state . auth . isAuthenticated ,
13
18
} ) ;
14
19
20
+ const mapDispatchToProps = dispatch =>
21
+ bindActionCreators (
22
+ {
23
+ auth,
24
+ getUser,
25
+ } ,
26
+ dispatch
27
+ ) ;
28
+
15
29
const Container = styled . View `
16
30
flex: 1;
17
31
justify-content: center;
@@ -30,8 +44,30 @@ class Welcome extends Component {
30
44
props : {
31
45
locale : string ,
32
46
isLoggingIn : boolean ,
47
+ isAuthenticated : boolean ,
48
+ auth : Function ,
49
+ getUser : Function ,
50
+ navigation : Object ,
33
51
} ;
34
52
53
+ componentDidMount ( ) {
54
+ const { isAuthenticated, navigation, auth, getUser } = this . props ;
55
+ const { code, state } = navigation . state . params ;
56
+
57
+ if ( isAuthenticated ) {
58
+ resetNavigationTo ( 'Main' , navigation ) ;
59
+ } else {
60
+ CookieManager . clearAll ( ) . then ( ( ) => {
61
+ auth ( code , state ) . then ( ( ) => {
62
+ getUser ( ) . then ( ( ) => {
63
+ console . log ( 'resetNavigationTo Main' ) ;
64
+ resetNavigationTo ( 'Main' , navigation ) ;
65
+ } ) ;
66
+ } ) ;
67
+ } ) ;
68
+ }
69
+ }
70
+
35
71
render ( ) {
36
72
const { locale, isLoggingIn } = this . props ;
37
73
@@ -46,4 +82,4 @@ class Welcome extends Component {
46
82
}
47
83
}
48
84
49
- export const WelcomeScreen = connect ( mapStateToProps ) ( Welcome ) ;
85
+ export const WelcomeScreen = connect ( mapStateToProps , mapDispatchToProps ) ( Welcome ) ;
0 commit comments