diff --git a/src-ts/.eslintrc.js b/src-ts/.eslintrc.js index ce2af1929..c54020a0f 100644 --- a/src-ts/.eslintrc.js +++ b/src-ts/.eslintrc.js @@ -76,6 +76,7 @@ module.exports = { 11 ], 'import/extensions': 'off', + 'import/no-named-default': 'off', 'import/prefer-default-export': 'off', 'indent': [ 2, @@ -105,6 +106,7 @@ module.exports = { 120, ], 'no-extra-boolean-cast': 'off', + 'no-nested-ternary': 'off', 'no-null/no-null': 'error', 'no-param-reassign': [ 'error', diff --git a/src-ts/config/constants.ts b/src-ts/config/constants.ts index 140ff4721..89e4094d6 100644 --- a/src-ts/config/constants.ts +++ b/src-ts/config/constants.ts @@ -1,7 +1,9 @@ export enum ToolTitle { - learn = 'Learn', + dev = 'Dev Center', + game = 'Gamification Admin', settings = 'Account Settings', - work = 'Work', + tca = 'Topcoder Academy', + work = 'Self-Service', } export const PagePortalId: string = 'page-subheader-portal-el' diff --git a/src-ts/header/Header.tsx b/src-ts/header/Header.tsx index 176b288e6..44e1b2a38 100644 --- a/src-ts/header/Header.tsx +++ b/src-ts/header/Header.tsx @@ -1,8 +1,25 @@ -import { Dispatch, FC, MutableRefObject, SetStateAction, useContext, useEffect, useRef, useState } from 'react' +import { + Dispatch, + FC, + MutableRefObject, + SetStateAction, + useContext, + useEffect, + useRef, + useState, +} from 'react' import classNames from 'classnames' import { EnvironmentConfig, PagePortalId } from '../config' -import { authUrlLogin, authUrlLogout, authUrlSignup, profileContext, ProfileContextData } from '../lib' +import { + authUrlLogin, + authUrlLogout, + authUrlSignup, + profileContext, + ProfileContextData, + routeContext, + RouteContextData, +} from '../lib' import UniNavSnippet from './universal-nav-snippet' @@ -11,6 +28,7 @@ declare let tcUniNav: any const Header: FC = () => { + const { activeToolName }: RouteContextData = useContext(routeContext) const { profile, initialized: profileReady }: ProfileContextData = useContext(profileContext) const [ready, setReady]: [boolean, Dispatch>] = useState(false) const headerInit: MutableRefObject = useRef(false) @@ -37,8 +55,7 @@ const Header: FC = () => { signIn() { window.location.href = authUrlLogin() }, signOut() { window.location.href = authUrlLogout }, signUp() { window.location.href = authUrlSignup() }, - // TODO: make this dynamic based on the current URL - toolName: 'Topcoder Academy', + toolName: activeToolName, user: profileReady && profile ? { handle: profile.handle, initials: `${profile.firstName.charAt(0)}${profile.lastName.charAt(0)}`, @@ -47,7 +64,10 @@ const Header: FC = () => { } : undefined, }, ) - }, [profileReady, profile]) + }, [ + activeToolName, + profileReady, + profile]) return ( <> diff --git a/src-ts/header/universal-nav-snippet.js b/src-ts/header/universal-nav-snippet.js index 3e9d97efc..9cc91496f 100644 --- a/src-ts/header/universal-nav-snippet.js +++ b/src-ts/header/universal-nav-snippet.js @@ -26,7 +26,7 @@ function UniNavSnippet(url) { i.type = 'module' i.src = a - + o.parentNode.insertBefore(i, o) }(window, document, 'script', url, 'tcUniNav')) diff --git a/src-ts/lib/functions/authentication-functions/authentication.functions.ts b/src-ts/lib/functions/authentication-functions/authentication.functions.ts index bd560c73e..e887b6c5c 100644 --- a/src-ts/lib/functions/authentication-functions/authentication.functions.ts +++ b/src-ts/lib/functions/authentication-functions/authentication.functions.ts @@ -22,12 +22,14 @@ configureConnector({ mockToken: undefined, }) -export function getRegistrationSource(activeTool: PlatformRoute | undefined): AuthenticationRegistrationSource | undefined { +export function getRegistrationSource( + activeTool: PlatformRoute | undefined, +): AuthenticationRegistrationSource | undefined { switch (activeTool?.title) { // currently, there is no reg source for members - case ToolTitle.learn: + case ToolTitle.tca: return undefined // currently, the work tool and the platform diff --git a/src-ts/lib/route-provider/route-context-data.model.ts b/src-ts/lib/route-provider/route-context-data.model.ts index d6794a94a..8b2c18416 100644 --- a/src-ts/lib/route-provider/route-context-data.model.ts +++ b/src-ts/lib/route-provider/route-context-data.model.ts @@ -3,6 +3,7 @@ import { FC, ReactElement } from 'react' import { PlatformRoute } from './platform-route.model' export interface RouteContextData { + activeToolName?: string allRoutes: Array getChildren: (parent: string) => Array getChildRoutes: (parent: string) => Array diff --git a/src-ts/lib/route-provider/route.provider.tsx b/src-ts/lib/route-provider/route.provider.tsx index ae8555fe7..a0736393c 100644 --- a/src-ts/lib/route-provider/route.provider.tsx +++ b/src-ts/lib/route-provider/route.provider.tsx @@ -78,9 +78,10 @@ export const RouteProvider: FC = (props: RouteProviderProps) ? props.rootCustomer : props.rootMember const contextData: RouteContextData = { + activeToolName: allRoutes.find(r => routeIsActiveTool(location.pathname, r))?.title, allRoutes, - getChildRoutes, getChildren, + getChildRoutes, getPath, getPathFromRoute, getRouteElement, diff --git a/src-ts/tools/dev-center/dev-center.routes.tsx b/src-ts/tools/dev-center/dev-center.routes.tsx index f2e1cb5cb..6fd7d4fb4 100644 --- a/src-ts/tools/dev-center/dev-center.routes.tsx +++ b/src-ts/tools/dev-center/dev-center.routes.tsx @@ -1,10 +1,15 @@ +import { ToolTitle } from '../../config' import { lazyLoad, LazyLoadedComponent, PlatformRoute } from '../../lib' -const GettingStartedGuide: LazyLoadedComponent = lazyLoad(() => import('./dev-center-pages/community-app/getting-started/GettingStartedGuide')) -const DevCenterLandingPage: LazyLoadedComponent = lazyLoad(() => import('./dev-center-pages/community-app/landing-page/DevCenterLandingPage')) +const GettingStartedGuide: LazyLoadedComponent + = lazyLoad(() => import('./dev-center-pages/community-app/getting-started/GettingStartedGuide')) + +const DevCenterLandingPage: LazyLoadedComponent + = lazyLoad(() => import('./dev-center-pages/community-app/landing-page/DevCenterLandingPage')) + const DevCenter: LazyLoadedComponent = lazyLoad(() => import('./DevCenter')) -export const toolTitle: string = 'Dev Center' +export const toolTitle: string = ToolTitle.dev export const devCenterRoutes: Array = [ { diff --git a/src-ts/tools/gamification-admin/GamificationAdmin.tsx b/src-ts/tools/gamification-admin/GamificationAdmin.tsx index 841ebb412..40fb9da7d 100644 --- a/src-ts/tools/gamification-admin/GamificationAdmin.tsx +++ b/src-ts/tools/gamification-admin/GamificationAdmin.tsx @@ -2,13 +2,14 @@ import { FC, useContext } from 'react' import { Outlet, Routes } from 'react-router-dom' import { SWRConfig } from 'swr' +import { ToolTitle } from '../../config' import { routeContext, RouteContextData, xhrGetAsync, } from '../../lib' -export const toolTitle: string = 'Gamification Admin' +export const toolTitle: string = ToolTitle.game const GamificationAdmin: FC<{}> = () => { diff --git a/src-ts/tools/learn/Learn.tsx b/src-ts/tools/learn/Learn.tsx index 4175dcfc3..172087f6d 100644 --- a/src-ts/tools/learn/Learn.tsx +++ b/src-ts/tools/learn/Learn.tsx @@ -9,7 +9,7 @@ import { import { LearnSwr } from './learn-lib' -export const toolTitle: string = ToolTitle.learn +export const toolTitle: string = ToolTitle.tca const Learn: FC<{}> = () => { diff --git a/src-ts/tools/work/work.routes.tsx b/src-ts/tools/work/work.routes.tsx index 9fb63e965..f4b3e62e5 100644 --- a/src-ts/tools/work/work.routes.tsx +++ b/src-ts/tools/work/work.routes.tsx @@ -12,7 +12,8 @@ const WorkNotLoggedIn: LazyLoadedComponent = lazyLoad(() => import('./work-not-l const BugHuntIntakeForm: LazyLoadedComponent = lazyLoad(() => import('./work-self-service'), 'BugHuntIntakeForm') const IntakeForms: LazyLoadedComponent = lazyLoad(() => import('./work-self-service'), 'IntakeForms') const Review: LazyLoadedComponent = lazyLoad(() => import('./work-self-service'), 'Review') -const SaveAfterLogin: LazyLoadedComponent = lazyLoad(() => import('./work-self-service/intake-forms/save-after-login/SaveAfterLogin')) +const SaveAfterLogin: LazyLoadedComponent + = lazyLoad(() => import('./work-self-service/intake-forms/save-after-login/SaveAfterLogin')) const WorkTable: LazyLoadedComponent = lazyLoad(() => import('./work-table'), 'WorkTable') const WorkThankYou: LazyLoadedComponent = lazyLoad(() => import('./work-thank-you'), 'WorkThankYou') @@ -45,7 +46,7 @@ export function workDetailOrDraftRoute(selectedWork: Work): string { } export function workDetailRoute(workId: string, tab?: 'solutions' | 'messages'): string { - return `${selfServiceRootRoute}/work-items/${workId}${!!tab ? `\?tab=${tab}` : ''}` + return `${selfServiceRootRoute}/work-items/${workId}${!!tab ? `?tab=${tab}` : ''}` } export const workRoutes: Array = [