Passed
Push — feature/experience-form-modals ( 7402c2...37703b )
by Tristan
03:49
created

EducationSubform.tsx ➔ EducationSubform   B

Complexity

Conditions 1

Size

Total Lines 66
Code Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 58
dl 0
loc 66
c 0
b 0
f 0
rs 8.3745
cc 1

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 { Field, FastField } from "formik";
4
import * as Yup from "yup";
5
import CheckboxInput from "../../Form/CheckboxInput";
6
7
export interface EducationFormValues {
8
  useAsEducationRequirement: boolean;
9
}
10
11
export const validationShape = {
12
  useAsEducationRequirement: Yup.boolean(),
13
};
14
15
export interface EducationSubformProps {
16
  educationRequirement: {
17
    title: string;
18
    description: string;
19
  };
20
  equivalentRequirment: {
21
    title: string;
22
    description: string;
23
  };
24
}
25
26
const messages = defineMessages({
27
  educationJustificationLabel: {
28
    id: "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
  educationRequirement,
38
  equivalentRequirment,
39
}: EducationSubformProps): React.ReactElement {
40
  const intl = useIntl();
41
42
  const checkboxKey = "useAsEducationRequirement";
43
  return (
44
    <>
45
      <div data-c-container="medium">
46
        <p
47
          data-c-margin="top(1) bottom(1)"
48
          data-c-font-size="h4"
49
          data-c-font-weight="bold"
50
          data-c-color="c3"
51
        >
52
          <FormattedMessage
53
            id="experienceModal.educationSubtitle"
54
            defaultMessage="Use This Experience as an Education Requirement"
55
            description="Subtitle for the use-as-Education-Requirement section."
56
          />
57
        </p>
58
        <p data-c-margin="bottom(1)">
59
          <FormattedMessage
60
            id="experienceModal.educationDescription"
61
            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."
62
            description="Explanation for the use-as-Education-Requirement section."
63
          />
64
        </p>
65
      </div>
66
      <div data-c-padding="bottom(1)">
67
        <div data-c-container="medium">
68
          <div data-c-grid="gutter(all, 1) middle">
69
            <div data-c-input="checkbox(group)" data-c-grid-item="base(1of1)">
70
              <FastField
71
                key={checkboxKey}
72
                id={checkboxKey}
73
                name={checkboxKey}
74
                label={intl.formatMessage(messages.educationJustificationLabel)}
75
                component={CheckboxInput}
76
                grid="base(1of2"
77
              />
78
            </div>
79
          </div>
80
          <div
81
            data-c-background="gray(20)"
82
            data-c-radius="rounded"
83
            data-c-padding="all(1)"
84
            data-c-margin="bottom(1)"
85
          >
86
            <p data-c-font-weight="bold">{educationRequirement.title}</p>
87
            <p>{educationRequirement.description}</p>
88
            <p data-c-margin="tb(1)">
89
              <FormattedMessage
90
                id="experienceModal.educationSubform.or"
91
                defaultMessage="OR"
92
                description="Conjunction used to join alternative experience requirements (ie Experience OR Equivalent Experience)."
93
              />
94
            </p>
95
            <p data-c-font-weight="bold">{equivalentRequirment.title}</p>
96
            <p>{equivalentRequirment.description}</p>
97
          </div>
98
        </div>
99
      </div>
100
    </>
101
  );
102
}
103