Skip to content

Commit 1f6f094

Browse files
Merge pull request #421 from topcoder-platform/PROD-3232_integrate-nav
PROD-3232 Adds the uni nav snippet -> PROD-3115_uni-nav
2 parents a16cacd + 8cba9e3 commit 1f6f094

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+134
-782
lines changed

src-ts/config/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ export enum ToolTitle {
33
settings = 'Account Settings',
44
work = 'Work',
55
}
6+
7+
export const PagePortalId: string = 'page-subheader-portal-el'

src-ts/config/environments/environment.default.config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export const EnvironmentConfigDefault: EnvironmentConfigModel = {
1414
V3: 'https://api.topcoder-dev.com/v3',
1515
V5: 'https://api.topcoder-dev.com/v5',
1616
},
17+
AUTH: {
18+
ACCOUNTS_APP_CONNECTOR: 'https://accounts-auth0.topcoder-dev.com',
19+
},
1720
ENV: 'default',
1821
LOGGING: {
1922
PUBLIC_TOKEN: 'puba0825671e469d16f940c5a30dc738f11',
@@ -38,7 +41,7 @@ export const EnvironmentConfigDefault: EnvironmentConfigModel = {
3841
USER_PROFILE: `${COMMUNITY_WEBSITE}/members`,
3942
WP_CONTENT: `${COMMUNITY_WEBSITE}/wp-content`,
4043
},
41-
URL: {
42-
ACCOUNTS_APP_CONNECTOR: 'https://accounts-auth0.topcoder-dev.com',
44+
UNIVERSAL_NAV: {
45+
URL: 'https://uni-nav.topcoder-dev.com/tc-universal-nav.js',
4346
},
4447
}

src-ts/config/environments/environment.prod.config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export const EnvironmentConfigProd: EnvironmentConfigModel = {
1616
V3: 'https://api.topcoder.com/v3',
1717
V5: 'https://api.topcoder.com/v5',
1818
},
19+
AUTH: {
20+
ACCOUNTS_APP_CONNECTOR: 'https://accounts-auth0.topcoder.com',
21+
},
1922
DISABLED_TOOLS: [],
2023
ENV: 'prod',
2124
// TODO: Move stripe creds to .env file
@@ -36,7 +39,7 @@ export const EnvironmentConfigProd: EnvironmentConfigModel = {
3639
USER_PROFILE: `${COMMUNITY_WEBSITE}/members`,
3740
WP_CONTENT: `${COMMUNITY_WEBSITE}/wp-content`,
3841
},
39-
URL: {
40-
ACCOUNTS_APP_CONNECTOR: 'https://accounts-auth0.topcoder.com',
42+
UNIVERSAL_NAV: {
43+
URL: 'https://uni-nav.topcoder.com/tc-universal-nav.js',
4144
},
4245
}

src-ts/header/Header.module.scss

Lines changed: 0 additions & 31 deletions
This file was deleted.

src-ts/header/Header.tsx

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,62 @@
1-
import { FC } from 'react'
2-
3-
import { Logo } from './logo'
4-
import { ToolSelectors } from './tool-selectors'
5-
import { UtilitySelectors } from './utility-selectors'
6-
import styles from './Header.module.scss'
7-
8-
const Header: FC<{}> = () => (
9-
<div className={styles['header-wrap']}>
10-
<header className={styles.header}>
11-
<ToolSelectors isWide={false} />
12-
<Logo />
13-
<ToolSelectors isWide />
14-
<UtilitySelectors />
15-
</header>
16-
<div id='page-subheader-portal-el' className={styles.subheader} />
17-
</div>
18-
)
1+
import { Dispatch, FC, MutableRefObject, SetStateAction, useContext, useEffect, useRef, useState } from 'react'
2+
import classNames from 'classnames'
3+
4+
import { EnvironmentConfig, PagePortalId } from '../config'
5+
import { authUrlLogin, authUrlLogout, authUrlSignup, profileContext, ProfileContextData } from '../lib'
6+
7+
import UniNavSnippet from './universal-nav-snippet'
8+
9+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
10+
declare let tcUniNav: any
11+
UniNavSnippet(EnvironmentConfig.UNIVERSAL_NAV.URL)
12+
13+
const Header: FC = () => {
14+
15+
const { profile, initialized: profileReady }: ProfileContextData = useContext(profileContext)
16+
const [ready, setReady]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)
17+
const headerInit: MutableRefObject<boolean> = useRef(false)
18+
const navElementId: string = 'main-nav-el'
19+
20+
useEffect(() => {
21+
22+
if (headerInit.current || !profileReady || !tcUniNav) {
23+
return
24+
}
25+
26+
headerInit.current = true
27+
28+
tcUniNav(
29+
'tool',
30+
navElementId,
31+
{
32+
onReady() {
33+
setReady(true)
34+
document.getElementById('root')?.classList.add('app-ready')
35+
},
36+
signIn() { window.location.href = authUrlLogin() },
37+
signOut() { window.location.href = authUrlLogout },
38+
signUp() { window.location.href = authUrlSignup() },
39+
// TODO: make this dynamic based on the current URL
40+
toolName: 'Topcoder Academy',
41+
user: profileReady && profile ? {
42+
handle: profile.handle,
43+
initials: `${profile.firstName.charAt(0)}${profile.lastName.charAt(0)}`,
44+
photoURL: profile.photoURL,
45+
userId: profile.userId,
46+
} : undefined,
47+
},
48+
)
49+
}, [profileReady, profile])
50+
51+
return (
52+
<>
53+
<div id={navElementId} />
54+
<div
55+
id={PagePortalId}
56+
className={classNames('full-width-relative', !ready && 'hidden')}
57+
/>
58+
</>
59+
)
60+
}
1961

2062
export default Header

src-ts/header/logo/Logo.module.scss

Lines changed: 0 additions & 33 deletions
This file was deleted.

src-ts/header/logo/Logo.tsx

Lines changed: 0 additions & 33 deletions
This file was deleted.

src-ts/header/logo/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src-ts/header/tool-selectors/ToolSelectors.tsx

Lines changed: 0 additions & 15 deletions
This file was deleted.

src-ts/header/tool-selectors/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src-ts/header/tool-selectors/tool-selectors-narrow/ToolSelectorsNarrow.module.scss

Lines changed: 0 additions & 31 deletions
This file was deleted.

src-ts/header/tool-selectors/tool-selectors-narrow/ToolSelectorsNarrow.tsx

Lines changed: 0 additions & 43 deletions
This file was deleted.

src-ts/header/tool-selectors/tool-selectors-narrow/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src-ts/header/tool-selectors/tool-selectors-narrow/tool-selector-narrow/ToolSelectorNarrow.module.scss

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)