Passed
Push — task/upgrade-to-laravel-8 ( d9ea58...580a94 )
by Grant
03:49
created

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

Complexity

Total Complexity 6
Complexity/F 0

Size

Lines of Code 168
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 131
mnd 6
bc 6
fnc 0
dl 0
loc 168
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 ExperienceCommunityAccordionProps {
13
  title: string;
14
  group: string;
15
  project: string;
16
  startDate: Date;
17
  endDate: Date | null;
18
  isActive: boolean;
19
  relevantSkills: ExperienceSkill[];
20
  skills: Skill[];
21
  irrelevantSkillCount: number;
22
  isEducationJustification: boolean;
23
  showSkillDetails: boolean;
24
  showButtons: boolean;
25
  handleDelete: () => Promise<void>;
26
  handleEdit: () => void;
27
}
28
29
const experienceCommunityDetails = ({
30
  locale,
31
  intl,
32
  title,
33
  group,
34
  project,
35
  startDate,
36
  endDate,
37
  isActive,
38
}: {
39
  locale: Locales;
40
  intl: IntlShape;
41
  title: string;
42
  group: string;
43
  project: string;
44
  startDate: Date;
45
  endDate: Date | null;
46
  isActive: boolean;
47
}): React.ReactElement => {
48
  const notApplicable = (
49
    <p data-c-color="gray">
50
      {intl.formatMessage(accordionMessages.notApplicable)}
51
    </p>
52
  );
53
  const endDateOrNa = endDate ? (
54
    <p>{readableDate(locale, endDate)}</p>
55
  ) : (
56
    notApplicable
57
  );
58
  return (
59
    <>
60
      <div data-c-grid-item="base(1of2) tl(1of3)">
61
        <p data-c-font-weight="bold">
62
          {intl.formatMessage(accordionMessages.experienceTypeLabel)}
63
        </p>
64
        <p>
65
          <i
66
            className="fas fa-people-carry"
67
            data-c-color="c1"
68
            data-c-margin="right(.25)"
69
          />
70
          {intl.formatMessage(accordionMessages.communityType)}
71
        </p>
72
      </div>
73
      <div data-c-grid-item="base(1of2) tl(1of3)">
74
        <p data-c-font-weight="bold">
75
          {intl.formatMessage(accordionMessages.communityRoleLabel)}
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
          {intl.formatMessage(accordionMessages.communityOrganizationLabel)}
82
        </p>
83
        {group ? <p>{group}</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.communityProjectLabel)}
88
        </p>
89
        {project ? <p>{project}</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.startDateLabel)}
94
        </p>
95
        {startDate ? <p>{readableDate(locale, startDate)}</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.endDateLabel)}
100
        </p>
101
        {isActive ? (
102
          <p>{intl.formatMessage(accordionMessages.ongoing)}</p>
103
        ) : (
104
          endDateOrNa
105
        )}
106
      </div>
107
    </>
108
  );
109
};
110
111
export const ExperienceCommunityAccordion: React.FC<ExperienceCommunityAccordionProps> = ({
112
  title,
113
  group,
114
  project,
115
  startDate,
116
  endDate,
117
  isActive,
118
  relevantSkills,
119
  skills,
120
  irrelevantSkillCount,
121
  isEducationJustification,
122
  showSkillDetails,
123
  showButtons,
124
  handleDelete,
125
  handleEdit,
126
}) => {
127
  const intl = useIntl();
128
  const locale = getLocale(intl.locale);
129
  const accordionTitle = (
130
    <>
131
      <p>
132
        {intl.formatMessage(accordionMessages.communityHeading, {
133
          title,
134
          group,
135
          b: (value) => <span data-c-font-weight="bold">{value}</span>,
136
        })}
137
      </p>
138
      {titleBarDateRange(startDate, endDate, isActive, intl, locale)}
139
    </>
140
  );
141
  return (
142
    <BaseExperienceAccordion
143
      title={accordionTitle}
144
      iconClass="fa-people-carry"
145
      relevantSkills={relevantSkills}
146
      skills={skills}
147
      irrelevantSkillCount={irrelevantSkillCount}
148
      isEducationJustification={isEducationJustification}
149
      details={experienceCommunityDetails({
150
        locale,
151
        intl,
152
        title,
153
        group,
154
        project,
155
        startDate,
156
        endDate,
157
        isActive,
158
      })}
159
      showSkillDetails={showSkillDetails}
160
      showButtons={showButtons}
161
      handleDelete={handleDelete}
162
      handleEdit={handleEdit}
163
    />
164
  );
165
};
166
167
export default ExperienceCommunityAccordion;
168