Passed
Push — dependabot/npm_and_yarn/dev/sa... ( 003e03...a9167e )
by Yonathan
06:21 queued 12s
created

resources/assets/js/components/JobCard.tsx   A

Complexity

Total Complexity 7
Complexity/F 0

Size

Lines of Code 208
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 156
mnd 7
bc 7
fnc 0
dl 0
loc 208
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import React from "react";
2
import { useIntl, defineMessages, FormattedMessage } from "react-intl";
3
import { JobStatus } from "../models/lookupConstants";
4
import { Link } from "../models/app";
5
import { jobStatus } from "../models/localizedConstants";
6
7
interface Activity {
8
  count: number;
9
  new: Link;
10
}
11
12
interface StatusPillProps {
13
  status: JobStatus;
14
  text: string;
15
}
16
17
const StatusPill: React.FC<StatusPillProps> = ({ text, status }) => (
18
  <span
19
    data-c-tag={status === JobStatus.Complete ? "go" : "c1"}
20
    data-c-font-size="small"
21
    data-c-radius="pill"
22
    data-c-margin="right(half)"
23
  >
24
    {text}
25
  </span>
26
);
27
28
export interface JobCardProps {
29
  activity: Activity;
30
  applicants: number;
31
  classification: string;
32
  draft: Link;
33
  managerTime: number;
34
  owned: boolean;
35
  preview: Link;
36
  screeningPlan: Link;
37
  summary: Link;
38
  status: JobStatus;
39
  title: string;
40
  userTime: number;
41
}
42
43
const JobCard: React.FC<JobCardProps> = ({
44
  activity,
45
  applicants,
46
  classification,
47
  draft,
48
  managerTime,
49
  owned,
50
  preview,
51
  screeningPlan,
52
  status,
53
  summary,
54
  title,
55
  userTime,
56
}) => {
57
  const intl = useIntl();
58
  return (
59
    <div
60
      data-c-card=""
61
      data-c-background="white(100)"
62
      data-c-radius="rounded"
63
      data-tc-status="in review"
64
      data-c-padding="all(normal)"
65
      data-c-margin="bottom(normal)"
66
    >
67
      <div data-c-grid="gutter middle">
68
        <div data-c-grid-item="tl(5of10)">
69
          <h2 data-c-margin="bottom(normal)" data-c-font-size="h3">
70
            {`${classification} - `}
71
            <span data-c-font-weight="bold" data-c-margin="right(normal)">
72
              {title}
73
            </span>
74
            <StatusPill
75
              text={intl.formatMessage(jobStatus(status))}
76
              status={status}
77
            />
78
          </h2>
79
80
          <p data-c-font-size="small" data-c-margin="top(normal)">
81
            {draft.url.length === 0 ? (
82
              <a
83
                href={draft.url}
84
                title={draft.title}
85
                data-c-margin="right(half)"
86
              >
87
                {draft.text}
88
              </a>
89
            ) : (
90
              <span data-c-color="gray" data-c-margin="right(half)">
91
                {draft.text}
92
              </span>
93
            )}
94
            {preview.url !== null ? (
95
              <a
96
                href={preview.url}
97
                title={preview.title}
98
                data-c-margin="right(half)"
99
              >
100
                {preview.text}
101
              </a>
102
            ) : (
103
              <span data-c-color="gray" data-c-margin="right(half)">
104
                {preview.text}
105
              </span>
106
            )}
107
            {screeningPlan.url !== null ? (
108
              <a
109
                href={screeningPlan.url}
110
                title={screeningPlan.title}
111
                data-c-margin="right(half)"
112
              >
113
                {screeningPlan.text}
114
              </a>
115
            ) : (
116
              <span data-c-color="gray" data-c-margin="right(half)">
117
                {screeningPlan.text}
118
              </span>
119
            )}
120
            <span data-c-color="gray" data-c-margin="right(half)">
121
              <FormattedMessage
122
                id="jobCard.applicants"
123
                defaultMessage={`{applicants, plural,
124
                  =0 {No Applicants}
125
                  one {# Applicant}
126
                  other {# Applicants}
127
                }`}
128
                description="Text displaying how many applicants have applied to this Job."
129
                values={{
130
                  applicants,
131
                }}
132
              />
133
            </span>
134
          </p>
135
        </div>
136
        <div data-c-grid-item="tl(3of10)">
137
          <div data-c-grid="gutter">
138
            <div data-c-grid-item="base(1of1)">
139
              <p data-c-font-size="small">
140
                <FormattedMessage
141
                  id="jobCard.managerTime"
142
                  defaultMessage={`Time with Manager: {managerTime, plural,
143
                    one {# day}
144
                    other {# days}
145
                  }`}
146
                  description="Text displaying how long a job post has been claimed by a manager."
147
                  values={{
148
                    managerTime,
149
                  }}
150
                />
151
              </p>
152
              <p data-c-font-size="small" className={owned ? "pulse" : ""}>
153
                <FormattedMessage
154
                  id="jobCard.userTime"
155
                  defaultMessage={`Time with you: <s>{userTime, plural,
156
                    one {# day}
157
                    other {# days}
158
                  }</s>`}
159
                  description="Text displaying how long a job has been claimed by the current user."
160
                  values={{
161
                    s: (msg): JSX.Element => <span>{msg}</span>,
162
                    userTime,
163
                  }}
164
                />
165
              </p>
166
              {activity.count > 0 && activity.new.url !== null ? (
167
                <a
168
                  href={activity.new.url}
169
                  title={activity.new.title}
170
                  data-c-font-size="small"
171
                  data-c-margin="top(half)"
172
                  data-c-color="stop"
173
                >
174
                  {`${activity.new.text} (${activity.count})`}
175
                </a>
176
              ) : (
177
                <p
178
                  data-c-font-size="small"
179
                  data-c-margin="top(half)"
180
                  data-c-color="gray"
181
                >
182
                  <FormattedMessage
183
                    id="jobCard.noActivity"
184
                    defaultMessage="No New Activity"
185
                    description="Fallback text for no new activity on a Job."
186
                  />
187
                </p>
188
              )}
189
            </div>
190
          </div>
191
        </div>
192
        <div data-c-grid-item="tl(2of10)" data-c-align="base(center)">
193
          <a
194
            href={summary.url !== null ? summary.url : "#"}
195
            title={summary.title}
196
            data-c-button="solid(c1)"
197
            data-c-radius="rounded"
198
          >
199
            {summary.text}
200
          </a>
201
        </div>
202
      </div>
203
    </div>
204
  );
205
};
206
207
export default JobCard;
208