Skip to content

Commit 820d8ca

Browse files
committed
fix: error message for topcoder-archive#44
1 parent a2657fc commit 820d8ca

File tree

6 files changed

+53
-10
lines changed

6 files changed

+53
-10
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Authentication
3+
*
4+
* wrap component for authentication
5+
*/
6+
import React, { useCallback, useState, useEffect } from "react";
7+
import { getAuthUserTokens, login } from "@topcoder/micro-frontends-navbar-app";
8+
9+
export default function Authentication(Component) {
10+
11+
const AuthenticatedComponent = (props) => {
12+
let [isLoggedIn, setIsLoggedIn] = useState(null);
13+
14+
useEffect(() => {
15+
if (props.auth) {
16+
getAuthUserTokens()
17+
.then(({ tokenV3 }) => {
18+
if (!!tokenV3) {
19+
setIsLoggedIn(!!tokenV3)
20+
} else {
21+
login()
22+
}
23+
})
24+
}
25+
}, [props.auth]);
26+
27+
return (
28+
<div>
29+
{
30+
(!props.auth || props.auth && isLoggedIn === true)
31+
? <Component { ...props}/>
32+
: null
33+
}
34+
</div>
35+
)
36+
}
37+
38+
return AuthenticatedComponent
39+
}

src/components/LoadingIndicator/index.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
* Optionally shows error.
55
*/
66
import React from "react";
7+
import _ from "lodash";
78
import PT from "prop-types";
89
import "./styles.module.scss";
910

1011
const LoadingIndicator = ({ error }) => {
1112
return (
12-
<div styleName="loading-indicator">{!error ? "Loading..." : error}</div>
13+
<div styleName="loading-indicator">{!error ? "Loading..." : _.get(error, 'response.data.message') || error}</div>
1314
);
1415
};
1516

1617
LoadingIndicator.propTypes = {
17-
error: PT.string,
18+
error: PT.object,
1819
};
1920

2021
export default LoadingIndicator;

src/root.component.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ export default function Root() {
1414
<div className={styles['topcoder-micro-frontends-teams-app']}>
1515
<Provider store={store}>
1616
<Router>
17-
<MyTeamsList path="/taas/myteams" />
18-
<MyTeamsDetails path="/taas/myteams/:teamId" />
19-
<PositionDetails path="/taas/myteams/:teamId/positions/:positionId" />
17+
<MyTeamsList path="/taas/myteams" auth/>
18+
<MyTeamsDetails path="/taas/myteams/:teamId" auth />
19+
<PositionDetails path="/taas/myteams/:teamId/positions/:positionId" auth/>
2020
</Router>
2121

2222
{/* Global config for Toastr popups */}

src/routes/MyTeamsDetails/index.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import LoadingIndicator from "components/LoadingIndicator";
1414
import TeamSummary from "./components/TeamSummary";
1515
import TeamMembers from "./components/TeamMembers";
1616
import TeamPositions from "./components/TeamPositions";
17+
import Authentication from '../../components/Authentication'
1718
import { useAsync } from "react-use";
1819

1920
const MyTeamsDetails = ({ teamId }) => {
@@ -22,7 +23,7 @@ const MyTeamsDetails = ({ teamId }) => {
2223
return (
2324
<LayoutContainer>
2425
{!team ? (
25-
<LoadingIndicator error={loadingError && loadingError.toString()} />
26+
<LoadingIndicator error={loadingError} />
2627
) : (
2728
<>
2829
<PageHeader title={team.name} backTo="/taas/myteams" />
@@ -39,4 +40,4 @@ MyTeamsDetails.propTypes = {
3940
teamId: PT.string,
4041
};
4142

42-
export default MyTeamsDetails;
43+
export default Authentication(MyTeamsDetails);

src/routes/MyTeamsList/index.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { getMyTeams } from "../../services/teams";
1313
import TeamCard from "./components/TeamCard";
1414
import TeamCardGrid from "./components/TeamCardGrid";
1515
import LoadingIndicator from "../../components/LoadingIndicator";
16+
import Authentication from '../../components/Authentication'
1617
import { useDebounce } from "react-use";
1718
import { TEAMS_PER_PAGE } from "constants";
1819
import "./styles.module.scss";
@@ -74,7 +75,7 @@ const MyTeamsList = () => {
7475
<div styleName="empty">No teams found</div>
7576
)}
7677
{!myTeams ? (
77-
<LoadingIndicator error={loadingError && loadingError.toString()} />
78+
<LoadingIndicator error={loadingError} />
7879
) : (
7980
<>
8081
<TeamCardGrid>
@@ -98,4 +99,4 @@ const MyTeamsList = () => {
9899
);
99100
};
100101

101-
export default MyTeamsList;
102+
export default Authentication(MyTeamsList);

src/routes/PositionDetails/index.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import LayoutContainer from "components/LayoutContainer";
99
import LoadingIndicator from "components/LoadingIndicator";
1010
import PageHeader from "components/PageHeader";
1111
import { CANDIDATE_STATUS } from "constants";
12+
import Authentication from '../../components/Authentication'
1213
import PositionCandidates from "./components/PositionCandidates";
1314
import CandidatesStatusFilter from "./components/CandidatesStatusFilter";
1415
import { useTeamPositionsState } from "./hooks/useTeamPositionsState";
@@ -61,4 +62,4 @@ PositionDetails.propTypes = {
6162
positionId: PT.string,
6263
};
6364

64-
export default PositionDetails;
65+
export default Authentication(PositionDetails);

0 commit comments

Comments
 (0)