Passed
Push — dev ( 047874...28c92f )
by Chris
05:17 queued 13s
created

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

Complexity

Total Complexity 5
Complexity/F 0

Size

Lines of Code 171
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 132
mnd 5
bc 5
fnc 0
dl 0
loc 171
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import React from "react";
2
import { FormattedMessage, useIntl, IntlShape } from "react-intl";
3
import {
4
  ExperienceSkill,
5
  BaseExperienceAccordion,
6
  titleBarDateRange,
7
  baseExperienceMessages,
8
} from "./BaseExperienceAccordion";
9
import { Locales, getLocale } from "../../../helpers/localize";
10
import { readableDate } from "../../../helpers/dates";
11
12
interface ExperienceWorkAccordionProps {
13
  title: string;
14
  organization: string;
15
  group: string;
16
  startDate: Date;
17
  endDate: Date | null;
18
  isActive: boolean;
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 experienceWorkDetails = ({
29
  locale,
30
  intl,
31
  title,
32
  organization,
33
  group,
34
  startDate,
35
  endDate,
36
  isActive,
37
}: {
38
  locale: Locales;
39
  intl: IntlShape;
40
  title: string;
41
  organization: string;
42
  group: string;
43
  startDate: Date;
44
  endDate: Date | null;
45
  isActive: boolean;
46
}): React.ReactElement => {
47
  const notApplicable = (
48
    <p data-c-color="gray">
49
      {intl.formatMessage(baseExperienceMessages.notApplicable)}
50
    </p>
51
  );
52
  return (
53
    <>
54
      <div data-c-grid-item="base(1of2) tl(1of3)">
55
        <p data-c-font-weight="bold">
56
          {intl.formatMessage(baseExperienceMessages.experienceTypeLabel)}
57
        </p>
58
        <p>
59
          <i
60
            className="fas fa-briefcase"
61
            data-c-color="c1"
62
            data-c-margin="right(.25)"
63
          />
64
          <FormattedMessage
65
            id="experienceWorkAccordion.experienceTypeTitle"
66
            defaultMessage="Work Experience"
67
          />
68
        </p>
69
      </div>
70
      <div data-c-grid-item="base(1of2) tl(1of3)">
71
        <p data-c-font-weight="bold">
72
          <FormattedMessage
73
            id="experienceWorkAccordion.roleLabel"
74
            defaultMessage="Role / Job Title:"
75
          />
76
        </p>
77
        {title ? <p>{title}</p> : notApplicable}
78
      </div>
79
      <div data-c-grid-item="base(1of2) tl(1of3)">
80
        <p data-c-font-weight="bold">
81
          <FormattedMessage
82
            id="experienceWorkAccordion.organizationLabel"
83
            defaultMessage="Organization / Company:"
84
          />
85
        </p>
86
        {organization ? <p>{organization}</p> : notApplicable}
87
      </div>
88
      <div data-c-grid-item="base(1of2) tl(1of3)">
89
        <p data-c-font-weight="bold">
90
          <FormattedMessage
91
            id="experienceWorkAccordion.teamLabel"
92
            defaultMessage="Team / Group:"
93
          />
94
        </p>
95
        {group ? <p>{group}</p> : notApplicable}
96
      </div>
97
      <div data-c-grid-item="base(1of2) tl(1of3)">
98
        <p data-c-font-weight="bold">
99
          {intl.formatMessage(baseExperienceMessages.startDateLabel)}
100
        </p>
101
        {startDate ? <p>{readableDate(locale, startDate)}</p> : notApplicable}
102
      </div>
103
      <div data-c-grid-item="base(1of2) tl(1of3)">
104
        <p data-c-font-weight="bold">
105
          {intl.formatMessage(baseExperienceMessages.endDateLabel)}
106
        </p>
107
        {isActive && (
108
          <p>{intl.formatMessage(baseExperienceMessages.ongoing)}</p>
109
        )}
110
        {!isActive && endDate ? (
111
          <p>{readableDate(locale, endDate)}</p>
112
        ) : (
113
          notApplicable
114
        )}
115
      </div>
116
    </>
117
  );
118
};
119
120
export const ExperienceWorkAccordion: React.FC<ExperienceWorkAccordionProps> = ({
121
  title,
122
  organization,
123
  group,
124
  startDate,
125
  endDate,
126
  isActive,
127
  relevantSkills,
128
  irrelevantSkillCount,
129
  isEducationJustification,
130
  showSkillDetails,
131
  showButtons,
132
  handleDelete,
133
  handleEdit,
134
}) => {
135
  const intl = useIntl();
136
  const locale = getLocale(intl.locale);
137
  const accordionTitle = (
138
    <>
139
      <p>
140
        <span data-c-font-weight="bold">{title}</span> - {organization}
141
      </p>
142
      {titleBarDateRange(startDate, endDate, isActive, locale)}
143
    </>
144
  );
145
  return (
146
    <BaseExperienceAccordion
147
      title={accordionTitle}
148
      iconClass="fa-briefcase"
149
      relevantSkills={relevantSkills}
150
      irrelevantSkillCount={irrelevantSkillCount}
151
      isEducationJustification={isEducationJustification}
152
      details={experienceWorkDetails({
153
        locale,
154
        intl,
155
        title,
156
        organization,
157
        group,
158
        startDate,
159
        endDate,
160
        isActive,
161
      })}
162
      showSkillDetails={showSkillDetails}
163
      showButtons={showButtons}
164
      handleDelete={handleDelete}
165
      handleEdit={handleEdit}
166
    />
167
  );
168
};
169
170
export default ExperienceWorkAccordion;
171