Passed
Push — task/comment-feed ( 81a5e9...83e610 )
by Yonathan
19:04 queued 05:11
created

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

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 242
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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