1
|
|
|
import React from "react"; |
2
|
|
|
import ReactDOM from "react-dom"; |
3
|
|
|
import { Routes } from "universal-router"; |
4
|
|
|
import { useIntl, defineMessages } from "react-intl"; |
5
|
|
|
import RootContainer from "../RootContainer"; |
6
|
|
|
import { RouterResult, useRouter, Link } from "../../helpers/router"; |
7
|
|
|
import IntroPage from "./Intro/IntroPage"; |
8
|
|
|
import ScrollToTop from "../ScrollToTop"; |
9
|
|
|
import BasicInfoPage from "./BasicInfo/BasicInfoPage"; |
10
|
|
|
import { |
11
|
|
|
applicationWelcome, |
12
|
|
|
applicationSkillsIntro, |
13
|
|
|
} from "../../helpers/routes"; |
14
|
|
|
import { Locales } from "../../helpers/localize"; |
15
|
|
|
import ExperienceIntroPage from "./Experience/ExperienceIntroPage"; |
16
|
|
|
|
17
|
|
|
const pageTitles = defineMessages({ |
18
|
|
|
welcomeTitle: { |
19
|
|
|
id: "application.welcome.documentTitle", |
20
|
|
|
defaultMessage: "Apply: Welcome", // TODO: Get page title from designs. |
21
|
|
|
description: "The document's title shown in browser's title bar or tab.", |
22
|
|
|
}, |
23
|
|
|
basicTitle: { |
24
|
|
|
id: "application.basic.documentTitle", |
25
|
|
|
defaultMessage: "Apply: My Basic Information", // TODO: Get page title from designs. |
26
|
|
|
description: "The document's title shown in browser's title bar or tab.", |
27
|
|
|
}, |
28
|
|
|
experienceIntroTitle: { |
29
|
|
|
id: "application.experienceIntro.documentTitle", |
30
|
|
|
defaultMessage: "Apply: Defining Your Experience", // TODO: Get page title from designs. |
31
|
|
|
description: "The document's title shown in browser's title bar or tab.", |
32
|
|
|
}, |
33
|
|
|
experienceTitle: { |
34
|
|
|
id: "application.experience.documentTitle", |
35
|
|
|
defaultMessage: "Apply: Experience", |
36
|
|
|
description: "The document's title shown in browser's title bar or tab.", |
37
|
|
|
}, |
38
|
|
|
}); |
39
|
|
|
|
40
|
|
|
const routes: Routes<{}, RouterResult> = [ |
41
|
|
|
{ |
42
|
|
|
path: "/:locale/demo/applications/:id", // TODO: remove demo from url. |
43
|
|
|
children: [ |
44
|
|
|
{ |
45
|
|
|
path: "/welcome", |
46
|
|
|
action: ({ params }) => ({ |
47
|
|
|
title: pageTitles.welcomeTitle, |
48
|
|
|
component: <IntroPage applicationId={Number(params.id)} />, |
49
|
|
|
}), |
50
|
|
|
}, |
51
|
|
|
{ |
52
|
|
|
path: "/basic", |
53
|
|
|
action: ({ params }) => ({ |
54
|
|
|
title: pageTitles.basicTitle, |
55
|
|
|
component: <BasicInfoPage applicationId={Number(params.id)} />, |
56
|
|
|
}), |
57
|
|
|
}, |
58
|
|
|
{ |
59
|
|
|
path: "/experience-intro", |
60
|
|
|
action: ({ params }) => ({ |
61
|
|
|
title: pageTitles.experienceIntroTitle, |
62
|
|
|
component: <ExperienceIntroPage applicationId={Number(params.id)} />, |
63
|
|
|
}), |
64
|
|
|
}, |
65
|
|
|
{ |
66
|
|
|
path: "/experience", |
67
|
|
|
action: ({ params }) => ({ |
68
|
|
|
title: pageTitles.experienceTitle, |
69
|
|
|
component: ( |
70
|
|
|
<> |
71
|
|
|
<p>PLACEHOLDER FOR EXPERIENCE STEP</p> |
72
|
|
|
<Link |
73
|
|
|
href={applicationSkillsIntro( |
74
|
|
|
params.locale as Locales, |
75
|
|
|
Number(params.id), |
76
|
|
|
)} |
77
|
|
|
title="" |
78
|
|
|
> |
79
|
|
|
Continue |
80
|
|
|
</Link> |
81
|
|
|
</> |
82
|
|
|
), |
83
|
|
|
}), |
84
|
|
|
}, |
85
|
|
|
{ |
86
|
|
|
// Redirect any unmatched url to Welcome step. |
87
|
|
|
path: "(.*)", |
88
|
|
|
action: ({ params }) => ({ |
89
|
|
|
title: pageTitles.welcomeTitle, |
90
|
|
|
component: <div />, |
91
|
|
|
redirect: applicationWelcome( |
92
|
|
|
params.locale as Locales, |
93
|
|
|
Number(params.id), |
94
|
|
|
), |
95
|
|
|
}), |
96
|
|
|
}, |
97
|
|
|
], |
98
|
|
|
}, |
99
|
|
|
]; |
100
|
|
|
|
101
|
|
|
const ApplicationRoot: React.FunctionComponent = () => { |
102
|
|
|
const intl = useIntl(); |
103
|
|
|
const match = useRouter(routes, intl); |
104
|
|
|
const tracker: HTMLElement | null = document.getElementById( |
105
|
|
|
"application-root", |
106
|
|
|
); |
107
|
|
|
const trackerOffsetTop: number = tracker ? tracker.offsetTop : 0; |
108
|
|
|
|
109
|
|
|
return ( |
110
|
|
|
<ScrollToTop offsetTop={trackerOffsetTop} scrollBehaviorAuto> |
111
|
|
|
{match} |
112
|
|
|
</ScrollToTop> |
113
|
|
|
); |
114
|
|
|
}; |
115
|
|
|
|
116
|
|
|
if (document.getElementById("application-root")) { |
117
|
|
|
const root = document.getElementById("application-root"); |
118
|
|
|
ReactDOM.render( |
119
|
|
|
<RootContainer> |
120
|
|
|
<ApplicationRoot /> |
121
|
|
|
</RootContainer>, |
122
|
|
|
root, |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
|