@@ -19,6 +19,7 @@ import {
1919 authUserSuccess ,
2020 authUserError ,
2121 authLoadTeamMembers ,
22+ authLoadV5UserProfile ,
2223 authClearTeamMembers ,
2324} from "./actions" ;
2425import { decodeToken } from "tc-auth-lib" ;
@@ -34,6 +35,9 @@ export default function withAuthentication(Component) {
3435 teamId,
3536 teamMembersLoaded,
3637 teamMembersLoadingError,
38+ v5UserProfile,
39+ v5UserProfileLoading,
40+ v5UserProfileLoadingError,
3741 } = useSelector ( ( state ) => state . authUser ) ;
3842 const params = useParams ( ) ;
3943
@@ -86,18 +90,37 @@ export default function withAuthentication(Component) {
8690 }
8791 } , [ params . teamId , teamId , dispatch , isLoggedIn ] ) ;
8892
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+
89103 return (
90104 < >
91105 { /* Show loading indicator until we know if user is logged-in or no.
92106 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.
93108 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+ ) }
98119
99120 { /* 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 ) ? (
101124 < Component { ...props } />
102125 ) : null }
103126 </ >
0 commit comments