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

[PROD] Patch 1.7.0.1 #270

Merged
merged 5 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: issue #112
  • Loading branch information
yoution committed May 18, 2021
commit fabceaee48a40f1e7880d60dbae6a0fb490569f7
6 changes: 3 additions & 3 deletions src/hoc/withAuthentication/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Auth User actions
*/
import { ACTION_TYPE } from "constants";
import { getTeamMembers, getUserProfile } from "services/teams";
import { getTeamMembers, getV5UserProfile } from "services/teams";

/**
* Action to set auth user data
Expand Down Expand Up @@ -45,10 +45,10 @@ export const authLoadTeamMembers = (teamId) => ({
*
* @returns {Promise} loaded user profile
*/
export const authLoadUserProfile = () => ({
export const authLoadV5UserProfile = () => ({
type: ACTION_TYPE.AUTH_LOAD_V5_USER_PROFILE,
payload: async () => {
const res = await getUserProfile();
const res = await getV5UserProfile();
return res.data;
},
});
Expand Down
14 changes: 6 additions & 8 deletions src/hoc/withAuthentication/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
authUserSuccess,
authUserError,
authLoadTeamMembers,
authLoadUserProfile,
authLoadV5UserProfile,
authClearTeamMembers,
} from "./actions";
import { decodeToken } from "tc-auth-lib";
Expand All @@ -36,6 +36,7 @@ export default function withAuthentication(Component) {
teamMembersLoaded,
teamMembersLoadingError,
v5UserProfile,
v5UserProfileLoading,
v5UserProfileLoadingError,
} = useSelector((state) => state.authUser);
const params = useParams();
Expand Down Expand Up @@ -91,24 +92,21 @@ export default function withAuthentication(Component) {

useEffect(() => {
if (isLoggedIn) {
dispatch(authLoadUserProfile());
dispatch(authLoadV5UserProfile());
}
}, [dispatch, isLoggedIn]);

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

{/* Show component only if v5 user profile load error */}
{isLoggedIn === true && v5UserProfileLoadingError && (
<LoadingIndicator error={v5UserProfileLoadingError} />
)}
{/* Show component only if user is logged-in and if we don't need team members or we already loaded them */}
{isLoggedIn === true &&
v5UserProfile &&
Expand Down
9 changes: 9 additions & 0 deletions src/hoc/withAuthentication/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const initialState = {
teamMembersLoadingError: undefined,
teamMembersLoaded: false,
v5UserProfile: undefined,
v5UserProfileLoading: false,
v5UserProfileLoadingError: false,
};

Expand Down Expand Up @@ -97,17 +98,25 @@ const reducer = (state = initialState, action) => {
};
}

case ACTION_TYPE.AUTH_LOAD_V5_USER_PROFILE_PENDING: {
return {
...state,
v5UserProfileLoading: true,
};
}
case ACTION_TYPE.AUTH_LOAD_V5_USER_PROFILE_SUCCESS: {
return {
...state,
v5UserProfile: action.payload,
v5UserProfileLoading: false,
v5UserProfileLoadingError: false,
};
}
case ACTION_TYPE.AUTH_LOAD_V5_USER_PROFILE_ERROR: {
return {
...state,
v5UserProfileLoadingError: action.payload,
v5UserProfileLoading: false,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const getMyTeams = (name, page = 1, perPage) => {
*
* @returns {Promise<{}>} user profile object
*/
export const getUserProfile = () => {
export const getV5UserProfile = () => {
return axios.get(`${config.API.V5}/taas-teams/me`);
};

Expand Down