Skip to content

Commit d5b83fa

Browse files
PROD-3233 #comment This commit sets the tool name based on the currently active tool #time 30m
1 parent edcc130 commit d5b83fa

File tree

11 files changed

+53
-18
lines changed

11 files changed

+53
-18
lines changed

src-ts/.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ module.exports = {
7676
11
7777
],
7878
'import/extensions': 'off',
79+
'import/no-named-default': 'off',
7980
'import/prefer-default-export': 'off',
8081
'indent': [
8182
2,
@@ -105,6 +106,7 @@ module.exports = {
105106
120,
106107
],
107108
'no-extra-boolean-cast': 'off',
109+
'no-nested-ternary': 'off',
108110
'no-null/no-null': 'error',
109111
'no-param-reassign': [
110112
'error',

src-ts/config/constants.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
export enum ToolTitle {
2-
learn = 'Learn',
2+
dev = 'Dev Center',
3+
game = 'Gamification Admin',
34
settings = 'Account Settings',
4-
work = 'Work',
5+
tca = 'Topcoder Academy',
6+
work = 'Self-Service',
57
}
68

79
export const PagePortalId: string = 'page-subheader-portal-el'

src-ts/header/Header.tsx

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1-
import { Dispatch, FC, MutableRefObject, SetStateAction, useContext, useEffect, useRef, useState } from 'react'
1+
import {
2+
Dispatch,
3+
FC,
4+
MutableRefObject,
5+
SetStateAction,
6+
useContext,
7+
useEffect,
8+
useRef,
9+
useState,
10+
} from 'react'
211
import classNames from 'classnames'
312

413
import { EnvironmentConfig, PagePortalId } from '../config'
5-
import { authUrlLogin, authUrlLogout, authUrlSignup, profileContext, ProfileContextData } from '../lib'
14+
import {
15+
authUrlLogin,
16+
authUrlLogout,
17+
authUrlSignup,
18+
profileContext,
19+
ProfileContextData,
20+
routeContext,
21+
RouteContextData,
22+
} from '../lib'
623

724
import UniNavSnippet from './universal-nav-snippet'
825

@@ -11,6 +28,7 @@ declare let tcUniNav: any
1128

1229
const Header: FC = () => {
1330

31+
const { activeToolName }: RouteContextData = useContext(routeContext)
1432
const { profile, initialized: profileReady }: ProfileContextData = useContext(profileContext)
1533
const [ready, setReady]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)
1634
const headerInit: MutableRefObject<boolean> = useRef(false)
@@ -37,8 +55,7 @@ const Header: FC = () => {
3755
signIn() { window.location.href = authUrlLogin() },
3856
signOut() { window.location.href = authUrlLogout },
3957
signUp() { window.location.href = authUrlSignup() },
40-
// TODO: make this dynamic based on the current URL
41-
toolName: 'Topcoder Academy',
58+
toolName: activeToolName,
4259
user: profileReady && profile ? {
4360
handle: profile.handle,
4461
initials: `${profile.firstName.charAt(0)}${profile.lastName.charAt(0)}`,
@@ -47,7 +64,10 @@ const Header: FC = () => {
4764
} : undefined,
4865
},
4966
)
50-
}, [profileReady, profile])
67+
}, [
68+
activeToolName,
69+
profileReady,
70+
profile])
5171

5272
return (
5373
<>

src-ts/header/universal-nav-snippet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function UniNavSnippet(url) {
2626
i.type = 'module'
2727

2828
i.src = a
29-
29+
3030
o.parentNode.insertBefore(i, o)
3131

3232
}(window, document, 'script', url, 'tcUniNav'))

src-ts/lib/functions/authentication-functions/authentication.functions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ configureConnector({
2222
mockToken: undefined,
2323
})
2424

25-
export function getRegistrationSource(activeTool: PlatformRoute | undefined): AuthenticationRegistrationSource | undefined {
25+
export function getRegistrationSource(
26+
activeTool: PlatformRoute | undefined,
27+
): AuthenticationRegistrationSource | undefined {
2628

2729
switch (activeTool?.title) {
2830

2931
// currently, there is no reg source for members
30-
case ToolTitle.learn:
32+
case ToolTitle.tca:
3133
return undefined
3234

3335
// currently, the work tool and the platform

src-ts/lib/route-provider/route-context-data.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { FC, ReactElement } from 'react'
33
import { PlatformRoute } from './platform-route.model'
44

55
export interface RouteContextData {
6+
activeToolName?: string
67
allRoutes: Array<PlatformRoute>
78
getChildren: (parent: string) => Array<PlatformRoute>
89
getChildRoutes: (parent: string) => Array<ReactElement>

src-ts/lib/route-provider/route.provider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ export const RouteProvider: FC<RouteProviderProps> = (props: RouteProviderProps)
7878
? props.rootCustomer
7979
: props.rootMember
8080
const contextData: RouteContextData = {
81+
activeToolName: allRoutes.find(r => routeIsActiveTool(location.pathname, r))?.title,
8182
allRoutes,
82-
getChildRoutes,
8383
getChildren,
84+
getChildRoutes,
8485
getPath,
8586
getPathFromRoute,
8687
getRouteElement,

src-ts/tools/dev-center/dev-center.routes.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import { ToolTitle } from '../../config'
12
import { lazyLoad, LazyLoadedComponent, PlatformRoute } from '../../lib'
23

3-
const GettingStartedGuide: LazyLoadedComponent = lazyLoad(() => import('./dev-center-pages/community-app/getting-started/GettingStartedGuide'))
4-
const DevCenterLandingPage: LazyLoadedComponent = lazyLoad(() => import('./dev-center-pages/community-app/landing-page/DevCenterLandingPage'))
4+
const GettingStartedGuide: LazyLoadedComponent
5+
= lazyLoad(() => import('./dev-center-pages/community-app/getting-started/GettingStartedGuide'))
6+
7+
const DevCenterLandingPage: LazyLoadedComponent
8+
= lazyLoad(() => import('./dev-center-pages/community-app/landing-page/DevCenterLandingPage'))
9+
510
const DevCenter: LazyLoadedComponent = lazyLoad(() => import('./DevCenter'))
611

7-
export const toolTitle: string = 'Dev Center'
12+
export const toolTitle: string = ToolTitle.dev
813

914
export const devCenterRoutes: Array<PlatformRoute> = [
1015
{

src-ts/tools/gamification-admin/GamificationAdmin.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import { FC, useContext } from 'react'
22
import { Outlet, Routes } from 'react-router-dom'
33
import { SWRConfig } from 'swr'
44

5+
import { ToolTitle } from '../../config'
56
import {
67
routeContext,
78
RouteContextData,
89
xhrGetAsync,
910
} from '../../lib'
1011

11-
export const toolTitle: string = 'Gamification Admin'
12+
export const toolTitle: string = ToolTitle.game
1213

1314
const GamificationAdmin: FC<{}> = () => {
1415

src-ts/tools/learn/Learn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99

1010
import { LearnSwr } from './learn-lib'
1111

12-
export const toolTitle: string = ToolTitle.learn
12+
export const toolTitle: string = ToolTitle.tca
1313

1414
const Learn: FC<{}> = () => {
1515

0 commit comments

Comments
 (0)