Skip to content

Commit b158852

Browse files
Merge pull request #427 from topcoder-platform/PROD-3245_work
Prod 3245 Integrate Self-Service Challenges, Support, Settings, Footer -> TCA-3115_uni-nav
2 parents 5a88174 + d092cec commit b158852

File tree

35 files changed

+91
-290
lines changed

35 files changed

+91
-290
lines changed

src-ts/config/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ export enum ToolTitle {
22
dev = 'Dev Center',
33
game = 'Gamification Admin',
44
settings = 'Account Settings',
5+
support = 'Support',
56
tca = 'Topcoder Academy',
6-
work = 'Self-Service',
7+
work = 'Self-Service Challenges',
78
}
89

910
export const PageSubheaderPortalId: string = 'page-subheader-portal-el'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function getRegistrationSource(
2626
activeTool: PlatformRoute | undefined,
2727
): AuthenticationRegistrationSource | undefined {
2828

29-
switch (activeTool?.title) {
29+
switch (activeTool?.id) {
3030

3131
// currently, there is no reg source for members
3232
case ToolTitle.tca:

src-ts/lib/page-footer/PageFooter.tsx

Lines changed: 12 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,21 @@
1-
import { Dispatch, FC, MouseEvent, SetStateAction, useState } from 'react'
1+
import { FC } from 'react'
22

3-
import { ContactSupportModal, OrderContractModal, PrivacyPolicyModal, TermsModal } from '../modals'
4-
import { ProfileProvider } from '../profile-provider'
5-
import { Facebook, Instagram, LinkedIn, Twitter, Youtube } from '../social-links'
6-
7-
import styles from './PageFooter.module.scss'
3+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4+
declare let tcUniNav: any
85

96
const PageFooter: FC<{}> = () => {
107

11-
const [isContactSupportModalOpen, setIsContactSupportModalOpen]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)
12-
const [isOrderContractModalOpen, setIsOrderContractModalOpen]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)
13-
const [isPrivacyModalOpen, setIsPrivacyModalOpen]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)
14-
const [isTermsModalOpen, setIsTermsModalOpen]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)
15-
16-
function handleClick(event: MouseEvent<HTMLAnchorElement>, setter: Dispatch<SetStateAction<boolean>>): void {
17-
event.preventDefault()
18-
setter(true)
19-
}
20-
21-
return (
22-
<div className={styles['footer-wrap']}>
23-
24-
<ProfileProvider>
25-
<ContactSupportModal
26-
isOpen={isContactSupportModalOpen}
27-
onClose={() => setIsContactSupportModalOpen(false)}
28-
/>
29-
</ProfileProvider>
8+
const navElementId: string = 'footer-nav-el'
309

31-
<OrderContractModal
32-
isOpen={isOrderContractModalOpen}
33-
onClose={() => setIsOrderContractModalOpen(false)}
34-
/>
35-
36-
<PrivacyPolicyModal
37-
isOpen={isPrivacyModalOpen}
38-
onClose={() => setIsPrivacyModalOpen(false)}
39-
/>
40-
41-
<TermsModal
42-
isOpen={isTermsModalOpen}
43-
onClose={() => setIsTermsModalOpen(false)}
44-
/>
45-
46-
<div className={styles['footer-inner']}>
47-
<div className={styles.utils}>
48-
<div>
49-
<span>
50-
©
51-
{(new Date())
52-
.getFullYear()}
53-
{' '}
54-
Topcoder
55-
</span>
56-
<a
57-
href={window.location.href}
58-
onClick={e => handleClick(e, setIsContactSupportModalOpen)}
59-
>
60-
Support
61-
</a>
62-
{/* TODO: add Report a bug functionality to send to zendesk
63-
https://topcoder.atlassian.net/browse/PROD-1864
64-
<a href='#'>See a Bug?</a> */}
65-
</div>
66-
<div>
67-
<a
68-
href={window.location.href}
69-
onClick={e => handleClick(e, setIsTermsModalOpen)}
70-
>
71-
Terms
72-
</a>
73-
<a
74-
href={window.location.href}
75-
onClick={e => handleClick(e, setIsPrivacyModalOpen)}
76-
>
77-
Privacy Policy
78-
</a>
79-
</div>
80-
</div>
81-
<div className={styles.social}>
82-
<Facebook />
83-
<Youtube />
84-
<LinkedIn />
85-
<Twitter />
86-
<Instagram />
87-
</div>
88-
</div>
89-
</div>
10+
tcUniNav(
11+
'init',
12+
navElementId,
13+
{
14+
type: 'footer',
15+
},
9016
)
17+
18+
return <div id={navElementId} />
9119
}
9220

9321
export default PageFooter

src-ts/lib/route-provider/platform-route.model.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ export interface PlatformRoute {
22
alternativePaths?: Array<string>
33
authRequired?: boolean
44
children?: Array<PlatformRoute>
5-
customerOnly?: boolean
65
disabled?: boolean
76
element: JSX.Element
87
hidden?: boolean
9-
memberOnly?: boolean
8+
id?: string
109
rolesRequired?: Array<string>
1110
route: string
1211
title?: string

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export interface RouteContextData {
88
allRoutes: Array<PlatformRoute>
99
getChildren: (parent: string) => Array<PlatformRoute>
1010
getChildRoutes: (parent: string) => Array<ReactElement>
11-
getPath: (routeTitle: string) => string
1211
getPathFromRoute: (route: PlatformRoute) => string
1312
getRouteElement: (route: PlatformRoute) => JSX.Element
1413
getSignupUrl: (currentLocation: string, toolRoutes: Array<PlatformRoute>, returnUrl?: string) => string
@@ -17,6 +16,5 @@ export interface RouteContextData {
1716
rootLoggedInRoute: string
1817
rootLoggedOutFC: FC<{}>
1918
toolsRoutes: Array<PlatformRoute>
20-
toolsRoutesForNav: Array<PlatformRoute>
2119
utilsRoutes: Array<PlatformRoute>
2220
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export {
2+
getActive as routeGetActive,
23
getSignupUrl as routeGetSignupUrl,
3-
isActiveTool as routeIsActiveTool,
44
} from './route.functions'

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import {
55
} from '../../functions'
66
import { PlatformRoute } from '../platform-route.model'
77

8+
export function getActive(currentLocation: string, toolRoutes: Array<PlatformRoute>): PlatformRoute | undefined {
9+
return toolRoutes.find(tool => isActiveTool(currentLocation, tool))
10+
}
11+
812
// NOTE: this function ties together routes and auth,
913
// so one could make an argument that it should be
1014
// part of the auth functions and be provided by the
@@ -18,14 +22,14 @@ export function getSignupUrl(
1822
): string {
1923

2024
// figure out the current tool so we can assign the correct reg source
21-
const activeTool: PlatformRoute | undefined = toolRoutes.find(tool => isActiveTool(currentLocation, tool))
25+
const activeTool: PlatformRoute | undefined = getActive(currentLocation, toolRoutes)
2226
const regSource: AuthenticationRegistrationSource | undefined
2327
= authGetRegistrationSource(activeTool)
2428

2529
return authUrlSignup(returnUrl, regSource)
2630
}
2731

28-
export function isActiveTool(activePath: string, toolRoute: PlatformRoute): boolean {
32+
function isActiveTool(activePath: string, toolRoute: PlatformRoute): boolean {
2933
return !!activePath.startsWith(toolRoute.route)
3034
|| !!toolRoute.alternativePaths?.some(path => activePath.startsWith(path))
3135
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import { RouteContextData } from './route-context-data.model'
44

55
export const defaultRouteContextData: RouteContextData = {
66
allRoutes: [],
7-
getChildRoutes: () => [],
87
getChildren: () => [],
9-
getPath: () => '',
8+
getChildRoutes: () => [],
109
getPathFromRoute: () => '',
1110
getRouteElement: () => <></>,
1211
getSignupUrl: () => '',
@@ -15,7 +14,6 @@ export const defaultRouteContextData: RouteContextData = {
1514
rootLoggedInRoute: '',
1615
rootLoggedOutFC: () => <></>,
1716
toolsRoutes: [],
18-
toolsRoutesForNav: [],
1917
utilsRoutes: [],
2018
}
2119

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

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { profileContext, ProfileContextData } from '../profile-provider'
1818
import { PlatformRoute } from './platform-route.model'
1919
import { RequireAuthProvider } from './require-auth-provider'
2020
import { RouteContextData } from './route-context-data.model'
21-
import { routeGetSignupUrl, routeIsActiveTool } from './route-functions'
21+
import { routeGetActive, routeGetSignupUrl } from './route-functions'
2222
import { default as routeContext, defaultRouteContextData } from './route.context'
2323

2424
interface RouteProviderProps {
@@ -47,39 +47,14 @@ export const RouteProvider: FC<RouteProviderProps> = (props: RouteProviderProps)
4747
// TODO: try to make these prop names configurable instead of hard-codded
4848
const toolsRoutes: Array<PlatformRoute> = props.toolsRoutes.filter(route => !route.disabled)
4949

50-
// display a tool in the nav if the following conditions are met:
51-
// 1. the tool has a title
52-
// 2. the tool isn't hidden (if the tool is hidden, it should never appear in the nav)
53-
// AND
54-
// 3. the tool is one of the following:
55-
// a. for customers and the user is a customer
56-
// b. for members and the user is a member
57-
// c. the active tool in the app (in case someone deep-links to it)
58-
let activeRoute: PlatformRoute | undefined
59-
const toolsRoutesForNav: Array<PlatformRoute> = toolsRoutes
60-
.filter(route => {
61-
62-
const isActive: boolean = routeIsActiveTool(location.pathname, route)
63-
if (isActive) {
64-
activeRoute = route
65-
}
66-
67-
return !!route.title
68-
&& !route.hidden
69-
&& (
70-
(
71-
(!route.customerOnly || !!profile?.isCustomer)
72-
&& (!route.memberOnly || !!profile?.isMember)
73-
)
74-
|| isActive
75-
)
76-
})
77-
7850
const utilsRoutes: Array<PlatformRoute> = props.utilsRoutes.filter(route => !route.disabled)
7951
allRoutes = [
8052
...toolsRoutes,
8153
...utilsRoutes,
8254
]
55+
56+
const activeRoute: PlatformRoute | undefined = routeGetActive(location.pathname, allRoutes)
57+
8358
// TODO: support additional roles and landing pages
8459
const loggedInRoot: string = !profile
8560
? ''
@@ -88,12 +63,11 @@ export const RouteProvider: FC<RouteProviderProps> = (props: RouteProviderProps)
8863
: props.rootMember
8964

9065
const contextData: RouteContextData = {
91-
activeToolName: activeRoute?.title,
66+
activeToolName: activeRoute?.title || activeRoute?.id,
9267
activeToolRoute: !!activeRoute ? `https://${window.location.hostname}${activeRoute.route}` : undefined,
9368
allRoutes,
9469
getChildren,
9570
getChildRoutes,
96-
getPath,
9771
getPathFromRoute,
9872
getRouteElement,
9973
getSignupUrl: routeGetSignupUrl,
@@ -102,15 +76,14 @@ export const RouteProvider: FC<RouteProviderProps> = (props: RouteProviderProps)
10276
rootLoggedInRoute: loggedInRoot,
10377
rootLoggedOutFC: props.rootLoggedOutFC,
10478
toolsRoutes,
105-
toolsRoutesForNav,
10679
utilsRoutes,
10780
}
10881
setRouteContextData(contextData)
10982
}
11083

11184
function getChildren(parent: string): Array<PlatformRoute> {
11285
return allRoutes
113-
.find(route => route.title === parent)
86+
.find(route => route.id === parent)
11487
?.children
11588
|| []
11689
}
@@ -120,12 +93,6 @@ export const RouteProvider: FC<RouteProviderProps> = (props: RouteProviderProps)
12093
.map(route => getRouteElement(route))
12194
}
12295

123-
function getPath(routeTitle: string): string {
124-
const platformRoute: PlatformRoute = allRoutes.find(route => route.title === routeTitle) as PlatformRoute
125-
// if the path has a trailing asterisk, remove it
126-
return getPathFromRoute(platformRoute)
127-
}
128-
12996
function getPathFromRoute(route: PlatformRoute): string {
13097
return route.route.replace('/*', '')
13198
}

src-ts/lib/social-links/facebook/Facebook.tsx

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

src-ts/lib/social-links/facebook/index.ts

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

src-ts/lib/social-links/index.ts

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

src-ts/lib/social-links/instagram/Instagram.tsx

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

src-ts/lib/social-links/instagram/index.ts

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

src-ts/lib/social-links/linked-in/LinkedIn.tsx

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

src-ts/lib/social-links/linked-in/index.ts

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

src-ts/lib/social-links/social-link/SocialLink.tsx

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

src-ts/lib/social-links/social-link/index.ts

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

src-ts/lib/social-links/twitter/Twitter.tsx

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

src-ts/lib/social-links/twitter/index.ts

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

0 commit comments

Comments
 (0)