Skip to content

Commit fede5ae

Browse files
Merge pull request #246 from topcoder-platform/PROD-2730_roles
PROD-2730 reg source from active tool -> dev
2 parents bd27088 + 69570b6 commit fede5ae

File tree

19 files changed

+117
-38
lines changed

19 files changed

+117
-38
lines changed

src-ts/config/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export enum ToolTitle {
2+
learn = 'Learn',
23
settings = 'Account Settings',
34
work = 'Work',
45
}

src-ts/header/tool-selectors/tool-selectors-wide/tool-selector-wide/ToolSelectorWide.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
PlatformRoute,
77
routeContext,
88
RouteContextData,
9+
routeIsActiveTool,
910
} from '../../../../lib'
1011
import '../../../../lib/styles/index.scss'
1112

@@ -19,15 +20,14 @@ const ToolSelectorWide: FC<ToolSelectorWideProps> = (props: ToolSelectorWideProp
1920

2021
const {
2122
getPathFromRoute,
22-
isActiveTool,
2323
isRootRoute,
2424
}: RouteContextData = useContext(routeContext)
2525

2626
const activePath: string = useLocation().pathname
2727
const toolRoute: PlatformRoute = props.route
2828
const toolPath: string = getPathFromRoute(toolRoute)
2929
const baseClass: string = 'tool-selector-wide'
30-
const isActive: boolean = isActiveTool(activePath, toolRoute)
30+
const isActive: boolean = routeIsActiveTool(activePath, toolRoute)
3131
const activeIndicatorClass: string = `${baseClass}-${isActive ? '' : 'in'}active`
3232

3333
// the tool link should be usable for all active routes except the home page

src-ts/header/utility-selectors/UtilitySelector/ProfileSelector/profile-not-logged-in/ProfileNotLoggedIn.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
import { FC } from 'react'
1+
import { FC, useContext } from 'react'
2+
import { Location, useLocation } from 'react-router-dom'
23

3-
import { authUrlLogin, authUrlSignup, Button } from '../../../../../lib'
4+
import {
5+
authUrlLogin,
6+
Button,
7+
routeContext,
8+
RouteContextData,
9+
} from '../../../../../lib'
410
import '../../../../../lib/styles/index.scss'
511

612
import styles from './ProfileNotLoggedIn.module.scss'
713

814
const ProfileNotLoggedIn: FC<{}> = () => {
915

16+
const routeData: RouteContextData = useContext(routeContext)
17+
const location: Location = useLocation()
18+
19+
function signUp(): void {
20+
const signupUrl: string = routeData.getSignupUrl(location.pathname, routeData.toolsRoutes)
21+
window.location.href = signupUrl
22+
}
23+
1024
return (
1125
<>
1226
<Button
@@ -15,15 +29,15 @@ const ProfileNotLoggedIn: FC<{}> = () => {
1529
label='Log In'
1630
size='md'
1731
tabIndex={-1}
18-
url={authUrlLogin}
32+
url={authUrlLogin()}
1933
/>
2034
<Button
2135
buttonStyle='tertiary'
2236
className={styles.signup}
2337
label='Sign Up'
2438
size='md'
2539
tabIndex={-1}
26-
url={authUrlSignup}
40+
onClick={signUp}
2741
/>
2842
</>
2943
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export enum AuthenticationRegistrationSource {
2+
work = 'selfService',
3+
}
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { EnvironmentConfig } from '../../../config'
22

3+
import { AuthenticationRegistrationSource } from './authentication-reg-source.enum'
4+
35
export const authentication: string = EnvironmentConfig.URL.ACCOUNTS_APP_CONNECTOR
46

5-
export const login: string = `${authentication}?retUrl=${encodeURIComponent(window.location.href.match(/[^?]*/)?.[0] || window.location.host)}`
7+
export function login(returnUrl?: string): string {
8+
const retUrl: string = returnUrl ?? window.location.href.match(/[^?]*/)?.[0] ?? window.location.host
9+
return `${authentication}?retUrl=${encodeURIComponent(retUrl)}`
10+
}
611

712
export const logout: string = `${authentication}?logout=true&retUrl=${encodeURIComponent('https://' + window.location.host)}`
813

9-
export const signup: string = `${login}&regSource=tcBusiness&mode=signUp`
14+
export function signup(returnUrl?: string, regSource?: AuthenticationRegistrationSource): string {
15+
return `${login(returnUrl)}&mode=signUp${!!regSource ? `&regSource=${regSource}` : ''}`
16+
}

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import cookies from 'browser-cookies'
22
import { configureConnector, decodeToken, getFreshToken } from 'tc-auth-lib'
33

44
import { User } from '../../../../types/tc-auth-lib'
5-
import { EnvironmentConfig } from '../../../config'
5+
import { EnvironmentConfig, ToolTitle } from '../../../config'
6+
import { PlatformRoute } from '../../route-provider'
67
import { logError } from '../logging-functions'
78

9+
import { AuthenticationRegistrationSource } from './authentication-reg-source.enum'
810
import { authentication as authenticationUrl } from './authentication-url.config'
911
import { CookieKeys } from './cookie-keys.enum'
1012

@@ -20,6 +22,21 @@ configureConnector({
2022
mockToken: undefined,
2123
})
2224

25+
export function getRegistrationSource(activeTool: PlatformRoute | undefined): AuthenticationRegistrationSource | undefined {
26+
27+
switch (activeTool?.title) {
28+
29+
// currently, there is no reg source for members
30+
case ToolTitle.learn:
31+
return
32+
33+
// currently, the work tool and the platform
34+
// landing page use the reg source of selfService
35+
default:
36+
return AuthenticationRegistrationSource.work
37+
}
38+
}
39+
2340
export async function initializeAsync(): Promise<string | undefined> {
2441
return getFreshToken()
2542
.then((tokenV3: string) => {
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
export * from './authentication-reg-source.enum'
12
export {
23
authentication as authUrl,
34
login as authUrlLogin,
45
logout as authUrlLogout,
56
signup as authUrlSignup,
67
} from './authentication-url.config'
7-
export { initializeAsync as authInitializeAsync } from './authentication.functions'
8+
export {
9+
getRegistrationSource as authGetRegistrationSource,
10+
initializeAsync as authInitializeAsync,
11+
} from './authentication.functions'

src-ts/lib/functions/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export {
2+
AuthenticationRegistrationSource,
3+
authGetRegistrationSource,
24
authUrl,
35
authUrlLogin,
46
authUrlLogout,

src-ts/lib/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export {
1010
authUrl,
1111
authUrlLogin,
1212
authUrlLogout,
13-
authUrlSignup,
1413
fileCreateFromCanvas,
1514
fileDownloadBlob,
1615
fileDownloadCanvasAsImage,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './route-functions'
12
export * from './platform-route.model'
23
export * from './route-context-data.model'
34
export { default as routeContext } from './route.context'

0 commit comments

Comments
 (0)