@@ -21,18 +21,21 @@ class ProfileContainer extends React.Component {
21
21
meta,
22
22
auth,
23
23
} = this . props ;
24
-
25
24
loadProfile ( handleParam , _ . get ( meta , 'groupIds' , [ ] ) , auth . tokenV3 , loadPublicStatsOnly ( meta ) ) ;
26
- if ( auth . tokenV3 && auth . memberGroups && auth . memberGroups . length > 0
27
- && auth . user && auth . user . handle === handleParam ) {
28
- _ . forEach ( auth . memberGroups , ( memberGroup ) => { /* eslint consistent-return: off */
29
- const profileConfig = _ . find ( config . URL . SUBDOMAIN_PROFILE_CONFIG , { groupId : memberGroup } ) ;
30
- if ( profileConfig && profileConfig . userProfile ) {
31
- // redirect user to configured profile url
32
- window . location . href = profileConfig . userProfile ;
33
- return false ;
34
- }
35
- } ) ;
25
+ if ( auth . tokenV3 && auth . memberGroups && auth . memberGroups . length > 0 && auth . user ) {
26
+ if ( auth . user . handle === handleParam ) {
27
+ _ . forEach ( auth . memberGroups , ( memberGroup ) => { /* eslint consistent-return: off */
28
+ const profileConfig = _ . find (
29
+ config . URL . SUBDOMAIN_PROFILE_CONFIG ,
30
+ { groupId : memberGroup } ,
31
+ ) ;
32
+ if ( profileConfig && profileConfig . userProfile ) {
33
+ // redirect user to configured profile url
34
+ window . location . href = profileConfig . userProfile ;
35
+ return false ;
36
+ }
37
+ } ) ;
38
+ }
36
39
}
37
40
}
38
41
@@ -41,13 +44,40 @@ class ProfileContainer extends React.Component {
41
44
handleParam,
42
45
profileForHandle,
43
46
loadProfile,
47
+ loadMemberGroups,
44
48
meta,
45
49
auth,
50
+ info,
51
+ memberGroups,
46
52
} = nextProps ;
47
53
54
+ const {
55
+ info : prevInfo ,
56
+ memberGroups : prevMemberGroups ,
57
+ } = this . props ;
58
+
48
59
if ( handleParam !== profileForHandle ) {
49
60
loadProfile ( handleParam , _ . get ( meta , 'groupIds' , [ ] ) , auth . tokenV3 , loadPublicStatsOnly ( meta ) ) ;
50
61
}
62
+
63
+ if ( auth . tokenV3 && auth . user && auth . user . handle !== handleParam
64
+ && info != null && info . userId != null
65
+ && ( prevInfo == null || info . userId !== prevInfo . userId ) ) {
66
+ loadMemberGroups ( info . userId , auth . tokenV3 ) ;
67
+ }
68
+
69
+ if ( memberGroups && memberGroups !== prevMemberGroups ) {
70
+ _ . forEach ( auth . memberGroups , ( memberGroup ) => { /* eslint consistent-return: off */
71
+ const profileConfig = _ . find ( config . URL . SUBDOMAIN_PROFILE_CONFIG , { groupId : memberGroup } ) ;
72
+ if ( profileConfig && profileConfig . userProfile
73
+ && memberGroups . indexOf ( profileConfig . groupId ) === - 1 ) {
74
+ if ( window . location . href . indexOf ( profileConfig . communityName ) !== - 1 ) {
75
+ window . location . href = `${ config . URL . BASE } /members/${ handleParam } ` ;
76
+ }
77
+ return false ;
78
+ }
79
+ } ) ;
80
+ }
51
81
}
52
82
53
83
render ( ) {
@@ -106,6 +136,7 @@ ProfileContainer.defaultProps = {
106
136
skills : null ,
107
137
stats : null ,
108
138
meta : null ,
139
+ memberGroups : null ,
109
140
auth : { } ,
110
141
} ;
111
142
@@ -119,9 +150,11 @@ ProfileContainer.propTypes = {
119
150
info : PT . shape ( ) ,
120
151
loadingError : PT . bool . isRequired ,
121
152
loadProfile : PT . func . isRequired ,
153
+ loadMemberGroups : PT . func . isRequired ,
122
154
profileForHandle : PT . string ,
123
155
skills : PT . shape ( ) ,
124
156
stats : PT . arrayOf ( PT . shape ( ) ) ,
157
+ memberGroups : PT . arrayOf ( PT . string ) ,
125
158
lookupData : PT . shape ( ) . isRequired ,
126
159
meta : PT . shape ( ) ,
127
160
auth : PT . shape ( ) ,
@@ -140,6 +173,7 @@ const mapStateToProps = (state, ownProps) => ({
140
173
profileForHandle : state . profile . profileForHandle ,
141
174
skills : state . profile . skills ,
142
175
stats : state . profile . stats ,
176
+ memberGroups : state . groups . memberGroups ,
143
177
lookupData : state . lookup ,
144
178
auth : {
145
179
...state . auth ,
@@ -150,6 +184,9 @@ function mapDispatchToProps(dispatch) {
150
184
const a = actions . profile ;
151
185
const lookupActions = actions . lookup ;
152
186
return {
187
+ loadMemberGroups : ( userId , tokenV3 ) => {
188
+ dispatch ( actions . groups . getMemberGroups ( userId , tokenV3 ) ) ;
189
+ } ,
153
190
loadProfile : ( handle , groupIds , tokenV3 , showPublicStats ) => {
154
191
dispatch ( a . clearProfile ( ) ) ;
155
192
dispatch ( a . loadProfile ( handle ) ) ;
0 commit comments