Passed
Push — feature/application-experience... ( 98b950...b54758 )
by Tristan
03:55
created

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

Complexity

Total Complexity 6
Complexity/F 0

Size

Lines of Code 210
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 160
mnd 6
bc 6
fnc 0
dl 0
loc 210
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
1
import React from "react";
2
import { FormattedMessage, useIntl } from "react-intl";
3
import {
4
  ExperienceSkill,
5
  BaseExperienceAccordion,
6
} from "./BaseExperienceAccordion";
7
import { Locales, getLocale } from "../../../helpers/localize";
8
import { readableDate } from "../../../helpers/dates";
9
10
interface ExperienceEducationAccordionProps {
11
  educationType: string;
12
  areaOfStudy: string;
13
  institution: string;
14
  status: string;
15
  startDate: Date;
16
  endDate: Date;
17
  isActive: boolean;
18
19
  relevantSkills: ExperienceSkill[];
20
  irrelevantSkillCount: number;
21
  isEducationJustification: boolean;
22
  showSkillDetails: boolean;
23
  showButtons: boolean;
24
  handleDelete: () => void;
25
  handleEdit: () => void;
26
}
27
28
const experienceEducationDetails = ({
29
  locale,
30
  educationType,
31
  areaOfStudy,
32
  institution,
33
  status,
34
  startDate,
35
  endDate,
36
  isActive,
37
}: {
38
  locale: Locales;
39
  educationType: string;
40
  areaOfStudy: string;
41
  institution: string;
42
  status: string;
43
  startDate: Date;
44
  endDate: Date;
45
  isActive: boolean;
46
}): React.ReactElement => {
47
  const notApplicable = (
48
    <p data-c-color="gray">
49
      <FormattedMessage
50
        id="experienceWorkAccordion.notApplicable"
51
        defaultMessage="N/A"
52
      />
53
    </p>
54
  );
55
  return (
56
    <>
57
      <div data-c-grid-item="base(1of2) tl(1of3)">
58
        <p data-c-font-weight="bold">
59
          <FormattedMessage
60
            id="experienceEducationAccordion.experienceTypeLabel"
61
            defaultMessage="Type of Experience:"
62
          />
63
        </p>
64
        <p>
65
          <i
66
            className="fas fa-briefcase"
67
            data-c-color="c1"
68
            data-c-margin="right(.25)"
69
          />
70
          <FormattedMessage
71
            id="experienceEducationAccordion.experienceTypeTitle"
72
            defaultMessage="Education Experience"
73
          />
74
        </p>
75
      </div>
76
      <div data-c-grid-item="base(1of2) tl(1of3)">
77
        <p data-c-font-weight="bold">
78
          <FormattedMessage
79
            id="experienceEducationAccordion.educationTypeLabel"
80
            defaultMessage="Type of Education:"
81
          />
82
          {educationType ? <p>{educationType}</p> : { notApplicable }}
83
        </p>
84
      </div>
85
      <div data-c-grid-item="base(1of2) tl(1of3)">
86
        <p data-c-font-weight="bold">
87
          <FormattedMessage
88
            id="experienceEducationAccordion.areaOfStudyLabel"
89
            defaultMessage="Area of Study:"
90
          />
91
        </p>
92
        {areaOfStudy ? <p>{areaOfStudy}</p> : { notApplicable }}
93
      </div>
94
      <div data-c-grid-item="base(1of2) tl(1of3)">
95
        <p data-c-font-weight="bold">
96
          <FormattedMessage
97
            id="experienceEducationAccordion.institutionLabel"
98
            defaultMessage="Institution:"
99
          />
100
        </p>
101
        {institution ? <p>{institution}</p> : { notApplicable }}
102
      </div>
103
      <div data-c-grid-item="base(1of2) tl(1of3)">
104
        <p data-c-font-weight="bold">
105
          <FormattedMessage
106
            id="experienceEducationAccordion.statusLabel"
107
            defaultMessage="Status:"
108
          />
109
        </p>
110
        {status ? <p>{status}</p> : { notApplicable }}
111
      </div>
112
      <div data-c-grid-item="base(1of2) tl(1of3)">
113
        <p data-c-font-weight="bold">
114
          <FormattedMessage
115
            id="experienceEducationAccordion.startDate"
116
            defaultMessage="Start Date:"
117
          />
118
        </p>
119
        {startDate ? (
120
          <p>{readableDate(locale, startDate)}</p>
121
        ) : (
122
          { notApplicable }
123
        )}
124
      </div>
125
      <div data-c-grid-item="base(1of2) tl(1of3)">
126
        <p data-c-font-weight="bold">
127
          <FormattedMessage
128
            id="experienceEducationAccordion.endDate"
129
            defaultMessage="End Date:"
130
          />
131
        </p>
132
        {isActive && (
133
          <p>
134
            <FormattedMessage
135
              id="experienceEducationAccordion.ongoing"
136
              defaultMessage="Ongoing"
137
            />
138
          </p>
139
        )}
140
        {!isActive && endDate ? (
141
          <p>{readableDate(locale, endDate)}</p>
142
        ) : (
143
          { notApplicable }
144
        )}
145
      </div>
146
    </>
147
  );
148
};
149
150
export const ExperienceEducationAccordion: React.FC<ExperienceEducationAccordionProps> = ({
151
  educationType,
152
  areaOfStudy,
153
  institution,
154
  status,
155
  startDate,
156
  endDate,
157
  isActive,
158
159
  relevantSkills,
160
  irrelevantSkillCount,
161
  isEducationJustification,
162
  showSkillDetails,
163
  showButtons,
164
  handleDelete,
165
  handleEdit,
166
}) => {
167
  const intl = useIntl();
168
  const locale = getLocale(intl.locale);
169
  const accordionTitle = (
170
    <p>
171
      <FormattedMessage
172
        id="experienceEducationAccordion.title"
173
        defaultMessage="<b>{educationType} in {areaOfStudy}</b> - {institution}"
174
        description="Title of education accordion (this is the visible text when accordion is closed)."
175
        values={{
176
          educationType,
177
          areaOfStudy,
178
          institution,
179
          b: value => <span data-c-font-weight="bold">{value}</span>,
180
        }}
181
      />
182
    </p>
183
  );
184
  return (
185
    <BaseExperienceAccordion
186
      title={accordionTitle}
187
      iconClass="fa-book"
188
      relevantSkills={relevantSkills}
189
      irrelevantSkillCount={irrelevantSkillCount}
190
      isEducationJustification={isEducationJustification}
191
      details={experienceEducationDetails({
192
        locale,
193
        educationType,
194
        areaOfStudy,
195
        institution,
196
        status,
197
        startDate,
198
        endDate,
199
        isActive,
200
      })}
201
      showSkillDetails={showSkillDetails}
202
      showButtons={showButtons}
203
      handleDelete={handleDelete}
204
      handleEdit={handleEdit}
205
    />
206
  );
207
};
208
209
export default ExperienceEducationAccordion;
210