Skip to content

Commit ef495ae

Browse files
Merge pull request #422 from topcoder-platform/PROD-3233_dynamic-tool
PROD-3233 Set the Tool Name to Active Route Name ->PROD-3115_uni-nav
2 parents 1f6f094 + d5b83fa commit ef495ae

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

@@ -12,6 +29,7 @@ UniNavSnippet(EnvironmentConfig.UNIVERSAL_NAV.URL)
1229

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

32+
const { activeToolName }: RouteContextData = useContext(routeContext)
1533
const { profile, initialized: profileReady }: ProfileContextData = useContext(profileContext)
1634
const [ready, setReady]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)
1735
const headerInit: MutableRefObject<boolean> = useRef(false)
@@ -36,8 +54,7 @@ const Header: FC = () => {
3654
signIn() { window.location.href = authUrlLogin() },
3755
signOut() { window.location.href = authUrlLogout },
3856
signUp() { window.location.href = authUrlSignup() },
39-
// TODO: make this dynamic based on the current URL
40-
toolName: 'Topcoder Academy',
57+
toolName: activeToolName,
4158
user: profileReady && profile ? {
4259
handle: profile.handle,
4360
initials: `${profile.firstName.charAt(0)}${profile.lastName.charAt(0)}`,
@@ -46,7 +63,10 @@ const Header: FC = () => {
4663
} : undefined,
4764
},
4865
)
49-
}, [profileReady, profile])
66+
}, [
67+
activeToolName,
68+
profileReady,
69+
profile])
5070

5171
return (
5272
<>

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

src-ts/tools/work/work.routes.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const WorkNotLoggedIn: LazyLoadedComponent = lazyLoad(() => import('./work-not-l
1212
const BugHuntIntakeForm: LazyLoadedComponent = lazyLoad(() => import('./work-self-service'), 'BugHuntIntakeForm')
1313
const IntakeForms: LazyLoadedComponent = lazyLoad(() => import('./work-self-service'), 'IntakeForms')
1414
const Review: LazyLoadedComponent = lazyLoad(() => import('./work-self-service'), 'Review')
15-
const SaveAfterLogin: LazyLoadedComponent = lazyLoad(() => import('./work-self-service/intake-forms/save-after-login/SaveAfterLogin'))
15+
const SaveAfterLogin: LazyLoadedComponent
16+
= lazyLoad(() => import('./work-self-service/intake-forms/save-after-login/SaveAfterLogin'))
1617
const WorkTable: LazyLoadedComponent = lazyLoad(() => import('./work-table'), 'WorkTable')
1718
const WorkThankYou: LazyLoadedComponent = lazyLoad(() => import('./work-thank-you'), 'WorkThankYou')
1819

@@ -45,7 +46,7 @@ export function workDetailOrDraftRoute(selectedWork: Work): string {
4546
}
4647

4748
export function workDetailRoute(workId: string, tab?: 'solutions' | 'messages'): string {
48-
return `${selfServiceRootRoute}/work-items/${workId}${!!tab ? `\?tab=${tab}` : ''}`
49+
return `${selfServiceRootRoute}/work-items/${workId}${!!tab ? `?tab=${tab}` : ''}`
4950
}
5051

5152
export const workRoutes: Array<PlatformRoute> = [

0 commit comments

Comments
 (0)