This repository was archived by the owner on Mar 13, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +63
-12
lines changed
components/LoadingIndicator Expand file tree Collapse file tree 6 files changed +63
-12
lines changed Original file line number Diff line number Diff line change 44 * Optionally shows error.
55 */
66import React from "react" ;
7+ import _ from "lodash" ;
78import PT from "prop-types" ;
89import "./styles.module.scss" ;
910
1011const LoadingIndicator = ( { error } ) => {
1112 return (
12- < div styleName = "loading-indicator" > { ! error ? "Loading..." : error } </ div >
13+ < div styleName = "loading-indicator" >
14+ { ! error ? "Loading..." : _ . get ( error , "response.data.message" ) || error }
15+ </ div >
1316 ) ;
1417} ;
1518
1619LoadingIndicator . propTypes = {
17- error : PT . string ,
20+ error : PT . object ,
1821} ;
1922
2023export default LoadingIndicator ;
Original file line number Diff line number Diff line change 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+ import LoadingIndicator from "../components/LoadingIndicator" ;
9+
10+ export default function withAuthentication ( Component ) {
11+ const AuthenticatedComponent = ( props ) => {
12+ let [ isLoggedIn , setIsLoggedIn ] = useState ( null ) ;
13+ let [ authError , setAuthError ] = useState ( false ) ;
14+
15+ useEffect ( ( ) => {
16+ if ( props . auth ) {
17+ getAuthUserTokens ( )
18+ . then ( ( { tokenV3 } ) => {
19+ if ( ! ! tokenV3 ) {
20+ setIsLoggedIn ( ! ! tokenV3 ) ;
21+ } else {
22+ login ( ) ;
23+ }
24+ } )
25+ . catch ( ( err ) => {
26+ setAuthError ( err ) ;
27+ } ) ;
28+ }
29+ } , [ props . auth ] ) ;
30+
31+ return (
32+ < >
33+ { authError && < LoadingIndicator error = { authError . toString ( ) } /> }
34+ { ! props . auth || ( props . auth && isLoggedIn === true ) ? (
35+ < Component { ...props } />
36+ ) : null }
37+ </ >
38+ ) ;
39+ } ;
40+
41+ return AuthenticatedComponent ;
42+ }
Original file line number Diff line number Diff line change @@ -4,19 +4,22 @@ import { Router } from "@reach/router";
44import MyTeamsList from "./routes/MyTeamsList" ;
55import MyTeamsDetails from "./routes/MyTeamsDetails" ;
66import PositionDetails from "./routes/PositionDetails" ;
7- import ReduxToastr from ' react-redux-toastr'
7+ import ReduxToastr from " react-redux-toastr" ;
88import store from "./store" ;
99import "./styles/main.vendor.scss" ;
1010import styles from "./styles/main.module.scss" ;
1111
1212export default function Root ( ) {
1313 return (
14- < div className = { styles [ ' topcoder-micro-frontends-teams-app' ] } >
14+ < 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
20+ path = "/taas/myteams/:teamId/positions/:positionId"
21+ auth
22+ />
2023 </ Router >
2124
2225 { /* Global config for Toastr popups */ }
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import LoadingIndicator from "components/LoadingIndicator";
1414import TeamSummary from "./components/TeamSummary" ;
1515import TeamMembers from "./components/TeamMembers" ;
1616import TeamPositions from "./components/TeamPositions" ;
17+ import withAuthentication from "../../hoc/withAuthentication" ;
1718import { useAsync } from "react-use" ;
1819
1920const 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 withAuthentication ( MyTeamsDetails ) ;
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import { getMyTeams } from "../../services/teams";
1313import TeamCard from "./components/TeamCard" ;
1414import TeamCardGrid from "./components/TeamCardGrid" ;
1515import LoadingIndicator from "../../components/LoadingIndicator" ;
16+ import withAuthentication from "../../hoc/withAuthentication" ;
1617import { useDebounce } from "react-use" ;
1718import { TEAMS_PER_PAGE } from "constants" ;
1819import "./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 withAuthentication ( MyTeamsList ) ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import LayoutContainer from "components/LayoutContainer";
99import LoadingIndicator from "components/LoadingIndicator" ;
1010import PageHeader from "components/PageHeader" ;
1111import { CANDIDATE_STATUS } from "constants" ;
12+ import withAuthentication from "../../hoc/withAuthentication" ;
1213import PositionCandidates from "./components/PositionCandidates" ;
1314import CandidatesStatusFilter from "./components/CandidatesStatusFilter" ;
1415import { useTeamPositionsState } from "./hooks/useTeamPositionsState" ;
@@ -61,4 +62,4 @@ PositionDetails.propTypes = {
6162 positionId : PT . string ,
6263} ;
6364
64- export default PositionDetails ;
65+ export default withAuthentication ( PositionDetails ) ;
You can’t perform that action at this time.
0 commit comments