Passed
Push — dev ( 05fc2a...74a584 )
by
unknown
05:49
created

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

Complexity

Total Complexity 6
Complexity/F 0

Size

Lines of Code 218
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 170
mnd 6
bc 6
fnc 0
dl 0
loc 218
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
1
import React from "react";
2
import { FormattedMessage, useIntl, IntlShape } from "react-intl";
3
import {
4
  ExperienceSkill,
5
  BaseExperienceAccordion,
6
  baseExperienceMessages,
7
} from "./BaseExperienceAccordion";
8
import { Locales, getLocale } from "../../../helpers/localize";
9
import { readableDate } from "../../../helpers/dates";
10
import { Link } from "../../../models/app";
11
12
interface ExperienceAwardAccordionProps {
13
  title: string;
14
  recipient: string;
15
  issuer: string;
16
  scope: string;
17
  awardedDate: Date;
18
  awardLink: Link;
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 experienceAwardDetails = ({
29
  locale,
30
  intl,
31
  title,
32
  recipient,
33
  issuer,
34
  scope,
35
  awardedDate,
36
  awardLink,
37
}: {
38
  locale: Locales;
39
  intl: IntlShape;
40
  title: string;
41
  recipient: string;
42
  issuer: string;
43
  scope: string;
44
  awardedDate: Date;
45
  awardLink: Link;
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-trophy"
61
            data-c-color="c1"
62
            data-c-margin="right(.25)"
63
          />
64
          <FormattedMessage
65
            id="experienceAwardAccordion.experienceTypeTitle"
66
            defaultMessage="Award 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="experienceAwardAccordion.awardTitleLabel"
74
            defaultMessage="Award 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="experienceAwardAccordion.recipientLabel"
83
            defaultMessage="Awarded to:"
84
          />
85
        </p>
86
        {recipient ? <p>{recipient}</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="experienceAwardAccordion.issuerLabel"
92
            defaultMessage="Issuing Organization / Institution:"
93
          />
94
        </p>
95
        {issuer ? <p>{issuer}</p> : notApplicable}
96
      </div>
97
      <div data-c-grid-item="base(1of2) tl(1of3)">
98
        <p data-c-font-weight="bold">
99
          <FormattedMessage
100
            id="experienceAwardAccordion.scopeLabel"
101
            defaultMessage="Award Eligibility / Scope:"
102
          />
103
        </p>
104
        {scope ? <p>{scope}</p> : notApplicable}
105
      </div>
106
      <div data-c-grid-item="base(1of2) tl(1of3)">
107
        <p data-c-font-weight="bold">
108
          <FormattedMessage
109
            id="experienceAwardAccordion.awardedDateLabel"
110
            defaultMessage="Date Awarded:"
111
          />
112
        </p>
113
        {awardedDate ? (
114
          <p>{readableDate(locale, awardedDate)}</p>
115
        ) : (
116
          notApplicable
117
        )}
118
      </div>
119
      <div data-c-grid-item="base(1of2) tl(1of3)">
120
        <p data-c-font-weight="bold">
121
          <FormattedMessage
122
            id="experienceAwardAccordion.linkLabel"
123
            defaultMessage="Link to award Date:"
124
          />
125
        </p>
126
        {awardLink && awardLink.url ? (
127
          <p>
128
            <a
129
              href={awardLink.url}
130
              title={awardLink.title}
131
              target="_blank"
132
              rel="noreferrer"
133
            >
134
              {awardLink.text}
135
            </a>
136
          </p>
137
        ) : (
138
          notApplicable
139
        )}
140
      </div>
141
    </>
142
  );
143
};
144
145
export const ExperienceAwardAccordion: React.FC<ExperienceAwardAccordionProps> = ({
146
  title,
147
  recipient,
148
  issuer,
149
  scope,
150
  awardedDate,
151
  awardLink,
152
  relevantSkills,
153
  irrelevantSkillCount,
154
  isEducationJustification,
155
  showSkillDetails,
156
  showButtons,
157
  handleDelete,
158
  handleEdit,
159
}) => {
160
  const intl = useIntl();
161
  const locale = getLocale(intl.locale);
162
  const accordionTitle = (
163
    <>
164
      <p>
165
        <FormattedMessage
166
          id="experienceAwardAccordion.title"
167
          defaultMessage="<b>{title}</b> - {institution}"
168
          description="Title of Award Experience accordion (this is the visible text when accordion is closed)."
169
          values={{
170
            title,
171
            institution: issuer,
172
            b: (value) => <span data-c-font-weight="bold">{value}</span>,
173
          }}
174
        />
175
      </p>
176
      <p
177
        data-c-margin="top(quarter)"
178
        data-c-colour="c1"
179
        data-c-font-size="small"
180
      >
181
        <FormattedMessage
182
          id="experienceAwardAccordion.titleDate"
183
          defaultMessage="Awarded on: {date}"
184
          description="Shows the awarded date in the accordion title bar."
185
          values={{
186
            date: readableDate(locale, awardedDate),
187
          }}
188
        />
189
      </p>
190
    </>
191
  );
192
  return (
193
    <BaseExperienceAccordion
194
      title={accordionTitle}
195
      iconClass="fa-trophy"
196
      relevantSkills={relevantSkills}
197
      irrelevantSkillCount={irrelevantSkillCount}
198
      isEducationJustification={isEducationJustification}
199
      details={experienceAwardDetails({
200
        locale,
201
        intl,
202
        title,
203
        recipient,
204
        issuer,
205
        scope,
206
        awardedDate,
207
        awardLink,
208
      })}
209
      showSkillDetails={showSkillDetails}
210
      showButtons={showButtons}
211
      handleDelete={handleDelete}
212
      handleEdit={handleEdit}
213
    />
214
  );
215
};
216
217
export default ExperienceAwardAccordion;
218