Skip to content

Commit 843d0c9

Browse files
committed
Merge remote-tracking branch 'origin/dev' into uof-dev-merge
2 parents bda30e9 + f4a5193 commit 843d0c9

File tree

7 files changed

+70
-15
lines changed

7 files changed

+70
-15
lines changed

src/apps/earn/src/earn.routes.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Navigate } from 'react-router-dom'
22

3-
import { ToolTitle } from '~/config'
3+
import { AppSubdomain, EnvironmentConfig, ToolTitle } from '~/config'
44
import { lazyLoad, LazyLoadedComponent, PlatformRoute } from '~/libs/core'
55

66
const EarnAppRoot: LazyLoadedComponent = lazyLoad(() => import('./EarnApp'))
@@ -36,19 +36,26 @@ const MyGigs: LazyLoadedComponent = lazyLoad(
3636
() => import('./routes/MyGigsPage'),
3737
)
3838

39-
export enum EARN_APP_PATHS {
40-
root = '/earn',
41-
gigs = '/earn/gigs',
42-
challenges = '/earn/challenges',
39+
export const rootRoute: string = (
40+
EnvironmentConfig.SUBDOMAIN === AppSubdomain.earn ? '' : `/${AppSubdomain.earn}`
41+
)
42+
43+
export const EARN_APP_PATHS: { [key: string]: string } = {
44+
root: rootRoute,
45+
gigs: `${rootRoute}/gigs`,
46+
challenges: `${rootRoute}/challenges`,
4347
}
4448

4549
export const toolTitle: string = ToolTitle.earn
46-
export const rootRoute: string = EARN_APP_PATHS.root
4750
export const absoluteRootRoute: string = `${window.location.origin}${EARN_APP_PATHS.root}`
4851

4952
export const earnRoutes: ReadonlyArray<PlatformRoute> = [
5053
{
5154
children: [
55+
{
56+
element: <Navigate to={EARN_APP_PATHS.challenges} />,
57+
route: '/',
58+
},
5259
{
5360
children: [],
5461
element: <ChallengeList />,
@@ -92,12 +99,9 @@ export const earnRoutes: ReadonlyArray<PlatformRoute> = [
9299
route: 'my-gigs',
93100
},
94101
],
102+
domain: AppSubdomain.earn,
95103
element: <EarnAppRoot />,
96104
id: toolTitle,
97105
route: rootRoute,
98106
},
99-
{
100-
element: <Navigate to={EARN_APP_PATHS.challenges} />,
101-
route: rootRoute,
102-
},
103107
]

src/apps/learn/src/course-page-wrapper/CoursePage.context.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const CoursePageContextProvider: FC<CoursePageContextProviderProps> = pro
4848
const breadcrumbs: BreadcrumbItemModel[] = [
4949
{
5050
name: 'Topcoder Academy',
51-
url: rootRoute,
51+
url: rootRoute || '/',
5252
},
5353
...(!parentTcaCert ? [] : [parentTcaCert]),
5454
...items,

src/apps/learn/src/learn.routes.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
lazyLoad,
55
LazyLoadedComponent,
66
PlatformRoute,
7+
Rewrite,
78
} from '~/libs/core'
89

910
import { LearnConfig } from './config'
@@ -137,7 +138,7 @@ export function getTCACertificateUrl(
137138
export function getTCACertificationValidationUrl(
138139
completionUuid: string,
139140
): string {
140-
return `${EnvironmentConfig.PLATFORMUI_URL}${LEARN_PATHS.root}/${completionUuid}`
141+
return `${absoluteRootRoute}/certificate/${completionUuid}`
141142
}
142143

143144
export function getTCAUserCertificationUrl(
@@ -157,6 +158,15 @@ export function getAuthenticateAndEnrollRoute(): string {
157158
return `${authUrlLogin()}${encodeURIComponent(LEARN_PATHS.tcaEnroll)}`
158159
}
159160

161+
const oldUrlRedirectRoute: ReadonlyArray<PlatformRoute> = EnvironmentConfig.SUBDOMAIN === AppSubdomain.tcAcademy ? [
162+
{
163+
children: [],
164+
element: <Rewrite to='/*' />,
165+
id: 'redirect-old-url',
166+
route: '/learn/*',
167+
},
168+
] : []
169+
160170
export const learnRoutes: ReadonlyArray<PlatformRoute> = [
161171
{
162172
children: [
@@ -225,7 +235,7 @@ export const learnRoutes: ReadonlyArray<PlatformRoute> = [
225235
children: [],
226236
element: <ValidateTCACertificate />,
227237
id: 'Hiring manager view - uuid param',
228-
route: ':completionUuid',
238+
route: 'certificate/:completionUuid',
229239
},
230240
{
231241
children: [],
@@ -239,6 +249,7 @@ export const learnRoutes: ReadonlyArray<PlatformRoute> = [
239249
id: 'Giring manager preview',
240250
route: 'tca-certifications/:certification/preview',
241251
},
252+
...oldUrlRedirectRoute,
242253
],
243254
domain: AppSubdomain.tcAcademy,
244255
element: <LearnAppRoot />,

src/apps/self-service/src/self-service.routes.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable max-len */
22
import { Navigate } from 'react-router-dom'
33

4-
import { ToolTitle } from '~/config'
5-
import { lazyLoad, LazyLoadedComponent, PlatformRoute } from '~/libs/core'
4+
import { AppSubdomain, EnvironmentConfig, ToolTitle } from '~/config'
5+
import { lazyLoad, LazyLoadedComponent, PlatformRoute, Rewrite } from '~/libs/core'
66

77
import { Work, WorkIntakeFormRoutes, WorkStatus, WorkType } from './lib'
88
import { bugHuntRoute, selfServiceRootRoute, selfServiceStartRoute, workDashboardRoute, workRootRoute } from './config'
@@ -54,6 +54,15 @@ export function workDetailRoute(workId: string, tab?: 'solutions' | 'messages'):
5454
return `${selfServiceRootRoute}/work-items/${workId}${!!tab ? `?tab=${tab}` : ''}`
5555
}
5656

57+
const oldUrlRedirectRoute: ReadonlyArray<PlatformRoute> = EnvironmentConfig.SUBDOMAIN === AppSubdomain.work ? [
58+
{
59+
children: [],
60+
element: <Rewrite to='/*' />,
61+
id: 'redirect-old-url',
62+
route: '/work/*',
63+
},
64+
] : []
65+
5766
export const selfServiceRoutes: ReadonlyArray<PlatformRoute> = [
5867
{
5968
element: <NotLoggedIn />,
@@ -85,6 +94,10 @@ export const selfServiceRoutes: ReadonlyArray<PlatformRoute> = [
8594
},
8695
{
8796
children: [
97+
{
98+
element: <Navigate to={selfServiceStartRoute} />,
99+
route: '/',
100+
},
88101
// Edit work item
89102
{
90103
element: <SelfServiceWorkItem />,
@@ -159,4 +172,5 @@ export const selfServiceRoutes: ReadonlyArray<PlatformRoute> = [
159172
element: <Navigate to={workDashboardRoute} />,
160173
route: `${selfServiceRootRoute}/dashboard`,
161174
},
175+
...oldUrlRedirectRoute,
162176
]

src/config/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export enum AppSubdomain {
22
devCenter = 'devcenter',
3+
earn = 'earn',
34
gamificationAdmin = 'gamification-admin',
45
tcAcademy = 'academy',
56
work = 'work',

src/libs/core/lib/router/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './router-context'
22
export * from './routes-functions'
33
export * from './platform-route.model'
44
export * from './router.utils'
5+
export * from './rewrite-route'
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { get } from 'lodash'
2+
import { FC } from 'react'
3+
import { Navigate, Params, useParams } from 'react-router-dom'
4+
5+
export interface RewriteProps {
6+
to: string
7+
}
8+
9+
/**
10+
* Extends react-router-dom Navigate component to support rewriting of urls
11+
* Eg. or rewrite rules:
12+
* - /learn/* -> /* (redirects all learn pages to root)
13+
*/
14+
export const Rewrite: FC<RewriteProps> = props => {
15+
const params: Params = useParams()
16+
const rewriteTo: string = props.to.replace(
17+
/(:[a-z0-9*]+)|\*/ig,
18+
(match: string) => get(params, match.replace(':', ''), ''),
19+
)
20+
21+
return (
22+
<Navigate to={rewriteTo} />
23+
)
24+
}

0 commit comments

Comments
 (0)