Passed
Push — task/application-handle-step-s... ( 5f39f9 )
by Yonathan
08:23
created

progressHelpers.ts ➔ makeProgressBarSteps   B

Complexity

Conditions 7

Size

Total Lines 64
Code Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 52
c 0
b 0
f 0
dl 0
loc 64
rs 7.1709
cc 7

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
import { IntlShape } from "react-intl";
2
import { ApplicationNormalized } from "../../../models/types";
3
import { ProgressBarProps, stepNames } from "./ProgressBar";
4
import {
5
  applicationBasic,
6
  applicationExperienceIntro,
7
  applicationSkills,
8
  applicationFit,
9
  applicationReview,
10
  applicationSubmission,
11
} from "../../../helpers/routes";
12
import { getLocale } from "../../../helpers/localize";
13
import { ProgressBarStatus } from "../../../models/lookupConstants";
14
15
export function makeProgressBarSteps(
16
  applicationId: number,
17
  steps: { [key in string]: ProgressBarStatus },
18
  intl: IntlShape,
19
  currentStep:
20
    | "welcome"
21
    | "basic"
22
    | "experience"
23
    | "skills"
24
    | "fit"
25
    | "review"
26
    | "submission"
27
    | "other",
28
): ProgressBarProps["steps"] {
29
  const locale = getLocale(intl.locale);
30
  return [
31
    {
32
      link: {
33
        url: applicationBasic(locale, applicationId),
34
        text: intl.formatMessage(stepNames.step01),
35
        title: intl.formatMessage(stepNames.step01),
36
      },
37
      status: currentStep === "basic" ? "current" : steps.basic,
38
    },
39
    {
40
      link: {
41
        url: applicationExperienceIntro(locale, applicationId),
42
        text: intl.formatMessage(stepNames.step02),
43
        title: intl.formatMessage(stepNames.step02),
44
      },
45
      status: currentStep === "experience" ? "current" : steps.experience,
46
    },
47
    {
48
      link: {
49
        url: applicationSkills(locale, applicationId),
50
        text: intl.formatMessage(stepNames.step03),
51
        title: intl.formatMessage(stepNames.step03),
52
      },
53
      status: currentStep === "skills" ? "current" : steps.skills,
54
    },
55
    {
56
      link: {
57
        url: applicationFit(locale, applicationId),
58
        text: intl.formatMessage(stepNames.step04),
59
        title: intl.formatMessage(stepNames.step04),
60
      },
61
      status: currentStep === "fit" ? "current" : steps.fit,
62
    },
63
    {
64
      link: {
65
        url: applicationReview(locale, applicationId),
66
        text: intl.formatMessage(stepNames.step05),
67
        title: intl.formatMessage(stepNames.step05),
68
      },
69
      status: currentStep === "review" ? "current" : steps.review,
70
    },
71
    {
72
      link: {
73
        url: applicationSubmission(locale, applicationId),
74
        text: intl.formatMessage(stepNames.step06),
75
        title: intl.formatMessage(stepNames.step06),
76
      },
77
      status: currentStep === "submission" ? "current" : steps.submission,
78
    },
79
  ];
80
}
81
82
export default makeProgressBarSteps;
83