Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit fabceae

Browse files
committed
fix: issue #112
1 parent 17ffacd commit fabceae

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

src/hoc/withAuthentication/actions/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Auth User actions
33
*/
44
import { ACTION_TYPE } from "constants";
5-
import { getTeamMembers, getUserProfile } from "services/teams";
5+
import { getTeamMembers, getV5UserProfile } from "services/teams";
66

77
/**
88
* Action to set auth user data
@@ -45,10 +45,10 @@ export const authLoadTeamMembers = (teamId) => ({
4545
*
4646
* @returns {Promise} loaded user profile
4747
*/
48-
export const authLoadUserProfile = () => ({
48+
export const authLoadV5UserProfile = () => ({
4949
type: ACTION_TYPE.AUTH_LOAD_V5_USER_PROFILE,
5050
payload: async () => {
51-
const res = await getUserProfile();
51+
const res = await getV5UserProfile();
5252
return res.data;
5353
},
5454
});

src/hoc/withAuthentication/index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
authUserSuccess,
2020
authUserError,
2121
authLoadTeamMembers,
22-
authLoadUserProfile,
22+
authLoadV5UserProfile,
2323
authClearTeamMembers,
2424
} from "./actions";
2525
import { decodeToken } from "tc-auth-lib";
@@ -36,6 +36,7 @@ export default function withAuthentication(Component) {
3636
teamMembersLoaded,
3737
teamMembersLoadingError,
3838
v5UserProfile,
39+
v5UserProfileLoading,
3940
v5UserProfileLoadingError,
4041
} = useSelector((state) => state.authUser);
4142
const params = useParams();
@@ -91,24 +92,21 @@ export default function withAuthentication(Component) {
9192

9293
useEffect(() => {
9394
if (isLoggedIn) {
94-
dispatch(authLoadUserProfile());
95+
dispatch(authLoadV5UserProfile());
9596
}
9697
}, [dispatch, isLoggedIn]);
9798

9899
return (
99100
<>
100101
{/* Show loading indicator until we know if user is logged-in or no.
101102
Also, show loading indicator if we need to know team members but haven't loaded them yet.
103+
or load v5 user profile but haven't loaded them yet.
102104
In we got error during this process, show error */}
103105
{isLoggedIn === null ||
104-
(params.teamId && !teamMembersLoaded && (
105-
<LoadingIndicator error={authError || teamMembersLoadingError} />
106+
((params.teamId && !teamMembersLoaded || v5UserProfileLoading || v5UserProfileLoadingError)&& (
107+
<LoadingIndicator error={authError || teamMembersLoadingError || v5UserProfileLoadingError} />
106108
))}
107109

108-
{/* Show component only if v5 user profile load error */}
109-
{isLoggedIn === true && v5UserProfileLoadingError && (
110-
<LoadingIndicator error={v5UserProfileLoadingError} />
111-
)}
112110
{/* Show component only if user is logged-in and if we don't need team members or we already loaded them */}
113111
{isLoggedIn === true &&
114112
v5UserProfile &&

src/hoc/withAuthentication/reducers/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const initialState = {
1717
teamMembersLoadingError: undefined,
1818
teamMembersLoaded: false,
1919
v5UserProfile: undefined,
20+
v5UserProfileLoading: false,
2021
v5UserProfileLoadingError: false,
2122
};
2223

@@ -97,17 +98,25 @@ const reducer = (state = initialState, action) => {
9798
};
9899
}
99100

101+
case ACTION_TYPE.AUTH_LOAD_V5_USER_PROFILE_PENDING: {
102+
return {
103+
...state,
104+
v5UserProfileLoading: true,
105+
};
106+
}
100107
case ACTION_TYPE.AUTH_LOAD_V5_USER_PROFILE_SUCCESS: {
101108
return {
102109
...state,
103110
v5UserProfile: action.payload,
111+
v5UserProfileLoading: false,
104112
v5UserProfileLoadingError: false,
105113
};
106114
}
107115
case ACTION_TYPE.AUTH_LOAD_V5_USER_PROFILE_ERROR: {
108116
return {
109117
...state,
110118
v5UserProfileLoadingError: action.payload,
119+
v5UserProfileLoading: false,
111120
};
112121
}
113122

src/services/teams.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const getMyTeams = (name, page = 1, perPage) => {
2727
*
2828
* @returns {Promise<{}>} user profile object
2929
*/
30-
export const getUserProfile = () => {
30+
export const getV5UserProfile = () => {
3131
return axios.get(`${config.API.V5}/taas-teams/me`);
3232
};
3333

0 commit comments

Comments
 (0)