1
|
|
|
import React, { useEffect } from "react"; |
2
|
|
|
import { useIntl, FormattedMessage, defineMessages } from "react-intl"; |
3
|
|
|
import { useDispatch, useSelector } from "react-redux"; |
4
|
|
|
import ReactDOM from "react-dom"; |
5
|
|
|
import RootContainer from "../RootContainer"; |
6
|
|
|
import { |
7
|
|
|
Job, |
8
|
|
|
JobPosterKeyTask, |
9
|
|
|
Criteria, |
10
|
|
|
Skill, |
11
|
|
|
Manager, |
12
|
|
|
Department, |
13
|
|
|
} from "../../models/types"; |
14
|
|
|
import { hrJobSummary } from "../../helpers/routes"; |
15
|
|
|
import { RootState } from "../../store/store"; |
16
|
|
|
import { |
17
|
|
|
getJob, |
18
|
|
|
getTasksByJob, |
19
|
|
|
getCriteriaByJob, |
20
|
|
|
} from "../../store/Job/jobSelector"; |
21
|
|
|
import { getSkills } from "../../store/Skill/skillSelector"; |
22
|
|
|
import { |
23
|
|
|
fetchJob, |
24
|
|
|
fetchJobTasks, |
25
|
|
|
fetchCriteria, |
26
|
|
|
} from "../../store/Job/jobActions"; |
27
|
|
|
import { getDepartments as fetchDepartments } from "../../store/Department/deptActions"; |
28
|
|
|
import { getDepartments } from "../../store/Department/deptSelector"; |
29
|
|
|
import { getManagerById } from "../../store/Manager/managerSelector"; |
30
|
|
|
import { fetchManager } from "../../store/Manager/managerActions"; |
31
|
|
|
import { JobReviewDisplay } from "../JobBuilder/Review/JobReview"; |
32
|
|
|
import { fetchSkills } from "../../store/Skill/skillActions"; |
33
|
|
|
|
34
|
|
|
const jobReviewMessages = defineMessages({ |
35
|
|
|
dataIsLoading: { |
36
|
|
|
id: "hrReviewPage.dataLoading", |
37
|
|
|
defaultMessage: "Data is loading...", |
38
|
|
|
description: "Placeholder text as job data is loading.", |
39
|
|
|
}, |
40
|
|
|
}); |
41
|
|
|
|
42
|
|
|
interface JobReviewHrPageProps { |
43
|
|
|
jobId: number; |
44
|
|
|
job: Job | null; |
45
|
|
|
skills: Skill[]; |
46
|
|
|
keyTasks: JobPosterKeyTask[]; |
47
|
|
|
criteria: Criteria[]; |
48
|
|
|
departments: Department[]; |
49
|
|
|
manager: Manager | null; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
const JobReviewHrPage: React.FunctionComponent<JobReviewHrPageProps> = ({ |
53
|
|
|
jobId, |
54
|
|
|
job, |
55
|
|
|
skills, |
56
|
|
|
keyTasks, |
57
|
|
|
criteria, |
58
|
|
|
departments, |
59
|
|
|
manager, |
60
|
|
|
}): React.ReactElement => { |
61
|
|
|
const { locale, formatMessage } = useIntl(); |
62
|
|
|
if (locale !== "en" && locale !== "fr") { |
63
|
|
|
throw new Error("Unexpected locale"); |
64
|
|
|
} |
65
|
|
|
return ( |
66
|
|
|
<div data-c-container="form" data-c-padding="top(triple) bottom(triple)"> |
67
|
|
|
{job !== null ? ( |
68
|
|
|
<JobReviewDisplay |
69
|
|
|
job={job} |
70
|
|
|
manager={manager} |
71
|
|
|
tasks={keyTasks} |
72
|
|
|
criteria={criteria} |
73
|
|
|
skills={skills} |
74
|
|
|
departments={departments} |
75
|
|
|
hideBuilderLinks |
76
|
|
|
/> |
77
|
|
|
) : ( |
78
|
|
|
<div data-c-alignment="base(centre)"> |
79
|
|
|
<i |
80
|
|
|
aria-hidden="true" |
81
|
|
|
className="fa fa-spinner fa-spin" |
82
|
|
|
title={formatMessage(jobReviewMessages.dataIsLoading)} |
83
|
|
|
/> |
84
|
|
|
<span data-c-visibility="invisible"> |
85
|
|
|
{formatMessage(jobReviewMessages.dataIsLoading)} |
86
|
|
|
</span> |
87
|
|
|
</div> |
88
|
|
|
)} |
89
|
|
|
<div data-c-grid="gutter"> |
90
|
|
|
<div data-c-grid-item="base(1of1)"> |
91
|
|
|
<hr data-c-margin="top(normal) bottom(normal)" /> |
92
|
|
|
</div> |
93
|
|
|
<div |
94
|
|
|
data-c-alignment="base(centre) tp(left)" |
95
|
|
|
data-c-grid-item="tp(1of2)" |
96
|
|
|
> |
97
|
|
|
<a href={hrJobSummary(locale, jobId)} title=""> |
98
|
|
|
<FormattedMessage |
99
|
|
|
id="jobReviewHr.summaryLink" |
100
|
|
|
defaultMessage="Return to Summary" |
101
|
|
|
description="Text for the Return to Summary link." |
102
|
|
|
/> |
103
|
|
|
</a> |
104
|
|
|
</div> |
105
|
|
|
</div> |
106
|
|
|
</div> |
107
|
|
|
); |
108
|
|
|
}; |
109
|
|
|
|
110
|
|
|
const JobReviewHrDataFetcher: React.FC<{ jobId: number }> = ({ jobId }) => { |
111
|
|
|
const dispatch = useDispatch(); |
112
|
|
|
|
113
|
|
|
// Request and select the job |
114
|
|
|
useEffect(() => { |
115
|
|
|
dispatch(fetchJob(jobId)); |
116
|
|
|
}, [dispatch, jobId]); |
117
|
|
|
const job = useSelector((state: RootState) => getJob(state, { jobId })); |
118
|
|
|
|
119
|
|
|
// Request and select the job tasks |
120
|
|
|
useEffect(() => { |
121
|
|
|
dispatch(fetchJobTasks(jobId)); |
122
|
|
|
}, [dispatch, jobId]); |
123
|
|
|
const tasks = useSelector((state: RootState) => |
124
|
|
|
getTasksByJob(state, { jobId }), |
125
|
|
|
); |
126
|
|
|
|
127
|
|
|
// Request and select job criteria |
128
|
|
|
useEffect(() => { |
129
|
|
|
dispatch(fetchCriteria(jobId)); |
130
|
|
|
}, [dispatch, jobId]); |
131
|
|
|
const criteria = useSelector((state: RootState) => |
132
|
|
|
getCriteriaByJob(state, { jobId }), |
133
|
|
|
); |
134
|
|
|
|
135
|
|
|
// Load all skills |
136
|
|
|
useEffect(() => { |
137
|
|
|
dispatch(fetchSkills()); |
138
|
|
|
}, [dispatch]); |
139
|
|
|
const skills = useSelector(getSkills); |
140
|
|
|
|
141
|
|
|
// Load all departments |
142
|
|
|
useEffect(() => { |
143
|
|
|
dispatch(fetchDepartments()); |
144
|
|
|
}, [dispatch]); |
145
|
|
|
const departments = useSelector(getDepartments); |
146
|
|
|
|
147
|
|
|
// Load manager after Job has loaded |
148
|
|
|
const managerId = job?.manager_id; |
|
|
|
|
149
|
|
|
useEffect(() => { |
150
|
|
|
if (managerId) { |
151
|
|
|
dispatch(fetchManager(managerId)); |
152
|
|
|
} |
153
|
|
|
}, [dispatch, managerId]); |
154
|
|
|
const manager = useSelector((state: RootState) => |
155
|
|
|
managerId ? getManagerById(state, { managerId }) : null, |
156
|
|
|
); |
157
|
|
|
|
158
|
|
|
return ( |
159
|
|
|
<JobReviewHrPage |
160
|
|
|
jobId={jobId} |
161
|
|
|
job={job} |
162
|
|
|
manager={manager} |
163
|
|
|
keyTasks={tasks} |
164
|
|
|
criteria={criteria} |
165
|
|
|
skills={skills} |
166
|
|
|
departments={departments} |
167
|
|
|
/> |
168
|
|
|
); |
169
|
|
|
}; |
170
|
|
|
|
171
|
|
|
export default JobReviewHrDataFetcher; |
172
|
|
|
|
173
|
|
|
const container = document.getElementById("job-review-hr"); |
174
|
|
|
if (container !== null) { |
175
|
|
|
if ("jobId" in container.dataset) { |
176
|
|
|
const jobId = Number(container.dataset.jobId as string); |
177
|
|
|
ReactDOM.render( |
178
|
|
|
<RootContainer> |
179
|
|
|
<JobReviewHrDataFetcher jobId={jobId} /> |
180
|
|
|
</RootContainer>, |
181
|
|
|
container, |
182
|
|
|
); |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
|