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 +53
-10
lines changed Expand file tree Collapse file tree 6 files changed +53
-10
lines changed 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
+
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
+ }
Original file line number Diff line number Diff line change 4
4
* Optionally shows error.
5
5
*/
6
6
import React from "react" ;
7
+ import _ from "lodash" ;
7
8
import PT from "prop-types" ;
8
9
import "./styles.module.scss" ;
9
10
10
11
const LoadingIndicator = ( { error } ) => {
11
12
return (
12
- < div styleName = "loading-indicator" > { ! error ? "Loading..." : error } </ div >
13
+ < div styleName = "loading-indicator" > { ! error ? "Loading..." : _ . get ( error , 'response.data.message' ) || error } </ div >
13
14
) ;
14
15
} ;
15
16
16
17
LoadingIndicator . propTypes = {
17
- error : PT . string ,
18
+ error : PT . object ,
18
19
} ;
19
20
20
21
export default LoadingIndicator ;
Original file line number Diff line number Diff line change @@ -14,9 +14,9 @@ export default function Root() {
14
14
< div className = { styles [ 'topcoder-micro-frontends-teams-app' ] } >
15
15
< Provider store = { store } >
16
16
< 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 />
20
20
</ Router >
21
21
22
22
{ /* Global config for Toastr popups */ }
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import LoadingIndicator from "components/LoadingIndicator";
14
14
import TeamSummary from "./components/TeamSummary" ;
15
15
import TeamMembers from "./components/TeamMembers" ;
16
16
import TeamPositions from "./components/TeamPositions" ;
17
+ import Authentication from '../../components/Authentication'
17
18
import { useAsync } from "react-use" ;
18
19
19
20
const MyTeamsDetails = ( { teamId } ) => {
@@ -22,7 +23,7 @@ const MyTeamsDetails = ({ teamId }) => {
22
23
return (
23
24
< LayoutContainer >
24
25
{ ! team ? (
25
- < LoadingIndicator error = { loadingError && loadingError . toString ( ) } />
26
+ < LoadingIndicator error = { loadingError } />
26
27
) : (
27
28
< >
28
29
< PageHeader title = { team . name } backTo = "/taas/myteams" />
@@ -39,4 +40,4 @@ MyTeamsDetails.propTypes = {
39
40
teamId : PT . string ,
40
41
} ;
41
42
42
- export default MyTeamsDetails ;
43
+ export default Authentication ( MyTeamsDetails ) ;
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import { getMyTeams } from "../../services/teams";
13
13
import TeamCard from "./components/TeamCard" ;
14
14
import TeamCardGrid from "./components/TeamCardGrid" ;
15
15
import LoadingIndicator from "../../components/LoadingIndicator" ;
16
+ import Authentication from '../../components/Authentication'
16
17
import { useDebounce } from "react-use" ;
17
18
import { TEAMS_PER_PAGE } from "constants" ;
18
19
import "./styles.module.scss" ;
@@ -74,7 +75,7 @@ const MyTeamsList = () => {
74
75
< div styleName = "empty" > No teams found</ div >
75
76
) }
76
77
{ ! myTeams ? (
77
- < LoadingIndicator error = { loadingError && loadingError . toString ( ) } />
78
+ < LoadingIndicator error = { loadingError } />
78
79
) : (
79
80
< >
80
81
< TeamCardGrid >
@@ -98,4 +99,4 @@ const MyTeamsList = () => {
98
99
) ;
99
100
} ;
100
101
101
- export default MyTeamsList ;
102
+ export default Authentication ( MyTeamsList ) ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import LayoutContainer from "components/LayoutContainer";
9
9
import LoadingIndicator from "components/LoadingIndicator" ;
10
10
import PageHeader from "components/PageHeader" ;
11
11
import { CANDIDATE_STATUS } from "constants" ;
12
+ import Authentication from '../../components/Authentication'
12
13
import PositionCandidates from "./components/PositionCandidates" ;
13
14
import CandidatesStatusFilter from "./components/CandidatesStatusFilter" ;
14
15
import { useTeamPositionsState } from "./hooks/useTeamPositionsState" ;
@@ -61,4 +62,4 @@ PositionDetails.propTypes = {
61
62
positionId : PT . string ,
62
63
} ;
63
64
64
- export default PositionDetails ;
65
+ export default Authentication ( PositionDetails ) ;
You can’t perform that action at this time.
0 commit comments