@@ -19,6 +19,7 @@ import {
19
19
authUserSuccess ,
20
20
authUserError ,
21
21
authLoadTeamMembers ,
22
+ authLoadV5UserProfile ,
22
23
authClearTeamMembers ,
23
24
} from "./actions" ;
24
25
import { decodeToken } from "tc-auth-lib" ;
@@ -34,6 +35,9 @@ export default function withAuthentication(Component) {
34
35
teamId,
35
36
teamMembersLoaded,
36
37
teamMembersLoadingError,
38
+ v5UserProfile,
39
+ v5UserProfileLoading,
40
+ v5UserProfileLoadingError,
37
41
} = useSelector ( ( state ) => state . authUser ) ;
38
42
const params = useParams ( ) ;
39
43
@@ -86,18 +90,37 @@ export default function withAuthentication(Component) {
86
90
}
87
91
} , [ params . teamId , teamId , dispatch , isLoggedIn ] ) ;
88
92
93
+ /*
94
+ Load V5 User Profile
95
+ */
96
+ useEffect ( ( ) => {
97
+ // is user is logged-in, but V5 user profile is not loaded yet, then load it
98
+ if ( isLoggedIn && ! v5UserProfileLoading && ! v5UserProfile ) {
99
+ dispatch ( authLoadV5UserProfile ( ) ) ;
100
+ }
101
+ } , [ dispatch , isLoggedIn , v5UserProfileLoading , v5UserProfile ] ) ;
102
+
89
103
return (
90
104
< >
91
105
{ /* Show loading indicator until we know if user is logged-in or no.
92
106
Also, show loading indicator if we need to know team members but haven't loaded them yet.
107
+ or load v5 user profile but haven't loaded them yet.
93
108
In we got error during this process, show error */ }
94
- { isLoggedIn === null ||
95
- ( params . teamId && ! teamMembersLoaded && (
96
- < LoadingIndicator error = { authError || teamMembersLoadingError } />
97
- ) ) }
109
+ { ( isLoggedIn === null ||
110
+ ( params . teamId && ! teamMembersLoaded ) ||
111
+ v5UserProfileLoading ||
112
+ v5UserProfileLoadingError ) && (
113
+ < LoadingIndicator
114
+ error = {
115
+ authError || teamMembersLoadingError || v5UserProfileLoadingError
116
+ }
117
+ />
118
+ ) }
98
119
99
120
{ /* Show component only if user is logged-in and if we don't need team members or we already loaded them */ }
100
- { isLoggedIn === true && ( ! params . teamId || teamMembersLoaded ) ? (
121
+ { isLoggedIn === true &&
122
+ v5UserProfile &&
123
+ ( ! params . teamId || teamMembersLoaded ) ? (
101
124
< Component { ...props } />
102
125
) : null }
103
126
</ >
0 commit comments