Passed
Push — dev ( cca3df...2cf700 )
by Chris
04:24 queued 10s
created

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

Complexity

Total Complexity 8
Complexity/F 0

Size

Lines of Code 195
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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