Passed
Push — dev ( 350847...de40c8 )
by
unknown
05:16
created

resources/assets/js/components/HRPortal/JobIndexHr.tsx   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 226
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 174
mnd 1
bc 1
fnc 0
dl 0
loc 226
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import React, { useState, useMemo } from "react";
2
import { FormattedMessage } from "react-intl";
3
import JobCard, { JobCardProps } from "../JobCard";
4
import UnclaimedJobCard, { UnclaimedJobCardProps } from "../UnclaimedJobCard";
5
import { JobStatus } from "../../models/lookupConstants";
6
7
interface CompletedJobsAccordionProps {
8
  completedJobActions: JobCardProps[];
9
}
10
11
const CompletedJobsAccordion: React.FC<CompletedJobsAccordionProps> = ({
12
  completedJobActions,
13
}) => {
14
  const [isExpanded, setIsExpanded] = useState(false);
15
16
  return (
17
    <section data-c-accordion-group data-c-margin="top(triple)">
18
      <div data-c-accordion="" className={`${isExpanded && "active"}`}>
19
        <button
20
          aria-expanded={isExpanded}
21
          data-c-accordion-trigger
22
          tabIndex={0}
23
          type="button"
24
          onClick={(): void => {
25
            setIsExpanded(!isExpanded);
26
          }}
27
        >
28
          <div>
29
            <h3 data-c-font-size="h3" data-c-color="c3">
30
              <FormattedMessage
31
                id="hrPortal.jobPageIndex.completedJobsHeader"
32
                description="Header for completed jobs accordion section."
33
                defaultMessage="My Completed Job Actions"
34
              />
35
            </h3>
36
          </div>
37
          <span data-c-visibility="invisible">
38
            <FormattedMessage
39
              id="hrPortal.jobPageIndex.clickToView"
40
              description="Accordion trigger message for screen readers."
41
              defaultMessage="Click to view..."
42
            />
43
          </span>
44
          <p
45
            data-c-accordion-add
46
            data-c-font-style="underline"
47
            data-c-color="c2"
48
          >
49
            <FormattedMessage
50
              id="hrPortal.jobPageIndex.showAccordion"
51
              description="Accordion trigger message to show items."
52
              defaultMessage="Show"
53
            />
54
          </p>
55
          <p
56
            data-c-accordion-remove
57
            data-c-font-style="underline"
58
            data-c-color="c2"
59
          >
60
            <FormattedMessage
61
              id="hrPortal.jobPageIndex.hideAccordion"
62
              description="Accordion trigger message to hide items."
63
              defaultMessage="Hide"
64
            />
65
          </p>
66
        </button>
67
        <div
68
          aria-hidden="true"
69
          data-c-accordion-content
70
          data-c-padding="top(double)"
71
        >
72
          <div>
73
            {(completedJobActions.length !== 0 &&
74
              completedJobActions.map(
75
                (jobAction): React.ReactElement => {
76
                  return <JobCard key={jobAction.id} {...jobAction} />;
77
                },
78
              )) || (
79
              <p>
80
                <FormattedMessage
81
                  id="hrPortal.jobPageIndex.noJobsCompleted"
82
                  description="Message displayed if the completed jobs list is empty."
83
                  defaultMessage="No jobs completed yet!"
84
                />
85
              </p>
86
            )}
87
          </div>
88
        </div>
89
      </div>
90
    </section>
91
  );
92
};
93
94
interface JobIndexHrProps {
95
  jobActions: JobCardProps[];
96
  unclaimedJobs: UnclaimedJobCardProps[];
97
  departmentName: string;
98
}
99
100
const JobIndexHr: React.FunctionComponent<JobIndexHrProps> = ({
101
  jobActions,
102
  unclaimedJobs,
103
  departmentName,
104
}) => {
105
  const notCompletedJobActions: JobCardProps[] = useMemo(
106
    () =>
107
      jobActions.filter(
108
        (jobAction) => jobAction.status.key !== JobStatus.Completed,
109
      ),
110
    [jobActions],
111
  );
112
113
  const completedJobActions: JobCardProps[] = useMemo(
114
    () =>
115
      jobActions.filter(
116
        (jobAction) => jobAction.status.key === JobStatus.Completed,
117
      ),
118
    [jobActions],
119
  );
120
121
  const sortByCurrentDate = (
122
    a: UnclaimedJobCardProps,
123
    b: UnclaimedJobCardProps,
124
  ): number => {
125
    if (b.reviewRequested && a.reviewRequested) {
126
      return b.reviewRequested.getTime() - a.reviewRequested.getTime();
127
    }
128
    return 0;
129
  };
130
131
  return (
132
    <section>
133
      <div
134
        data-c-background="gray(10)"
135
        data-c-border="bottom(thin, solid, black)"
136
      >
137
        <div data-c-container="large" data-c-padding="tb(triple)">
138
          {/*
139
          <p>
140
            <FormattedMessage
141
              id="hrPortal.jobPageIndex.welcomeMessage"
142
              description="Welcome message at beginning of page."
143
              defaultMessage="Welcome! Introductory copy that explains how this page works, and what an HR advisor needs to do to claim a job action as their own. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium ducimus laboriosam sequi, quis autem minima esse quasi aspernatur vero provident quos eligendi, ea officia exercitationem. Obcaecati impedit quae veritatis corrupti!"
144
            />
145
          </p>
146
          */}
147
          <h2 data-c-font-size="h2" data-c-margin="bottom(normal)">
148
            <FormattedMessage
149
              id="hrPortal.jobPageIndex.jobActionsHeader"
150
              description="Header for my job actions section."
151
              defaultMessage="My Job Actions"
152
            />
153
          </h2>
154
          <p data-c-margin="bottom(double)">
155
            <FormattedMessage
156
              id="hrPortal.jobPageIndex.jobActionsMessage"
157
              description="Message before list of users job actions."
158
              defaultMessage="This is a list of all job actions you are currently participating in. Looking for an older job? Check the 'My Completed Job Actions' section below your active jobs."
159
            />
160
          </p>
161
162
          {/* Users Job Actions List */}
163
          {/* Not Completed */}
164
          {(notCompletedJobActions.length !== 0 &&
165
            notCompletedJobActions.map(
166
              (jobAction): React.ReactElement => {
167
                return <JobCard key={jobAction.id} {...jobAction} />;
168
              },
169
            )) || (
170
            <p>
171
              <FormattedMessage
172
                id="hrPortal.jobPageIndex.jobActionsEmpty"
173
                description="Message displayed if the jobs actions list is empty."
174
                defaultMessage="Claim a job below!"
175
              />
176
            </p>
177
          )}
178
179
          {/* Completed */}
180
          <CompletedJobsAccordion completedJobActions={completedJobActions} />
181
182
          <hr data-c-margin="tb(triple)" data-c-hr="gray" />
183
          <h2 data-c-font-size="h2" data-c-margin="top(triple) bottom(double)">
184
            <FormattedMessage
185
              id="hrPortal.jobPageIndex.preDepartmentName"
186
              description="Message before department name."
187
              defaultMessage="All Jobs in"
188
            />
189
            {` ${departmentName}`}
190
          </h2>
191
          <p data-c-margin="bottom(double)">
192
            <FormattedMessage
193
              id="hrPortal.jobPageIndex.unclaimedJobsMessage"
194
              description="Message before list of unclaimed jobs."
195
              defaultMessage="This is the list of all active job actions in your department. From here you can 'claim' a job, which will move it into your jobs list above and allow you to begin working with the hiring manager on finding the best talent possible. If you claim a job by accident, no fear, for you can click into the job summary and remove yourself using the 'Relinquish This Job' button."
196
            />
197
          </p>
198
199
          {/* Unclaimed Jobs List */}
200
          <section data-c-grid="gutter">
201
            {unclaimedJobs.length !== 0 &&
202
              unclaimedJobs.sort(sortByCurrentDate).map(
203
                (unclaimedJob): React.ReactElement => {
204
                  return (
205
                    <UnclaimedJobCard key={unclaimedJob.id} {...unclaimedJob} />
206
                  );
207
                },
208
              )}
209
          </section>
210
          {unclaimedJobs.length === 0 && (
211
            <p>
212
              <FormattedMessage
213
                id="hrPortal.jobPageIndex.unclaimedJobsEmpty"
214
                description="Message displayed if the unclaimed jobs list is empty."
215
                defaultMessage="There are currently no active jobs available."
216
              />
217
            </p>
218
          )}
219
        </div>
220
      </div>
221
    </section>
222
  );
223
};
224
225
export default JobIndexHr;
226