Passed
Push — feature/timeline-profile ( c0d068...6ae019 )
by Tristan
04:59 queued 11s
created

EducationSubform.tsx ➔ EducationSubform   B

Complexity

Conditions 3

Size

Total Lines 76
Code Lines 64

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 64
dl 0
loc 76
rs 8.1781
c 0
b 0
f 0
cc 3

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 React from "react";
2
import { FormattedMessage, useIntl, defineMessages } from "react-intl";
3
import { FastField } from "formik";
4
import * as Yup from "yup";
5
import CheckboxInput from "../../Form/CheckboxInput";
6
import textToParagraphs from "../../../helpers/textToParagraphs";
7
import { educationMessages } from "../../JobBuilder/Details/JobDetailsMessages";
8
import { hasKey } from "../../../helpers/queries";
9
import { educationRequirementMessages } from "../applicationMessages";
10
11
export interface EducationFormValues {
12
  useAsEducationRequirement: boolean;
13
}
14
15
export const validationShape = {
16
  useAsEducationRequirement: Yup.boolean(),
17
};
18
19
export interface EducationSubformProps {
20
  keyPrefix: string;
21
  jobClassification: string;
22
  jobEducationRequirements: string | null;
23
}
24
25
const messages = defineMessages({
26
  educationJustificationLabel: {
27
    id:
28
      "application.experienceModal.educationSubform.educationJustificationLabel",
29
    defaultMessage:
30
      "Yes, this experience helps me meet the education requirements outlined below.",
31
    description:
32
      "Label for the checkbox that checks whether to use this experience to as education justification.",
33
  },
34
});
35
36
export function EducationSubform({
37
  keyPrefix,
38
  jobClassification,
39
  jobEducationRequirements,
40
}: EducationSubformProps): React.ReactElement {
41
  const intl = useIntl();
42
43
  const jobEducationReq = jobEducationRequirements;
44
  const defaultEducationReq = hasKey(educationMessages, jobClassification)
45
    ? intl.formatMessage(educationMessages[jobClassification])
46
    : intl.formatMessage(educationRequirementMessages.missingClassification);
47
  // If the job is using the default education requirements (for its classification) then we
48
  //  can predictably style it, by setting the right lines to bold. Otherwise, all we can do is
49
  //  split it into paragraphs.
50
  const educationRequirements =
51
    jobEducationReq === null || jobEducationReq === defaultEducationReq
52
      ? textToParagraphs(
53
          defaultEducationReq,
54
          {},
55
          {
56
            0: { "data-c-font-weight": "bold" },
57
            5: { "data-c-font-weight": "bold" },
58
          },
59
        )
60
      : textToParagraphs(jobEducationReq);
61
62
  const checkboxKey = "useAsEducationRequirement";
63
  return (
64
    <>
65
      <div data-c-container="medium">
66
        <p
67
          data-c-margin="top(1) bottom(1)"
68
          data-c-font-size="h4"
69
          data-c-font-weight="bold"
70
          data-c-color="c3"
71
        >
72
          <FormattedMessage
73
            id="application.experienceModal.educationSubtitle"
74
            defaultMessage="Use This Experience as an Education Requirement"
75
            description="Subtitle for the use-as-Education-Requirement section."
76
          />
77
        </p>
78
        <p data-c-margin="bottom(1)">
79
          <FormattedMessage
80
            id="application.experienceModal.educationDescription"
81
            defaultMessage="You can select the option below if you feel that this experience helps you meet some or all of the specific education requirements for this job. We've included the requirements below to help refresh your memory."
82
            description="Explanation for the use-as-Education-Requirement section."
83
          />
84
        </p>
85
      </div>
86
      <div data-c-padding="bottom(1)">
87
        <div data-c-container="medium">
88
          <div data-c-grid="gutter(all, 1) middle">
89
            <div data-c-grid-item="base(1of1)">
90
              <FastField
91
                key={checkboxKey}
92
                id={`${keyPrefix}-${checkboxKey}`}
93
                name={checkboxKey}
94
                label={intl.formatMessage(messages.educationJustificationLabel)}
95
                component={CheckboxInput}
96
                checkboxBorder
97
              />
98
            </div>
99
          </div>
100
          <div
101
            data-c-background="gray(20)"
102
            data-c-radius="rounded"
103
            data-c-padding="all(1)"
104
            data-c-margin="bottom(1)"
105
          >
106
            {educationRequirements}
107
          </div>
108
        </div>
109
      </div>
110
    </>
111
  );
112
}
113