Passed
Push — task/timeline-congrats-page ( 60126e...6c8d46 )
by Yonathan
07:44
created

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

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 187
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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