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

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

Complexity

Total Complexity 6
Complexity/F 0

Size

Lines of Code 207
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 159
mnd 6
bc 6
fnc 0
dl 0
loc 207
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 ExperienceCommunityAccordionProps {
11
  role: string;
12
  group: 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 experienceCommunityDetails = ({
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="experienceCommunityAccordion.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="experienceCommunityAccordion.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="experienceCommunityAccordion.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="experienceCommunityAccordion.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="experienceCommunityAccordion.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="experienceCommunityAccordion.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="experienceCommunityAccordion.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="experienceCommunityAccordion.endDate"
129
            defaultMessage="End Date:"
130
          />
131
        </p>
132
        {isActive && (
133
          <p>
134
            <FormattedMessage
135
              id="experienceCommunityAccordion.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 ExperienceCommunityAccordion: React.FC<ExperienceCommunityAccordionProps> = ({
151
  role,
152
  group,
153
  startDate,
154
  endDate,
155
  isActive,
156
157
  relevantSkills,
158
  irrelevantSkillCount,
159
  isEducationJustification,
160
  showSkillDetails,
161
  showButtons,
162
  handleDelete,
163
  handleEdit,
164
}) => {
165
  const intl = useIntl();
166
  const locale = getLocale(intl.locale);
167
  const accordionTitle = (
168
    <p>
169
      <FormattedMessage
170
        id="experienceCommunityAccordion.title"
171
        defaultMessage="<b>{role}</b> - {group}"
172
        description="Title of Community Experience accordion (this is the visible text when accordion is closed)."
173
        values={{
174
          role,
175
          group,
176
          b: value => <span data-c-font-weight="bold">{value}</span>,
177
        }}
178
      />
179
    </p>
180
  );
181
  return (
182
    <BaseExperienceAccordion
183
      title={accordionTitle}
184
      iconClass="fa-book"
185
      relevantSkills={relevantSkills}
186
      irrelevantSkillCount={irrelevantSkillCount}
187
      isEducationJustification={isEducationJustification}
188
      details={experienceCommunityDetails({
189
        locale,
190
        educationType,
191
        areaOfStudy,
192
        institution,
193
        status,
194
        startDate,
195
        endDate,
196
        isActive,
197
      })}
198
      showSkillDetails={showSkillDetails}
199
      showButtons={showButtons}
200
      handleDelete={handleDelete}
201
      handleEdit={handleEdit}
202
    />
203
  );
204
};
205
206
export default ExperienceCommunityAccordion;
207