Passed
Push — dev ( d3b83a...666ebb )
by
unknown
04:25
created

resources/assets/js/components/Application/Experience/ExperienceIntroPage.tsx   A

Complexity

Total Complexity 5
Complexity/F 0

Size

Lines of Code 76
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 65
mnd 5
bc 5
fnc 0
dl 0
loc 76
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
/* eslint-disable camelcase */
2
import React from "react";
3
import { useIntl } from "react-intl";
4
import { useDispatch } from "react-redux";
5
import { getLocale } from "../../../helpers/localize";
6
import { applicationExperience } from "../../../helpers/routes";
7
import ProgressBar, { stepNames } from "../ProgressBar/ProgressBar";
8
import { navigate } from "../../../helpers/router";
9
import makeProgressBarSteps from "../ProgressBar/progressHelpers";
10
import ExperienceIntro from "./ExperienceIntro";
11
import { DispatchType } from "../../../configureStore";
12
import { loadingMessages } from "../applicationMessages";
13
import {
14
  useApplication,
15
  useFetchAllApplicationData,
16
  useJob,
17
  useJobApplicationSteps,
18
  useTouchApplicationStep,
19
} from "../../../hooks/applicationHooks";
20
21
interface ExperienceIntroPageProps {
22
  applicationId: number;
23
}
24
25
export const ExperienceIntroPage: React.FunctionComponent<ExperienceIntroPageProps> = ({
26
  applicationId,
27
}) => {
28
  const intl = useIntl();
29
  const locale = getLocale(intl.locale);
30
  const dispatch = useDispatch<DispatchType>();
31
32
  // Fetch all un-loaded data that may be required for the Application.
33
  useFetchAllApplicationData(applicationId, dispatch);
34
35
  const application = useApplication(applicationId);
36
  const jobId = application?.job_poster_id;
37
  const job = useJob(jobId);
38
  const steps = useJobApplicationSteps();
39
40
  const stepsAreUpdating = useTouchApplicationStep(
41
    applicationId,
42
    "experience",
43
    dispatch,
44
  );
45
46
  const handleStart = (): void =>
47
    navigate(applicationExperience(locale, applicationId));
48
  const closeDate = job?.close_date_time ?? null;
49
  return application === null ? (
50
    <h2
51
      data-c-heading="h2"
52
      data-c-align="center"
53
      data-c-padding="top(2) bottom(2)"
54
    >
55
      {intl.formatMessage(loadingMessages.loading)}
56
    </h2>
57
  ) : (
58
    <>
59
      <ProgressBar
60
        closeDateTime={closeDate}
61
        currentTitle={intl.formatMessage(stepNames.step02)}
62
        steps={makeProgressBarSteps(
63
          applicationId,
64
          steps,
65
          intl,
66
          "experience",
67
          stepsAreUpdating,
68
        )}
69
      />
70
      <ExperienceIntro handleStart={handleStart} />
71
    </>
72
  );
73
};
74
75
export default ExperienceIntroPage;
76