Skip to content

Commit 1ce3d53

Browse files
committed
Initial universal nav implementation
1 parent 6eeef9e commit 1ce3d53

File tree

11 files changed

+123
-19
lines changed

11 files changed

+123
-19
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ workflows:
200200
- build-dev
201201
filters: &filters-dev
202202
branches:
203-
only: ['dev', 'feature/milestone-customer-approval', 'reskin']
203+
only: ['dev', 'universal_nav', 'feature/milestone-customer-approval', 'reskin']
204204

205205
- deployTest01:
206206
context : org-global

config/constants/dev.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const DOMAIN = 'topcoder-dev.com'
2+
13
module.exports = {
24
API_URL : 'https://api.topcoder-dev.com/v3',
35
API_URL_V2 : 'https://api.topcoder-dev.com/v2',
@@ -59,5 +61,8 @@ module.exports = {
5961
CONTENTFUL_SPACE_ID : process.env.CONTENTFUL_SPACE_ID,
6062

6163
TAAS_APP_URL: 'https://platform.topcoder-dev.com/taas',
62-
DEFAULT_NDA_UUID: 'e5811a7b-43d1-407a-a064-69e5015b4900'
64+
DEFAULT_NDA_UUID: 'e5811a7b-43d1-407a-a064-69e5015b4900',
65+
UNIVERSAL_NAV_URL: '//uni-nav.topcoder-dev.com/v1/tc-universal-nav.js',
66+
HEADER_AUTH_URLS_HREF: `https://accounts-auth0.${DOMAIN}?utm_source=community-app-main`,
67+
HEADER_AUTH_URLS_LOCATION: `https://accounts-auth0.${DOMAIN}?retUrl=%S&utm_source=community-app-main`
6368
}

config/constants/master.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const DOMAIN = 'topcoder.com'
2+
13
module.exports = {
24
API_URL : 'https://api.topcoder.com/v3',
35
API_URL_V2 : 'https://api.topcoder.com/v2',
@@ -59,5 +61,8 @@ module.exports = {
5961
CONTENTFUL_SPACE_ID : process.env.CONTENTFUL_SPACE_ID,
6062

6163
TAAS_APP_URL: 'https://platform.topcoder.com/taas',
62-
DEFAULT_NDA_UUID: 'c41e90e5-4d0e-4811-bd09-38ff72674490'
64+
DEFAULT_NDA_UUID: 'c41e90e5-4d0e-4811-bd09-38ff72674490',
65+
UNIVERSAL_NAV_URL: '//uni-nav.topcoder.com/v1/tc-universal-nav.js',
66+
HEADER_AUTH_URLS_HREF: `https://accounts-auth0.${DOMAIN}?utm_source=community-app-main`,
67+
HEADER_AUTH_URLS_LOCATION: `https://accounts-auth0.${DOMAIN}?retUrl=%S&utm_source=community-app-main`
6368
}

config/constants/qa.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const DOMAIN = 'topcoder-dev.com'
2+
13
module.exports = {
24
API_URL : 'https://api.topcoder-qa.com/v3',
35
API_URL_V2 : 'https://api.topcoder-qa.com/v2',
@@ -54,5 +56,8 @@ module.exports = {
5456
TC_CDN_URL: process.env.TC_CDN_URL,
5557

5658
TAAS_APP_URL: 'https://platform.topcoder-dev.com/taas',
57-
DEFAULT_NDA_UUID: 'e5811a7b-43d1-407a-a064-69e5015b4900'
59+
DEFAULT_NDA_UUID: 'e5811a7b-43d1-407a-a064-69e5015b4900',
60+
UNIVERSAL_NAV_URL: '//uni-nav.topcoder-dev.com/v1/tc-universal-nav.js',
61+
HEADER_AUTH_URLS_HREF: `https://accounts-auth0.${DOMAIN}?utm_source=community-app-main`,
62+
HEADER_AUTH_URLS_LOCATION: `https://accounts-auth0.${DOMAIN}?retUrl=%S&utm_source=community-app-main`
5863
}

src/components/Layout/Layout.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
:global {
44
.main-wrapper {
5-
min-height: calc(100vh - 60px); // minus height
6-
padding-top: 60px;
5+
min-height: calc(100vh - 120px); // minus height
6+
padding-top: 120px;
77
overflow: hidden;
88

99
@media screen and (max-width: $screen-md - 1px) {

src/components/TopBar/ProjectsToolBar.js

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
require('./ProjectsToolBar.scss')
2-
2+
/* global tcUniNav */
33
import React, { Component } from 'react'
44
import PropTypes from 'prop-types'
55
import querystring from 'query-string'
66
import { withRouter, Prompt } from 'react-router-dom'
77
import { connect } from 'react-redux'
88
import _ from 'lodash'
99
import SearchBar from 'appirio-tech-react-components/components/SearchBar/SearchBar'
10-
import NotificationsDropdown from '../NotificationsDropdown/NotificationsDropdownContainer'
1110
import NewProjectNavLink from './NewProjectNavLink'
1211
import MobileMenu from '../MobileMenu/MobileMenu'
1312
import MobileMenuToggle from '../MobileMenu/MobileMenuToggle'
@@ -16,21 +15,34 @@ import { loadProjectsMetadata } from '../../actions/templates'
1615
import { getNewProjectLink } from '../../helpers/projectHelper'
1716
import { hasPermission } from '../../helpers/permissions'
1817
import { PERMISSIONS } from '../../config/permissions'
18+
import { HEADER_AUTH_URLS_HREF, HEADER_AUTH_URLS_LOCATION, DOMAIN } from '../../config/constants'
19+
import { getInitials } from '../../helpers/format'
20+
21+
const HEADER_AUTH_URLS = {
22+
href: HEADER_AUTH_URLS_HREF,
23+
location: HEADER_AUTH_URLS_LOCATION
24+
}
25+
const BASE = `https://www.${DOMAIN}`
26+
27+
let uniqueId = 0
1928

2029
class ProjectsToolBar extends Component {
2130

2231
constructor(props) {
2332
super(props)
33+
uniqueId += 1
2434
this.state = {
2535
errorCreatingProject: false,
2636
isMobileMenuOpen: false,
27-
isMobileSearchVisible: false
37+
isMobileSearchVisible: false,
38+
headerId: uniqueId,
2839
}
2940
this.applyFilters = this.applyFilters.bind(this)
3041
this.handleTermChange = this.handleTermChange.bind(this)
3142
this.handleSearch = this.handleSearch.bind(this)
3243
this.toggleMobileMenu = this.toggleMobileMenu.bind(this)
3344
this.onLeave = this.onLeave.bind(this)
45+
this.uniNavInitialized = false
3446
}
3547

3648
componentWillMount() {
@@ -71,6 +83,43 @@ class ProjectsToolBar extends Component {
7183
window.addEventListener('beforeunload', this.onLeave)
7284
}
7385

86+
componentDidUpdate() {
87+
if (!!this.state.headerId && !this.uniNavInitialized) {
88+
const user = this.props.user
89+
const navigationUserInfo = {
90+
...user,
91+
initials: getInitials(user.firstName, user.lastName)
92+
}
93+
const authToken = user ? user.token : null
94+
this.uniNavInitialized = true
95+
const headerId = this.state.headerId
96+
const isAuthenticated = !!authToken
97+
const authURLs = HEADER_AUTH_URLS
98+
99+
const regSource = window.location.pathname.split('/')[1]
100+
const retUrl = encodeURIComponent(window.location.href)
101+
tcUniNav('init', `headerNav-${headerId}`, {
102+
type: 'tool',
103+
toolName: 'Connect',
104+
toolRoot: '/',
105+
user: isAuthenticated ? navigationUserInfo : null,
106+
signOut: () => {
107+
window.location = `${BASE}/logout?ref=nav`
108+
},
109+
signIn: () => {
110+
window.location = `${authURLs.location
111+
.replace('%S', retUrl)
112+
.replace('member?', '#!/member?')}&regSource=${regSource}`
113+
},
114+
signUp: () => {
115+
window.location = `${authURLs.location
116+
.replace('%S', retUrl)
117+
.replace('member?', '#!/member?')}&mode=signUp&regSource=${regSource}`
118+
}
119+
})
120+
}
121+
}
122+
74123
componentWillUnmount() {
75124
window.removeEventListener('beforeunload', this.onLeave)
76125
const contentDiv = document.getElementById('wrapper-main')
@@ -146,8 +195,8 @@ class ProjectsToolBar extends Component {
146195
}
147196

148197
render() {
149-
const { renderLogoSection, userMenu, userRoles, user, mobileMenu, location, orgConfig } = this.props
150-
const { isMobileMenuOpen, isMobileSearchVisible } = this.state
198+
const { userRoles, user, mobileMenu, orgConfig } = this.props
199+
const { isMobileMenuOpen, isMobileSearchVisible, headerId } = this.state
151200
const isLoggedIn = !!(userRoles && userRoles.length)
152201

153202
const onLeaveMessage = this.onLeave() || ''
@@ -158,8 +207,8 @@ class ProjectsToolBar extends Component {
158207
when={!!onLeaveMessage}
159208
message={onLeaveMessage}
160209
/>
210+
<div id={`headerNav-${headerId}`} />
161211
<div className="primary-toolbar">
162-
{ renderLogoSection() }
163212
{ isLoggedIn && !hasPermission(PERMISSIONS.SEARCH_PROJECTS) && <div className="projects-title-mobile">MY PROJECTS</div> }
164213
{
165214
isLoggedIn && hasPermission(PERMISSIONS.SEARCH_PROJECTS) &&
@@ -176,10 +225,6 @@ class ProjectsToolBar extends Component {
176225
}
177226
<div className="actions">
178227
{isLoggedIn && <NewProjectNavLink link={getNewProjectLink(orgConfig)} />}
179-
{ userMenu }
180-
{/* pass location, to make sure that component is re-rendered when location is changed
181-
it's necessary to hide notification dropdown on mobile when users uses browser history back/forward buttons */}
182-
{ isLoggedIn && <NotificationsDropdown location={location} /> }
183228
{ isLoggedIn && <MobileMenuToggle onToggle={this.toggleMobileMenu}/> }
184229
</div>
185230
</div>

src/components/TopBar/ProjectsToolBar.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
height: 60px;
1616
justify-content: space-between;
1717
user-select: none;
18+
padding: 0 20px;
19+
1820
@media screen and (max-width: $screen-md - 1px) {
1921
height: auto;
2022
min-height: 50px;

src/components/TopBar/TopBarContainer.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@
9696

9797
&.tc-header__connect {
9898
padding: 0;
99-
min-height: 60px;
99+
min-height: 120px;
100100
height: auto;
101101
@media screen and (max-width: $screen-md - 1px) {
102102
min-height: 50px;
103103
}
104104

105105
.top-bar {
106-
height: 60px;
106+
height: 120px;
107107
background-color: $tc-black;
108108
position: relative;
109109
@media screen and (max-width: $screen-md - 1px) {

src/config/constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,3 +1235,7 @@ export const DEFAULT_NDA_UUID = process.env.DEFAULT_NDA_UUID
12351235
* The minimal duration of a TaaS Job in weeks
12361236
*/
12371237
export const TAAS_MIN_JOB_DURATION = 4
1238+
1239+
export const UNIVERSAL_NAV_URL = process.env.UNIVERSAL_NAV_URL || '//uni-nav.topcoder-dev.com/v1/tc-universal-nav.js'
1240+
export const HEADER_AUTH_URLS_HREF = process.env.HEADER_AUTH_URLS_HREF || `https://accounts-auth0.${DOMAIN}?utm_source=community-app-main`
1241+
export const HEADER_AUTH_URLS_LOCATION = process.env.HEADER_AUTH_URLS_LOCATION || `https://accounts-auth0.${DOMAIN}?retUrl=%S&utm_source=community-app-main`

src/helpers/format.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,13 @@
1111
export function formatNumberWithCommas(value) {
1212
return (value || 0 ).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
1313
}
14+
15+
/**
16+
* Get initials from user profile
17+
* @param {String} firstName first name
18+
* @param {String} lastName last name
19+
* @returns {String}
20+
*/
21+
export function getInitials(firstName = '', lastName = '') {
22+
return `${firstName.slice(0, 1)}${lastName.slice(0, 1)}`
23+
}

0 commit comments

Comments
 (0)