Passed
Push — dev ( cd2464...7a88aa )
by
unknown
04:47
created

resources/assets/js/components/Application/ApplicationRoot.tsx   A

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 175
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 135
mnd 2
bc 2
fnc 0
dl 0
loc 175
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
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 } from "../../helpers/router";
7
import IntroPage from "./Intro/IntroPage";
8
import ScrollToTop from "../ScrollToTop";
9
import BasicInfoPage from "./BasicInfo/BasicInfoPage";
10
import { applicationWelcome } from "../../helpers/routes";
11
import { Locales } from "../../helpers/localize";
12
import ExperienceIntroPage from "./Experience/ExperienceIntroPage";
13
import ExperiencePage from "./Experience/ExperiencePage";
14
import SkillsPage from "./Skills/SkillsPage";
15
import FitPage from "./Fit/FitPage";
16
import ReviewPage from "./Review/ReviewPage";
17
import FinalSubmitPage from "./FinalSubmit/FinalSubmitPage";
18
import SkillsIntroPage from "./Skills/SkillsIntroPage";
19
20
const pageTitles = defineMessages({
21
  welcomeTitle: {
22
    id: "application.welcome.documentTitle",
23
    defaultMessage: "Apply: Welcome", // TODO: Get page title from designs.
24
    description: "The document's title shown in browser's title bar or tab.",
25
  },
26
  basicTitle: {
27
    id: "application.basic.documentTitle",
28
    defaultMessage: "Apply: My Basic Information", // TODO: Get page title from designs.
29
    description: "The document's title shown in browser's title bar or tab.",
30
  },
31
  experienceIntroTitle: {
32
    id: "application.experienceIntro.documentTitle",
33
    defaultMessage: "Apply: Defining Your Experience", // TODO: Get page title from designs.
34
    description: "The document's title shown in browser's title bar or tab.",
35
  },
36
  experienceTitle: {
37
    id: "application.experience.documentTitle",
38
    defaultMessage: "Apply: Experience",
39
    description: "The document's title shown in browser's title bar or tab.",
40
  },
41
  skillsIntroTitle: {
42
    id: "application.skillsIntro.documentTitle",
43
    defaultMessage: "Apply: Understanding Skills",
44
    description: "The document's title shown in browser's title bar or tab.",
45
  },
46
  skillsTitle: {
47
    id: "application.skills.documentTitle",
48
    defaultMessage: "Apply: Skills",
49
    description: "The document's title shown in browser's title bar or tab.",
50
  },
51
  fitTitle: {
52
    id: "application.fit.documentTitle",
53
    defaultMessage: "Apply: Application Questions",
54
    description: "The document's title shown in browser's title bar or tab.",
55
  },
56
  reviewTitle: {
57
    id: "application.review.documentTitle",
58
    defaultMessage: "Apply: Review Your Application",
59
    description: "The document's title shown in browser's title bar or tab.",
60
  },
61
  submissionTitle: {
62
    id: "application.submission.documentTitle",
63
    defaultMessage: "Apply: Submit",
64
    description: "The document's title shown in browser's title bar or tab.",
65
  },
66
});
67
68
const routes: Routes<{}, RouterResult> = [
69
  {
70
    path: "/:locale/applications/:id",
71
    children: [
72
      {
73
        path: "/welcome",
74
        action: ({ params }) => ({
75
          title: pageTitles.welcomeTitle,
76
          component: <IntroPage applicationId={Number(params.id)} />,
77
        }),
78
      },
79
      {
80
        path: "/basic",
81
        action: ({ params }) => ({
82
          title: pageTitles.basicTitle,
83
          component: <BasicInfoPage applicationId={Number(params.id)} />,
84
        }),
85
      },
86
      {
87
        path: "/experience-intro",
88
        action: ({ params }) => ({
89
          title: pageTitles.experienceIntroTitle,
90
          component: <ExperienceIntroPage applicationId={Number(params.id)} />,
91
        }),
92
      },
93
      {
94
        path: "/experience",
95
        action: ({ params }) => ({
96
          title: pageTitles.experienceTitle,
97
          component: <ExperiencePage applicationId={Number(params.id)} />,
98
        }),
99
      },
100
      {
101
        path: "/skills-intro",
102
        action: ({ params }) => ({
103
          title: pageTitles.skillsIntroTitle,
104
          component: <SkillsIntroPage applicationId={Number(params.id)} />,
105
        }),
106
      },
107
      {
108
        path: "/skills",
109
        action: ({ params }) => ({
110
          title: pageTitles.skillsTitle,
111
          component: <SkillsPage applicationId={Number(params.id)} />,
112
        }),
113
      },
114
      {
115
        path: "/fit",
116
        action: ({ params }) => ({
117
          title: pageTitles.fitTitle,
118
          component: <FitPage applicationId={Number(params.id)} />,
119
        }),
120
      },
121
      {
122
        path: "/review",
123
        action: ({ params }) => ({
124
          title: pageTitles.reviewTitle,
125
          component: <ReviewPage applicationId={Number(params.id)} />,
126
        }),
127
      },
128
      {
129
        path: "/submission",
130
        action: ({ params }) => ({
131
          title: pageTitles.submissionTitle,
132
          component: <FinalSubmitPage applicationId={Number(params.id)} />,
133
        }),
134
      },
135
      {
136
        // Redirect any unmatched url to Welcome step.
137
        path: "(.*)",
138
        action: ({ params }) => ({
139
          title: pageTitles.welcomeTitle,
140
          component: <div />,
141
          redirect: applicationWelcome(
142
            params.locale as Locales,
143
            Number(params.id),
144
          ),
145
        }),
146
      },
147
    ],
148
  },
149
];
150
151
const ApplicationRoot: React.FunctionComponent = () => {
152
  const intl = useIntl();
153
  const match = useRouter(routes, intl);
154
  const tracker: HTMLElement | null = document.getElementById(
155
    "application-root",
156
  );
157
  const trackerOffsetTop: number = tracker ? tracker.offsetTop : 0;
158
159
  return (
160
    <ScrollToTop offsetTop={trackerOffsetTop} scrollBehaviorAuto>
161
      {match}
162
    </ScrollToTop>
163
  );
164
};
165
166
if (document.getElementById("application-root")) {
167
  const root = document.getElementById("application-root");
168
  ReactDOM.render(
169
    <RootContainer>
170
      <ApplicationRoot />
171
    </RootContainer>,
172
    root,
173
  );
174
}
175