Passed
Push — task/common-translation-packag... ( dbb970...52324d )
by Tristan
06:50 queued 11s
created

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

Complexity

Total Complexity 7
Complexity/F 0

Size

Lines of Code 203
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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